Без опису

TransformativeActionsController.php 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. <?php
  2. use Illuminate\Support\Facades\Input;
  3. class TransformativeActionsController extends \BaseController
  4. {
  5. public function editTA()
  6. {
  7. $title = "Transformative Action";
  8. $role = Auth::user()['role'];
  9. $outcomes = Outcome::orderBy('name', 'ASC')->lists('name', 'id');
  10. $schools = School::orderBy('name', 'ASC')->get();
  11. $criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
  12. $programs = Program::orderBy('name', 'ASC')->get();
  13. $user_id = auth::user()->id;
  14. $program_id = DB::table('program_user')
  15. ->where('user_id',$user_id)
  16. ->select('program_id')
  17. ->get();
  18. $program_id = $program_id[0]->program_id; //program id 15 debido al user 8
  19. $outcomes = Outcome::orderBy('name', 'ASC')
  20. ->where('deactivation_date','=','0000-00-00')
  21. ->orWhereNull('deactivation_date')
  22. ->get();
  23. $objectives = array();
  24. // if user is program coordinator
  25. if ($role == 3){
  26. //1 edit panel: load the TA that
  27. // are custom ('transformative_actions.by_professor' == 0)
  28. // were approved in past ('transformative_actions.is_custom' == 1)
  29. $ta_edit_panel = DB::table('transformative_actions')
  30. ->where('transformative_actions.is_custom', 1)
  31. ->where('transformative_actions.program_id', $program_id)
  32. ->where('transformative_actions.by_professor', 0)
  33. ->orderBy('at_text', 'ASC')
  34. ->get();
  35. //2 approve panel: load TAs that
  36. // can be approved ('transformative_actions.by_professor' == 1)
  37. $ta_approval_panel = DB::table('transformative_actions')
  38. ->where('transformative_actions.is_custom', 1)
  39. ->where('transformative_actions.program_id', $program_id)
  40. ->where('transformative_actions.by_professor',1)
  41. ->orderBy('at_text', 'ASC')
  42. ->get();
  43. //2.1 approve panel: load the filter options.
  44. // the "->where()" should be the same from $ta_approval_panel,
  45. // but with aditional joins and different select
  46. //
  47. // get the names of the professors
  48. $professor_filter_approvePanel = DB::table('transformative_actions')
  49. ->join('users','users.id','=','transformative_actions.user_id')
  50. ->where('transformative_actions.is_custom', 1)
  51. ->where('transformative_actions.program_id', $program_id)
  52. ->where('transformative_actions.by_professor', 1)
  53. ->select('users.*')
  54. ->groupby('transformative_actions.user_id')
  55. ->orderBy('users.first_name', 'ASC')
  56. ->get();
  57. // get the courses from asociated with a TA
  58. $course_filter_approvePanel = DB::table('ta_course')
  59. ->join('transformative_actions','transformative_actions.id','=','ta_course.ta_id')
  60. ->join('courses','courses.id','=','ta_course.course_id')
  61. ->where('transformative_actions.is_custom', 1)
  62. ->where('transformative_actions.program_id', $program_id)
  63. ->where('transformative_actions.by_professor', 1)
  64. ->select('courses.*')
  65. ->groupBy('courses.name','courses.code')
  66. ->orderBy('courses.name', 'ASC')
  67. ->orderBy('courses.code', 'ASC')
  68. ->get();
  69. // get the outcome asociated with a TA
  70. $outcome_filter_approvePanel = DB::table('transformative_actions')
  71. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  72. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  73. ->join('outcomes','outcomes.id','=','criterion_objective_outcome.outcome_id')
  74. ->where('transformative_actions.is_custom', 1)
  75. ->where('transformative_actions.program_id', $program_id)
  76. ->where('transformative_actions.by_professor', 1)
  77. ->select('outcomes.*')
  78. ->groupBy('outcomes.id')
  79. ->orderBy('outcomes.name', 'ASC')
  80. ->get();
  81. //3 edit panel: load the filter options.
  82. // the "->where()" should be the same from $ta_edit_panel,
  83. // but with aditional joins and different select
  84. //
  85. $professor_filter_editPanel = DB::table('transformative_actions')
  86. ->join('users','users.id','=','transformative_actions.user_id')
  87. ->where('transformative_actions.is_custom', 1)
  88. ->where('transformative_actions.program_id', $program_id)
  89. ->where('transformative_actions.by_professor', 0)
  90. ->select('users.*')
  91. ->groupby('transformative_actions.user_id')
  92. ->orderBy('users.first_name', 'ASC')
  93. ->get();
  94. $course_filter_editPanel = DB::table('ta_course')
  95. ->join('transformative_actions','transformative_actions.id','=','ta_course.ta_id')
  96. ->join('courses','courses.id','=','ta_course.course_id')
  97. ->where('transformative_actions.is_custom', 1)
  98. ->where('transformative_actions.program_id', $program_id)
  99. ->where('transformative_actions.by_professor', 0)
  100. ->select('courses.*')
  101. ->groupBy('courses.name','courses.code')
  102. ->orderBy('courses.name', 'ASC')
  103. ->orderBy('courses.code', 'ASC')
  104. ->get();
  105. $outcome_filter_editPanel = DB::table('transformative_actions')
  106. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  107. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  108. ->join('outcomes','outcomes.id','=','criterion_objective_outcome.outcome_id')
  109. ->where('transformative_actions.is_custom', 1)
  110. ->where('transformative_actions.program_id', $program_id)
  111. ->where('transformative_actions.by_professor', 0)
  112. ->select('outcomes.*')
  113. ->groupBy('outcomes.id')
  114. ->orderBy('outcomes.name', 'ASC')
  115. ->get();
  116. // 4 create panel: search all courses
  117. $courses_create = DB::table('courses')
  118. ->where('courses.program_id',$program_id)
  119. ->select('courses.*')
  120. ->groupBy('courses.name','courses.code')
  121. ->orderBy('courses.name', 'ASC')
  122. ->orderBy('courses.code', 'ASC')
  123. ->get();
  124. }
  125. // if user is profesor
  126. elseif ($role == 4){
  127. // 1 the user can only edit TA that need approval and has been submited by the same user
  128. $ta_edit_panel = DB::table('transformative_actions')
  129. ->where('transformative_actions.is_custom', 1)
  130. ->where('transformative_actions.program_id',$program_id)
  131. ->where('transformative_actions.user_id', Auth::user()->id)
  132. ->where('transformative_actions.by_professor',1)
  133. ->select('transformative_actions.*')
  134. ->orderBy('at_text', 'ASC')
  135. ->get();
  136. // 2 approve panel: dont load TA since professors cant approve them
  137. $ta_approval_panel = array();
  138. // 3 edit panel: load professor filter for his courses
  139. $professor_filter_editPanel = array();
  140. $course_filter_editPanel = DB::table('ta_course')
  141. ->join('transformative_actions','transformative_actions.id','=','ta_course.ta_id')
  142. ->join('courses','courses.id','=','ta_course.course_id')
  143. ->where('transformative_actions.is_custom', 1)
  144. ->where('transformative_actions.user_id', Auth::user()->id)
  145. ->where('transformative_actions.program_id', $program_id)
  146. ->where('transformative_actions.by_professor', 1)
  147. ->select('courses.*')
  148. ->groupBy('courses.name','courses.code')
  149. ->orderBy('courses.name', 'ASC')
  150. ->orderBy('courses.code', 'ASC')
  151. ->get();
  152. $outcome_filter_editPanel = DB::table('transformative_actions')
  153. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  154. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  155. ->join('outcomes','outcomes.id','=','criterion_objective_outcome.outcome_id')
  156. ->where('transformative_actions.is_custom', 1)
  157. ->where('transformative_actions.user_id', Auth::user()->id)
  158. ->where('transformative_actions.program_id',$program_id)
  159. ->where('transformative_actions.by_professor', 1)
  160. ->select('outcomes.*')
  161. ->groupBy('outcomes.id')
  162. ->orderBy('outcomes.name', 'ASC')
  163. ->get();
  164. // these arent used by professors
  165. $professor_filter_approvePanel = array();
  166. $course_filter_approvePanel = array();
  167. $outcome_filter_approvePanel = array();
  168. // 4 create panel: search courses given by the professor
  169. $courses_create = DB::table('courses')
  170. ->where('courses.program_id',$program_id)
  171. ->where('courses.user_id', Auth::user()->id)
  172. ->select('courses.*')
  173. ->groupBy('courses.name','courses.code')
  174. ->orderBy('courses.name', 'ASC')
  175. ->orderBy('courses.code', 'ASC')
  176. ->get();
  177. }
  178. return View::make('local.managers.admins.transformativeAction', compact('title','role', 'outcomes', 'schools', 'criteria', 'programs', 'outcomes', 'objectives',
  179. 'ta_edit_panel','ta_approval_panel','courses_create',
  180. 'professor_filter_approvePanel', 'course_filter_approvePanel', 'outcome_filter_approvePanel',
  181. 'professor_filter_editPanel', 'outcome_filter_editPanel', 'course_filter_editPanel'
  182. ));
  183. }
  184. private function cleanInput()
  185. {
  186. $clean_input = array();
  187. $trimmed = trim(preg_replace('/\t+/', '', Input::get('text')));
  188. Log::info('trimmed 1 -->' . $trimmed . '<--');
  189. // if ($trimmed == '') {
  190. // $trimmed = NULL;
  191. // } else {
  192. // $trimmed = json_encode(preg_split('/\r\n/', $trimmed));
  193. // }
  194. Log::info('trimmed 2 -->' . $trimmed . '<--');
  195. $clean_input['text'] = $trimmed;
  196. //////
  197. $trimmed = trim(preg_replace('/\t+/', '', Input::get('description')));
  198. Log::info('trimmed 3 -->' . $trimmed . '<--');
  199. // if ($trimmed == '') {
  200. // $trimmed = NULL;
  201. // } else {
  202. // $trimmed = json_encode(preg_split('/\r\n/', $trimmed));
  203. // }
  204. Log::info('trimmed 4 -->' . $trimmed . '<--');
  205. $clean_input['description'] = $trimmed;
  206. $clean_input['objectiveid'] = Input::get('objectiveid');
  207. $clean_input['courseid'] = Input::get('courseid');
  208. $clean_input['approval'] = Input::get('approval');
  209. $clean_input['ta_id'] = Input::get('ta_id');
  210. return $clean_input;
  211. }
  212. private function makeValidator($clean_input)
  213. {
  214. /** Validation rules */
  215. return Validator::make(
  216. array(
  217. 'text' => $clean_input['text'],
  218. 'description' => $clean_input['description'],
  219. 'objectiveid' => $clean_input['objectiveid'],
  220. 'courseid' => $clean_input['courseid'],
  221. 'approval' => $clean_input['approval'],
  222. 'ta_id' => $clean_input['ta_id'],
  223. ),
  224. array(
  225. 'text' => 'required|string',
  226. 'description' => 'required|string',
  227. 'objectiveid' => 'required|array',
  228. 'courseid' => 'required|array',
  229. 'approval' => 'integer',
  230. 'ta_id' => 'integer',
  231. )
  232. );
  233. }
  234. /**
  235. * Create a new transformative action.
  236. *
  237. * @return Redirect Redirect back to form page
  238. */
  239. public function createTA()
  240. {
  241. $clean_input = $this->cleanInput();
  242. /** Validation rules */
  243. $validator = $this->makeValidator($clean_input);
  244. /** If validation fails */
  245. if ($validator->fails()) {
  246. /** Prepare error message */
  247. $message = '<p>Error(s) creating a new Transformative Action:</p><ul>';
  248. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  249. $message .= $validationError;
  250. }
  251. $message .= '</ul>';
  252. /** Send error message and old data */
  253. Session::flash('status', 'danger');
  254. Session::flash('message', $message);
  255. $role = Auth::user()['role'];
  256. return Redirect::to('transformativeAction')->withInput();
  257. } else {
  258. $user_id = auth::user()->id;
  259. $program_id = DB::table('program_user')
  260. ->where('user_id',$user_id)
  261. ->select('program_id')
  262. ->get();
  263. $program_id = $program_id[0]->program_id;
  264. $role = Auth::user()['role'];
  265. $by_professor = 1;
  266. if($role == 3){
  267. $by_professor = 0;
  268. }
  269. // $by_professor = $clean_input['approval'];
  270. $current_timestamp = date('Y/m/d H:i:s', time());
  271. // insert the TA
  272. $ta_id = DB::table('transformative_actions')->insertGetId(
  273. array('at_text' => $clean_input['text'],
  274. 'description' => $clean_input['description'],
  275. 'is_custom' => 1,
  276. 'user_id' => $user_id,
  277. 'program_id' => $program_id,
  278. 'created_at' => $current_timestamp,
  279. 'by_professor' => $by_professor,
  280. )
  281. );
  282. //
  283. // // insert the multiple TA_objective_program
  284. foreach ($clean_input['objectiveid'] as $objective_id) {
  285. DB::table('transformative_objective_program')->insert(
  286. array(
  287. 'ta_id' => $ta_id,
  288. 'objective_id' => $objective_id,
  289. 'program_id' => $program_id,
  290. 'created_at' => $current_timestamp,
  291. )
  292. );
  293. }
  294. //
  295. // // insert the multiple TA_course
  296. foreach ($clean_input['courseid'] as $course_id) {
  297. DB::table('TA_course')->insert(
  298. array(
  299. 'ta_id' => $ta_id,
  300. 'course_id' => $course_id,
  301. )
  302. );
  303. }
  304. Session::flash('status', 'success');
  305. Session::flash('message', 'Transformative Action created: "' . $clean_input['text'] . '".');
  306. $role = Auth::user()['role'];
  307. return Redirect::to('transformativeAction')->withInput();
  308. }
  309. }
  310. public function approveTA()
  311. {
  312. $role = Auth::user()['role'];
  313. if($role != 3){
  314. $message = 'Only Program Coordinators can approve a TA';
  315. Session::flash('status', 'danger');
  316. Session::flash('message', $message);
  317. return Redirect::to('transformativeAction')->withInput();
  318. }
  319. $ta_id = Input::get('ta_id');
  320. $text = Input::get('at_text');
  321. if($ta_id == 0){
  322. $message = 'Please select a Transformative Action</p>';
  323. Session::flash('status', 'danger');
  324. Session::flash('message', $message);
  325. $role = Auth::user()['role'];
  326. return Redirect::to('transformativeAction')->withInput();
  327. }
  328. $current_timestamp = date('Y/m/d H:i:s', time());
  329. // edit the TA
  330. DB::table('transformative_actions')
  331. ->where('id', $ta_id)
  332. ->update([
  333. 'by_professor' => 0,
  334. 'updated_at' => $current_timestamp,
  335. ]);
  336. Session::flash('status', 'success');
  337. Session::flash('message', 'Approved the Transformative Action: "' . $text . '".');
  338. $role = Auth::user()['role'];
  339. return Redirect::to('transformativeAction')->withInput();
  340. }
  341. public function updateTA()
  342. {
  343. $clean_input = $this->cleanInput();
  344. /** Validation rules */
  345. $validator = $this->makeValidator($clean_input);
  346. /** If validation fails */
  347. if ($validator->fails()) {
  348. /** Prepare error message */
  349. $message = 'Error(s) updating the Transformative Action: <ul>';
  350. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  351. $message .= $validationError;
  352. }
  353. $message .= '</ul>';
  354. /** Send error message and old data */
  355. Session::flash('status', 'danger');
  356. Session::flash('message', $message);
  357. $role = Auth::user()['role'];
  358. return Redirect::to('transformativeAction')->withInput();
  359. } else {
  360. $user_id = auth::user()->id;
  361. $program_id = DB::table('program_user')
  362. ->where('user_id',$user_id)
  363. ->select('program_id')
  364. ->get();
  365. $program_id = $program_id[0]->program_id;
  366. $role = Auth::user()['role'];
  367. $by_professor = $clean_input['approval'];
  368. if($role == 4){
  369. $by_professor = 1;
  370. }
  371. // $by_professor = $clean_input['approval'];
  372. $current_timestamp = date('Y/m/d H:i:s', time());
  373. // edit the TA
  374. DB::table('transformative_actions')
  375. ->where('id', $clean_input['ta_id'])
  376. ->update([
  377. 'by_professor' => $by_professor,
  378. 'at_text' => $clean_input['text'],
  379. 'description' => $clean_input['description'],
  380. 'updated_at' => $current_timestamp,
  381. ]);
  382. $ta_id = $clean_input['ta_id'];
  383. $new_objective_id = $clean_input['objectiveid'];
  384. $old_objective_id = DB::table('transformative_objective_program')
  385. ->where('ta_id',$ta_id)
  386. ->select('objective_id')
  387. ->lists('objective_id');
  388. //delete existing objective_id if it isnt in new_ids array
  389. foreach ($old_objective_id as $old_id) {
  390. if(in_array($old_id,$new_objective_id)){
  391. //do nothing if a new id is already in atble
  392. }
  393. else {
  394. //if old id not in new id, delete
  395. DB::table('transformative_objective_program')
  396. ->where('ta_id',$ta_id)
  397. ->where('objective_id', $old_id)
  398. ->delete();
  399. }
  400. }
  401. //
  402. foreach ($new_objective_id as $new_id) {
  403. $result = DB::table('transformative_objective_program')
  404. ->where('objective_id',$new_id)
  405. ->select('objective_id')
  406. ->lists('objective_id');
  407. if(count($result) == 0){
  408. //if the new_id does not exists, do nothing
  409. DB::table('transformative_objective_program')->insert(
  410. array(
  411. 'ta_id' => $ta_id,
  412. 'objective_id' => $new_id,
  413. 'program_id' => $program_id,
  414. 'created_at' => $current_timestamp,
  415. )
  416. );
  417. }
  418. else {
  419. //if the new_id already exists, do nothing
  420. }
  421. }
  422. $new_course_id = $clean_input['courseid'];
  423. $old_course_id = DB::table('ta_course')
  424. ->where('ta_id',$ta_id)
  425. ->select('course_id')
  426. ->lists('course_id');
  427. //delete existing course_id if it isnt in new_ids array
  428. foreach ($old_course_id as $old_id) {
  429. if(in_array($old_id,$new_course_id)){
  430. //do nothing if a new id is already in atble
  431. }
  432. else {
  433. //if old id not in new id, delete
  434. DB::table('ta_course')
  435. ->where('ta_id',$ta_id)
  436. ->where('course_id', $old_id)
  437. ->delete();
  438. }
  439. }
  440. //add course_id if it isnt already inserted
  441. foreach ($new_course_id as $new_id) {
  442. $result = DB::table('ta_course')
  443. ->where('ta_id',$ta_id)
  444. ->where('course_id',$new_id)
  445. ->select('course_id')
  446. ->lists('course_id');
  447. if(count($result) == 0){
  448. //if the new_id does not exists, do nothing
  449. DB::table('ta_course')->insert(
  450. array(
  451. 'ta_id' => $ta_id,
  452. 'course_id' => $new_id,
  453. )
  454. );
  455. }
  456. else {
  457. //if the new_id already exists, do nothing
  458. }
  459. }
  460. Session::flash('status', 'success');
  461. Session::flash('message', 'Updated Transformative Action: "' . $clean_input['text'] . '".');
  462. $role = Auth::user()['role'];
  463. return Redirect::to('transformativeAction')->withInput();
  464. }
  465. }
  466. public function deleteTA()
  467. {
  468. $ta_id = array(Input::get('ta_id'));
  469. // si envia id 0, el backend se queja en la linea: $ta = $ta[0];
  470. // nunca deberia ocurrir, pero es un safity measure.
  471. if($ta_id == 0){
  472. $message = 'Please select a Transformative Action</p>';
  473. Session::flash('status', 'danger');
  474. Session::flash('message', $message);
  475. $role = Auth::user()['role'];
  476. return Redirect::to('transformativeAction')->withInput();
  477. }
  478. $ta = DB::table('transformative_actions')
  479. ->where('transformative_actions.is_custom', 1)
  480. ->where('id',$ta_id)
  481. ->get();
  482. $ta = $ta[0];
  483. $used = DB::table('annual_plan_transformative')
  484. ->where('id',$ta_id)
  485. ->get();
  486. $recommended = $ta->by_professor;
  487. // the TA can only be deleted if error if the TA is not currently as "Recommended"
  488. // and isnt used in an anual plan
  489. if ($recommended == 1 && count($used) == 0) {
  490. // delete the TA if it qualifies
  491. DB::delete("delete from transformative_actions where id = ?", $ta_id);
  492. $name = $ta->at_text;
  493. $message = 'The Transformative Action has been deleted:</p><ul>';
  494. $message .= '<li> '.$name.' </li>';
  495. $message .= '</ul>';
  496. Session::flash('status', 'success');
  497. Session::flash('message', $message);
  498. $role = Auth::user()['role'];
  499. return Redirect::to('transformativeAction')->withInput();
  500. }
  501. $message = 'Transformative Actions can only be deleted if:</p><ul>';
  502. $message .= '<li> It has a status of "Recommended"</li>';
  503. $message .= '<li> It is not currently used in a plan</li>';
  504. $message .= '</ul>';
  505. Session::flash('status', 'danger');
  506. Session::flash('message', $message);
  507. $role = Auth::user()['role'];
  508. return Redirect::to('transformativeAction')->withInput();
  509. }
  510. public function selectTA()
  511. {
  512. $ta_id = Input::get("ta_id");
  513. $user_id = Auth::user()->id;
  514. $program_id = DB::table('program_user')
  515. ->where('user_id',$user_id)
  516. ->select('program_id')
  517. ->get();
  518. $program_id = $program_id[0]->program_id;
  519. $objectives = DB::table('transformative_actions')
  520. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  521. ->join('objectives','objectives.id','=','transformative_objective_program.objective_id')
  522. ->where('transformative_actions.id',$ta_id)
  523. ->select('objectives.text as text', 'objectives.id as id')
  524. ->orderBy('objectives.text', 'ASC')
  525. ->get();
  526. $an_objective = $objectives[0]->id;
  527. $outcome_id = DB::table('criterion_objective_outcome')
  528. ->where('criterion_objective_outcome.objective_id',$an_objective)
  529. ->select('criterion_objective_outcome.outcome_id')
  530. ->get();
  531. $outcome_id = $outcome_id[0]->outcome_id;
  532. $objectives_from_outcome = DB::table('objectives')
  533. ->join('objective_program','objective_program.objective_id','=','objectives.id')
  534. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','objectives.id')
  535. ->where('criterion_objective_outcome.outcome_id',$outcome_id)
  536. ->where('objective_program.program_id',$program_id)
  537. ->orderBy('objectives.text', 'ASC')
  538. ->select('objectives.text as text', 'objectives.id as id')
  539. ->get();
  540. $selected_courses = DB::table('ta_course')
  541. ->join('courses','courses.id','=','ta_course.course_id')
  542. ->where('ta_id',$ta_id)
  543. ->orderBy('courses.name', 'ASC')
  544. ->orderBy('courses.code', 'ASC')
  545. ->select('courses.*')
  546. ->get();
  547. $name = DB::table('transformative_actions')
  548. ->where('id',$ta_id)
  549. ->select('at_text as name')
  550. ->lists('name');
  551. $description = DB::table('transformative_actions')
  552. ->where('id',$ta_id)
  553. ->select('description')
  554. ->lists('description');
  555. $status = DB::table('transformative_actions')
  556. ->where('id',$ta_id)
  557. ->select('by_professor as status')
  558. ->lists('status');
  559. $status = $status[0];
  560. $plans_count = DB::table('annual_plan_transformative')
  561. ->where('id',$ta_id)
  562. ->get();
  563. $plans_count = count($plans_count);
  564. $can_be_deleted = false;
  565. if($plans_count == 0 && $status == 1){
  566. $can_be_deleted = true;
  567. }
  568. return array(
  569. 'objectives' => $objectives,
  570. 'objectives_from_outcome' => $objectives_from_outcome,
  571. 'selected_courses' => $selected_courses,
  572. 'name' => $name,
  573. 'description' => $description,
  574. 'status' => $status,
  575. 'can_be_deleted' => $can_be_deleted,
  576. 'plans_count' => $plans_count,
  577. );
  578. }
  579. public function objectivesFromOutcome()
  580. {
  581. $user_id = Auth::user()->id;
  582. $program_id = DB::table('program_user')
  583. ->where('user_id',$user_id)
  584. ->select('program_id')
  585. ->get();
  586. $program_id = $program_id[0]->program_id;
  587. $ta_id = Input::get("ta_id");
  588. $outcome_id = Input::get("outcome_id");
  589. $objectives = DB::table('objectives')
  590. ->join('objective_program','objective_program.objective_id','=','objectives.id')
  591. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','objectives.id')
  592. ->where('criterion_objective_outcome.outcome_id',$outcome_id)
  593. ->where('objective_program.program_id',$program_id)
  594. ->orderBy('objectives.text', 'ASC')
  595. ->select('objectives.text as text', 'objectives.id as id')
  596. ->get();
  597. return array(
  598. 'objectives' => $objectives,
  599. );
  600. }
  601. // return TA filtered by the user on the approve or edit panel
  602. public function filterTA()
  603. {
  604. $user_id = Auth::user()->id;
  605. $role = Auth::user()['role'];
  606. $professor_id = Input::get('professor_id');
  607. $course_id = Input::get('course_id');
  608. $outcome_id = Input::get('outcome_id');
  609. $panel_id = Input::get('panel_id');
  610. $program_id = DB::table('program_user')
  611. ->where('user_id',$user_id)
  612. ->select('program_id')
  613. ->get();
  614. $program_id = $program_id[0]->program_id;
  615. // if the user is a coordinator filtering the approvePanel
  616. if ($role == '3' && $panel_id == 'approvePanel'){
  617. // if professor isnt a desired filter, search all professors
  618. if ($professor_id == 0){
  619. $all_ta_users = DB::table('transformative_actions')
  620. ->where('transformative_actions.is_custom', 1)
  621. ->where('transformative_actions.program_id', $program_id)
  622. ->where('transformative_actions.by_professor',1)
  623. ->select('transformative_actions.user_id')
  624. ->get();
  625. $professor_id = array();
  626. foreach ($all_ta_users as $key => $user) {
  627. array_push($professor_id, $user->user_id);
  628. }
  629. }else{
  630. $professor_id = array($professor_id);
  631. }
  632. // if course isnt a desired filter, search all courses
  633. if ($course_id == 0){
  634. $courses = DB::table('ta_course')
  635. ->join('transformative_actions','transformative_actions.id','=','ta_course.ta_id')
  636. ->join('courses','courses.id','=','ta_course.course_id')
  637. ->where('transformative_actions.is_custom', 1)
  638. ->where('transformative_actions.program_id', $program_id)
  639. ->where('transformative_actions.by_professor', 1)
  640. ->select('courses.id')
  641. ->get();
  642. $course_id = array();
  643. foreach ($courses as $key => $course) {
  644. array_push($course_id, $course->id);
  645. }
  646. }else{
  647. $course_id = array($course_id);
  648. }
  649. // if outcome isnt a desired filter, search all outcomes
  650. if ($outcome_id == 0){
  651. $outcomes = DB::table('transformative_actions')
  652. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  653. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  654. ->join('outcomes','outcomes.id','=','criterion_objective_outcome.outcome_id')
  655. ->where('transformative_actions.is_custom', 1)
  656. ->where('transformative_actions.program_id', $program_id)
  657. ->where('transformative_actions.by_professor', 1)
  658. ->select('outcomes.id')
  659. ->groupBy('outcomes.id')
  660. ->get();
  661. $outcome_id = array();
  662. foreach ($outcomes as $key => $outcome) {
  663. array_push($outcome_id, $outcome->id);
  664. }
  665. }else{
  666. $outcome_id = array($outcome_id);
  667. }
  668. // search TA with filters
  669. $filtered_at = DB::table('transformative_actions')
  670. ->join('ta_course','ta_course.ta_id','=','transformative_actions.id')
  671. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  672. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  673. ->where('transformative_actions.is_custom', 1)
  674. ->where('transformative_actions.program_id',$program_id)
  675. ->where('transformative_actions.by_professor',1)
  676. ->whereIn('transformative_actions.user_id',$professor_id)
  677. ->whereIn('criterion_objective_outcome.outcome_id',$outcome_id)
  678. ->whereIn('ta_course.course_id',$course_id)
  679. ->select('transformative_actions.*')
  680. ->groupBy('transformative_actions.id')
  681. ->orderBy('transformative_actions.at_text', 'ASC')
  682. ->get();
  683. return $filtered_at;
  684. }
  685. // if the user is a coordinator filtering the editPanel
  686. elseif($role == '3' && $panel_id == 'editPanel'){
  687. // if professor isnt a desired filter, search all professors
  688. if ($professor_id == 0){
  689. $all_ta_users = DB::table('transformative_actions')
  690. ->where('transformative_actions.is_custom', 1)
  691. ->where('transformative_actions.program_id', $program_id)
  692. ->where('transformative_actions.by_professor',0)
  693. ->select('transformative_actions.user_id')
  694. ->get();
  695. $professor_id = array();
  696. foreach ($all_ta_users as $key => $user) {
  697. array_push($professor_id, $user->user_id);
  698. }
  699. }else{
  700. $professor_id = array($professor_id);
  701. }
  702. // if course isnt a desired filter, search all courses
  703. if ($course_id == 0){
  704. $courses = DB::table('ta_course')
  705. ->join('transformative_actions','transformative_actions.id','=','ta_course.ta_id')
  706. ->join('courses','courses.id','=','ta_course.course_id')
  707. ->where('transformative_actions.is_custom', 1)
  708. ->where('transformative_actions.program_id', $program_id)
  709. ->where('transformative_actions.by_professor', 0)
  710. ->select('courses.id')
  711. ->get();
  712. $course_id = array();
  713. foreach ($courses as $key => $course) {
  714. array_push($course_id, $course->id);
  715. }
  716. }else{
  717. $course_id = array($course_id);
  718. }
  719. // if outcome isnt a desired filter, search all outcomes
  720. if ($outcome_id == 0){
  721. $outcomes = DB::table('transformative_actions')
  722. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  723. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  724. ->join('outcomes','outcomes.id','=','criterion_objective_outcome.outcome_id')
  725. ->where('transformative_actions.is_custom', 1)
  726. ->where('transformative_actions.program_id', $program_id)
  727. ->where('transformative_actions.by_professor', 0)
  728. ->select('outcomes.id')
  729. ->groupBy('outcomes.id')
  730. ->get();
  731. $outcome_id = array();
  732. foreach ($outcomes as $key => $outcome) {
  733. array_push($outcome_id, $outcome->id);
  734. }
  735. }else{
  736. $outcome_id = array($outcome_id);
  737. }
  738. // search TA with filters
  739. $filtered_at = DB::table('transformative_actions')
  740. ->join('ta_course','ta_course.ta_id','=','transformative_actions.id')
  741. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  742. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  743. ->where('transformative_actions.is_custom', 1)
  744. ->where('transformative_actions.program_id',$program_id)
  745. ->where('transformative_actions.by_professor',0)
  746. ->whereIn('transformative_actions.user_id',$professor_id)
  747. ->whereIn('criterion_objective_outcome.outcome_id',$outcome_id)
  748. ->whereIn('ta_course.course_id',$course_id)
  749. ->select('transformative_actions.*')
  750. ->groupBy('transformative_actions.id')
  751. ->orderBy('transformative_actions.at_text', 'ASC')
  752. ->get();
  753. return $filtered_at;
  754. }
  755. // if the user is a professor filtering the editPanel
  756. elseif($role == '4' && $panel_id == 'editPanel'){
  757. // if course isnt a desired filter, search all courses
  758. if ($course_id == 0){
  759. $courses = DB::table('ta_course')
  760. ->join('transformative_actions','transformative_actions.id','=','ta_course.ta_id')
  761. ->join('courses','courses.id','=','ta_course.course_id')
  762. ->where('transformative_actions.user_id', Auth::user()->id)
  763. ->where('transformative_actions.is_custom', 1)
  764. ->where('transformative_actions.program_id', $program_id)
  765. ->where('transformative_actions.by_professor', 1)
  766. ->select('courses.id')
  767. ->get();
  768. $course_id = array();
  769. foreach ($courses as $key => $course) {
  770. array_push($course_id, $course->id);
  771. }
  772. }else{
  773. $course_id = array($course_id);
  774. }
  775. // if outcome isnt a desired filter, search all outcomes
  776. if ($outcome_id == 0){
  777. $outcomes = DB::table('transformative_actions')
  778. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  779. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  780. ->join('outcomes','outcomes.id','=','criterion_objective_outcome.outcome_id')
  781. ->where('transformative_actions.user_id', Auth::user()->id)
  782. ->where('transformative_actions.is_custom', 1)
  783. ->where('transformative_actions.program_id', $program_id)
  784. ->where('transformative_actions.by_professor', 1)
  785. ->select('outcomes.id')
  786. ->groupBy('outcomes.id')
  787. ->get();
  788. $outcome_id = array();
  789. foreach ($outcomes as $key => $outcome) {
  790. array_push($outcome_id, $outcome->id);
  791. }
  792. }else{
  793. $outcome_id = array($outcome_id);
  794. }
  795. // search TA with filters
  796. $filtered_at = DB::table('transformative_actions')
  797. ->join('ta_course','ta_course.ta_id','=','transformative_actions.id')
  798. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  799. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  800. ->where('transformative_actions.user_id', Auth::user()->id)
  801. ->where('transformative_actions.is_custom', 1)
  802. ->where('transformative_actions.program_id',$program_id)
  803. ->where('transformative_actions.by_professor',1)
  804. ->whereIn('criterion_objective_outcome.outcome_id',$outcome_id)
  805. ->whereIn('ta_course.course_id',$course_id)
  806. ->select('transformative_actions.*')
  807. ->groupBy('transformative_actions.id')
  808. ->orderBy('transformative_actions.at_text', 'ASC')
  809. ->get();
  810. return $filtered_at;
  811. }
  812. return 'ilegal';
  813. }
  814. }