Ei kuvausta

TransformativeActionsController.php 35KB

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