Ei kuvausta

TransformativeActionsController.php 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  73. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.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_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  108. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.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_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  155. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.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('title','role', 'outcomes', 'schools', 'criteria', 'programs', 'outcomes', 'objectives',
  180. 'ta_edit_panel','ta_approval_panel','courses_create',
  181. 'professor_filter_approvePanel', 'course_filter_approvePanel', 'outcome_filter_approvePanel',
  182. 'professor_filter_editPanel', 'outcome_filter_editPanel', 'course_filter_editPanel'
  183. ));
  184. }
  185. private function cleanInput()
  186. {
  187. $clean_input = array();
  188. $trimmed = trim(preg_replace('/\t+/', '', Input::get('text')));
  189. Log::info('trimmed 1 -->' . $trimmed . '<--');
  190. // if ($trimmed == '') {
  191. // $trimmed = NULL;
  192. // } else {
  193. // $trimmed = json_encode(preg_split('/\r\n/', $trimmed));
  194. // }
  195. Log::info('trimmed 2 -->' . $trimmed . '<--');
  196. $clean_input['text'] = $trimmed;
  197. //////
  198. $trimmed = trim(preg_replace('/\t+/', '', Input::get('description')));
  199. Log::info('trimmed 3 -->' . $trimmed . '<--');
  200. // if ($trimmed == '') {
  201. // $trimmed = NULL;
  202. // } else {
  203. // $trimmed = json_encode(preg_split('/\r\n/', $trimmed));
  204. // }
  205. Log::info('trimmed 4 -->' . $trimmed . '<--');
  206. $clean_input['description'] = $trimmed;
  207. $clean_input['objectiveid'] = Input::get('objectiveid');
  208. $clean_input['courseid'] = Input::get('courseid');
  209. $clean_input['approval'] = Input::get('approval');
  210. $clean_input['ta_id'] = Input::get('ta_id');
  211. return $clean_input;
  212. }
  213. private function makeValidator($clean_input)
  214. {
  215. /** Validation rules */
  216. return Validator::make(
  217. array(
  218. 'text' => $clean_input['text'],
  219. 'description' => $clean_input['description'],
  220. 'objectiveid' => $clean_input['objectiveid'],
  221. 'courseid' => $clean_input['courseid'],
  222. 'approval' => $clean_input['approval'],
  223. 'ta_id' => $clean_input['ta_id'],
  224. ),
  225. array(
  226. 'text' => 'required|string',
  227. 'description' => 'required|string',
  228. 'objectiveid' => 'required|array',
  229. 'courseid' => 'required|array',
  230. 'approval' => 'integer',
  231. 'ta_id' => 'integer',
  232. )
  233. );
  234. }
  235. // Create a Transformative Action
  236. public function createTA()
  237. {
  238. $clean_input = $this->cleanInput();
  239. /** Validation rules */
  240. $validator = $this->makeValidator($clean_input);
  241. /** If validation fails */
  242. if ($validator->fails()) {
  243. /** Prepare error message */
  244. $message = '<p>Error(s) creating a new Transformative Action:</p><ul>';
  245. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  246. $message .= $validationError;
  247. }
  248. $message .= '</ul>';
  249. /** Send error message and old data */
  250. Session::flash('status', 'danger');
  251. Session::flash('message', $message);
  252. $role = Auth::user()['role'];
  253. return Redirect::to('transformativeAction')->withInput();
  254. } else {
  255. $user_id = auth::user()->id;
  256. $program_id = DB::table('program_user')
  257. ->where('user_id',$user_id)
  258. ->select('program_id')
  259. ->get();
  260. $program_id = $program_id[0]->program_id;
  261. $role = Auth::user()['role'];
  262. $by_professor = 1;
  263. if($role == 3){
  264. $by_professor = 0;
  265. }
  266. // $by_professor = $clean_input['approval'];
  267. $current_timestamp = date('Y/m/d H:i:s', time());
  268. // insert the TA
  269. $ta_id = DB::table('transformative_actions')->insertGetId(
  270. array('at_text' => $clean_input['text'],
  271. 'description' => $clean_input['description'],
  272. 'is_custom' => 1,
  273. 'user_id' => $user_id,
  274. 'program_id' => $program_id,
  275. 'created_at' => $current_timestamp,
  276. 'by_professor' => $by_professor,
  277. )
  278. );
  279. //
  280. // // insert the multiple TA_objective_program
  281. foreach ($clean_input['objectiveid'] as $objective_id) {
  282. DB::table('transformative_objective_program')->insert(
  283. array(
  284. 'ta_id' => $ta_id,
  285. 'objective_id' => $objective_id,
  286. 'program_id' => $program_id,
  287. 'created_at' => $current_timestamp,
  288. )
  289. );
  290. }
  291. //
  292. // // insert the multiple TA_course
  293. foreach ($clean_input['courseid'] as $course_id) {
  294. DB::table('TA_course')->insert(
  295. array(
  296. 'ta_id' => $ta_id,
  297. 'course_id' => $course_id,
  298. )
  299. );
  300. }
  301. Session::flash('status', 'success');
  302. Session::flash('message', 'Transformative Action created: "' . $clean_input['text'] . '".');
  303. $role = Auth::user()['role'];
  304. return Redirect::to('transformativeAction')->withInput();
  305. }
  306. }
  307. // apporve a Transformative Action
  308. public function approveTA()
  309. {
  310. $role = Auth::user()['role'];
  311. if($role != 3){
  312. $message = 'Only Program Coordinators can approve a TA';
  313. Session::flash('status', 'danger');
  314. Session::flash('message', $message);
  315. return Redirect::to('transformativeAction')->withInput();
  316. }
  317. $ta_id = Input::get('ta_id');
  318. $text = Input::get('at_text');
  319. if($ta_id == 0){
  320. $message = 'Please select a Transformative Action</p>';
  321. Session::flash('status', 'danger');
  322. Session::flash('message', $message);
  323. $role = Auth::user()['role'];
  324. return Redirect::to('transformativeAction')->withInput();
  325. }
  326. $current_timestamp = date('Y/m/d H:i:s', time());
  327. // edit the TA
  328. DB::table('transformative_actions')
  329. ->where('id', $ta_id)
  330. ->update([
  331. 'by_professor' => 0,
  332. 'updated_at' => $current_timestamp,
  333. ]);
  334. Session::flash('status', 'success');
  335. Session::flash('message', 'Approved the Transformative Action: "' . $text . '".');
  336. $role = Auth::user()['role'];
  337. return Redirect::to('transformativeAction')->withInput();
  338. }
  339. // update a Tranformative Action
  340. public function updateTA()
  341. {
  342. $clean_input = $this->cleanInput();
  343. /** Validation rules */
  344. $validator = $this->makeValidator($clean_input);
  345. /** If validation fails */
  346. if ($validator->fails()) {
  347. /** Prepare error message */
  348. $message = 'Error(s) updating the Transformative Action: <ul>';
  349. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  350. $message .= $validationError;
  351. }
  352. $message .= '</ul>';
  353. /** Send error message and old data */
  354. Session::flash('status', 'danger');
  355. Session::flash('message', $message);
  356. $role = Auth::user()['role'];
  357. return Redirect::to('transformativeAction')->withInput();
  358. } else {
  359. $user_id = auth::user()->id;
  360. $program_id = DB::table('program_user')
  361. ->where('user_id',$user_id)
  362. ->select('program_id')
  363. ->get();
  364. $program_id = $program_id[0]->program_id;
  365. $role = Auth::user()['role'];
  366. $by_professor = $clean_input['approval'];
  367. if($role == 4){
  368. $by_professor = 1;
  369. }
  370. // $by_professor = $clean_input['approval'];
  371. $current_timestamp = date('Y/m/d H:i:s', time());
  372. // edit the TA
  373. DB::table('transformative_actions')
  374. ->where('id', $clean_input['ta_id'])
  375. ->update([
  376. 'by_professor' => $by_professor,
  377. 'at_text' => $clean_input['text'],
  378. 'description' => $clean_input['description'],
  379. 'updated_at' => $current_timestamp,
  380. ]);
  381. $ta_id = $clean_input['ta_id'];
  382. $new_objective_id = $clean_input['objectiveid'];
  383. $old_objective_id = DB::table('transformative_objective_program')
  384. ->where('ta_id',$ta_id)
  385. ->select('objective_id')
  386. ->lists('objective_id');
  387. //delete existing objective_id if it isnt in new_ids array
  388. foreach ($old_objective_id as $old_id) {
  389. if(in_array($old_id,$new_objective_id)){
  390. //do nothing if a new id is already in atble
  391. }
  392. else {
  393. //if old id not in new id, delete
  394. DB::table('transformative_objective_program')
  395. ->where('ta_id',$ta_id)
  396. ->where('objective_id', $old_id)
  397. ->delete();
  398. }
  399. }
  400. //
  401. foreach ($new_objective_id as $new_id) {
  402. $result = DB::table('transformative_objective_program')
  403. ->where('objective_id',$new_id)
  404. ->select('objective_id')
  405. ->lists('objective_id');
  406. if(count($result) == 0){
  407. //if the new_id does not exists, do nothing
  408. DB::table('transformative_objective_program')->insert(
  409. array(
  410. 'ta_id' => $ta_id,
  411. 'objective_id' => $new_id,
  412. 'program_id' => $program_id,
  413. 'created_at' => $current_timestamp,
  414. )
  415. );
  416. }
  417. else {
  418. //if the new_id already exists, do nothing
  419. }
  420. }
  421. $new_course_id = $clean_input['courseid'];
  422. $old_course_id = DB::table('ta_course')
  423. ->where('ta_id',$ta_id)
  424. ->select('course_id')
  425. ->lists('course_id');
  426. //delete existing course_id if it isnt in new_ids array
  427. foreach ($old_course_id as $old_id) {
  428. if(in_array($old_id,$new_course_id)){
  429. //do nothing if a new id is already in atble
  430. }
  431. else {
  432. //if old id not in new id, delete
  433. DB::table('ta_course')
  434. ->where('ta_id',$ta_id)
  435. ->where('course_id', $old_id)
  436. ->delete();
  437. }
  438. }
  439. //add course_id if it isnt already inserted
  440. foreach ($new_course_id as $new_id) {
  441. $result = DB::table('ta_course')
  442. ->where('ta_id',$ta_id)
  443. ->where('course_id',$new_id)
  444. ->select('course_id')
  445. ->lists('course_id');
  446. if(count($result) == 0){
  447. //if the new_id does not exists, do nothing
  448. DB::table('ta_course')->insert(
  449. array(
  450. 'ta_id' => $ta_id,
  451. 'course_id' => $new_id,
  452. )
  453. );
  454. }
  455. else {
  456. //if the new_id already exists, do nothing
  457. }
  458. }
  459. Session::flash('status', 'success');
  460. Session::flash('message', 'Updated Transformative Action: "' . $clean_input['text'] . '".');
  461. $role = Auth::user()['role'];
  462. return Redirect::to('transformativeAction')->withInput();
  463. }
  464. }
  465. // delete a Transformative Action
  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. // load the information of a Tranformative Action when its
  511. // selected on the approve or edit panel
  512. public function selectTA()
  513. {
  514. $ta_id = Input::get("ta_id");
  515. $user_id = Auth::user()->id;
  516. $program_id = DB::table('program_user')
  517. ->where('user_id',$user_id)
  518. ->select('program_id')
  519. ->get();
  520. $program_id = $program_id[0]->program_id;
  521. $objectives = DB::table('transformative_actions')
  522. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  523. ->join('objectives','objectives.id','=','transformative_objective_program.objective_id')
  524. ->where('transformative_actions.id',$ta_id)
  525. ->select('objectives.text as text', 'objectives.id as id')
  526. ->orderBy('objectives.text', 'ASC')
  527. ->get();
  528. $an_objective = $objectives[0]->id;
  529. $outcome_id = DB::table('criterion_objective_outcome')
  530. ->where('criterion_objective_outcome.objective_id',$an_objective)
  531. ->select('criterion_objective_outcome.outcome_id')
  532. ->get();
  533. $outcome_id = $outcome_id[0]->outcome_id;
  534. $objectives_from_outcome = DB::table('objectives')
  535. ->join('objective_program','objective_program.objective_id','=','objectives.id')
  536. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','objectives.id')
  537. ->where('criterion_objective_outcome.outcome_id',$outcome_id)
  538. ->where('objective_program.program_id',$program_id)
  539. ->orderBy('objectives.text', 'ASC')
  540. ->select('objectives.text as text', 'objectives.id as id')
  541. ->get();
  542. $selected_courses = DB::table('ta_course')
  543. ->join('courses','courses.id','=','ta_course.course_id')
  544. ->where('ta_id',$ta_id)
  545. ->orderBy('courses.name', 'ASC')
  546. ->orderBy('courses.code', 'ASC')
  547. ->select('courses.*')
  548. ->get();
  549. $name = DB::table('transformative_actions')
  550. ->where('id',$ta_id)
  551. ->select('at_text as name')
  552. ->lists('name');
  553. $description = DB::table('transformative_actions')
  554. ->where('id',$ta_id)
  555. ->select('description')
  556. ->lists('description');
  557. $status = DB::table('transformative_actions')
  558. ->where('id',$ta_id)
  559. ->select('by_professor as status')
  560. ->lists('status');
  561. $status = $status[0];
  562. $plans_count = DB::table('annual_plan_transformative')
  563. ->where('id',$ta_id)
  564. ->get();
  565. $plans_count = count($plans_count);
  566. $can_be_deleted = false;
  567. if($plans_count == 0 && $status == 1){
  568. $can_be_deleted = true;
  569. }
  570. return array(
  571. 'objectives' => $objectives,
  572. 'objectives_from_outcome' => $objectives_from_outcome,
  573. 'selected_courses' => $selected_courses,
  574. 'name' => $name,
  575. 'description' => $description,
  576. 'status' => $status,
  577. 'can_be_deleted' => $can_be_deleted,
  578. 'plans_count' => $plans_count,
  579. );
  580. }
  581. // load the available objectieves from an outcome when creating a Tranformative Action
  582. public function objectivesFromOutcome()
  583. {
  584. $user_id = Auth::user()->id;
  585. $program_id = DB::table('program_user')
  586. ->where('user_id',$user_id)
  587. ->select('program_id')
  588. ->get();
  589. $program_id = $program_id[0]->program_id;
  590. $ta_id = Input::get("ta_id");
  591. $outcome_id = Input::get("outcome_id");
  592. $objectives = DB::table('objectives')
  593. ->join('objective_program','objective_program.objective_id','=','objectives.id')
  594. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','objectives.id')
  595. ->where('criterion_objective_outcome.outcome_id',$outcome_id)
  596. ->where('objective_program.program_id',$program_id)
  597. ->orderBy('objectives.text', 'ASC')
  598. ->select('objectives.text as text', 'objectives.id as id')
  599. ->get();
  600. return array(
  601. 'objectives' => $objectives,
  602. );
  603. }
  604. // return Transformative Actions that meet the filter criterias
  605. public function filterTA()
  606. {
  607. $user_id = Auth::user()->id;
  608. $role = Auth::user()['role'];
  609. $professor_id = Input::get('professor_id');
  610. $course_id = Input::get('course_id');
  611. $outcome_id = Input::get('outcome_id');
  612. $panel_id = Input::get('panel_id');
  613. $program_id = DB::table('program_user')
  614. ->where('user_id',$user_id)
  615. ->select('program_id')
  616. ->get();
  617. $program_id = $program_id[0]->program_id;
  618. // if the user is a coordinator filtering the approvePanel
  619. if ($role == '3' && $panel_id == 'approvePanel'){
  620. // if professor isnt a desired filter, search all professors
  621. if ($professor_id == 0){
  622. $all_ta_users = DB::table('transformative_actions')
  623. ->where('transformative_actions.is_custom', 1)
  624. ->where('transformative_actions.program_id', $program_id)
  625. ->where('transformative_actions.by_professor',1)
  626. ->select('transformative_actions.user_id')
  627. ->get();
  628. $professor_id = array();
  629. foreach ($all_ta_users as $key => $user) {
  630. array_push($professor_id, $user->user_id);
  631. }
  632. }else{
  633. $professor_id = array($professor_id);
  634. }
  635. // if course isnt a desired filter, search all courses
  636. if ($course_id == 0){
  637. $courses = DB::table('ta_course')
  638. ->join('transformative_actions','transformative_actions.id','=','ta_course.ta_id')
  639. ->join('courses','courses.id','=','ta_course.course_id')
  640. ->where('transformative_actions.is_custom', 1)
  641. ->where('transformative_actions.program_id', $program_id)
  642. ->where('transformative_actions.by_professor', 1)
  643. ->select('courses.id')
  644. ->get();
  645. $course_id = array();
  646. foreach ($courses as $key => $course) {
  647. array_push($course_id, $course->id);
  648. }
  649. }else{
  650. $course_id = array($course_id);
  651. }
  652. // if outcome isnt a desired filter, search all outcomes
  653. if ($outcome_id == 0){
  654. $outcomes = DB::table('transformative_actions')
  655. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  656. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  657. ->join('outcomes','outcomes.id','=','criterion_objective_outcome.outcome_id')
  658. ->where('transformative_actions.is_custom', 1)
  659. ->where('transformative_actions.program_id', $program_id)
  660. ->where('transformative_actions.by_professor', 1)
  661. ->select('outcomes.id')
  662. ->groupBy('outcomes.id')
  663. ->get();
  664. $outcome_id = array();
  665. foreach ($outcomes as $key => $outcome) {
  666. array_push($outcome_id, $outcome->id);
  667. }
  668. }else{
  669. $outcome_id = array($outcome_id);
  670. }
  671. // search TA with filters
  672. $filtered_at = DB::table('transformative_actions')
  673. ->join('ta_course','ta_course.ta_id','=','transformative_actions.id')
  674. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  675. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  676. ->where('transformative_actions.is_custom', 1)
  677. ->where('transformative_actions.program_id',$program_id)
  678. ->where('transformative_actions.by_professor',1)
  679. ->whereIn('transformative_actions.user_id',$professor_id)
  680. ->whereIn('criterion_objective_outcome.outcome_id',$outcome_id)
  681. ->whereIn('ta_course.course_id',$course_id)
  682. ->select('transformative_actions.*')
  683. ->groupBy('transformative_actions.id')
  684. ->orderBy('transformative_actions.at_text', 'ASC')
  685. ->get();
  686. return $filtered_at;
  687. }
  688. // if the user is a coordinator filtering the editPanel
  689. elseif($role == '3' && $panel_id == 'editPanel'){
  690. // if professor isnt a desired filter, search all professors
  691. if ($professor_id == 0){
  692. $all_ta_users = DB::table('transformative_actions')
  693. ->where('transformative_actions.is_custom', 1)
  694. ->where('transformative_actions.program_id', $program_id)
  695. ->where('transformative_actions.by_professor',0)
  696. ->select('transformative_actions.user_id')
  697. ->get();
  698. $professor_id = array();
  699. foreach ($all_ta_users as $key => $user) {
  700. array_push($professor_id, $user->user_id);
  701. }
  702. }else{
  703. $professor_id = array($professor_id);
  704. }
  705. // if course isnt a desired filter, search all courses
  706. if ($course_id == 0){
  707. $courses = DB::table('ta_course')
  708. ->join('transformative_actions','transformative_actions.id','=','ta_course.ta_id')
  709. ->join('courses','courses.id','=','ta_course.course_id')
  710. ->where('transformative_actions.is_custom', 1)
  711. ->where('transformative_actions.program_id', $program_id)
  712. ->where('transformative_actions.by_professor', 0)
  713. ->select('courses.id')
  714. ->get();
  715. $course_id = array();
  716. foreach ($courses as $key => $course) {
  717. array_push($course_id, $course->id);
  718. }
  719. }else{
  720. $course_id = array($course_id);
  721. }
  722. // if outcome isnt a desired filter, search all outcomes
  723. if ($outcome_id == 0){
  724. $outcomes = DB::table('transformative_actions')
  725. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  726. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  727. ->join('outcomes','outcomes.id','=','criterion_objective_outcome.outcome_id')
  728. ->where('transformative_actions.is_custom', 1)
  729. ->where('transformative_actions.program_id', $program_id)
  730. ->where('transformative_actions.by_professor', 0)
  731. ->select('outcomes.id')
  732. ->groupBy('outcomes.id')
  733. ->get();
  734. $outcome_id = array();
  735. foreach ($outcomes as $key => $outcome) {
  736. array_push($outcome_id, $outcome->id);
  737. }
  738. }else{
  739. $outcome_id = array($outcome_id);
  740. }
  741. // search TA with filters
  742. $filtered_at = DB::table('transformative_actions')
  743. ->join('ta_course','ta_course.ta_id','=','transformative_actions.id')
  744. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  745. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  746. ->where('transformative_actions.is_custom', 1)
  747. ->where('transformative_actions.program_id',$program_id)
  748. ->where('transformative_actions.by_professor',0)
  749. ->whereIn('transformative_actions.user_id',$professor_id)
  750. ->whereIn('criterion_objective_outcome.outcome_id',$outcome_id)
  751. ->whereIn('ta_course.course_id',$course_id)
  752. ->select('transformative_actions.*')
  753. ->groupBy('transformative_actions.id')
  754. ->orderBy('transformative_actions.at_text', 'ASC')
  755. ->get();
  756. return $filtered_at;
  757. }
  758. // if the user is a professor filtering the editPanel
  759. elseif($role == '4' && $panel_id == 'editPanel'){
  760. // if course isnt a desired filter, search all courses
  761. if ($course_id == 0){
  762. $courses = DB::table('ta_course')
  763. ->join('transformative_actions','transformative_actions.id','=','ta_course.ta_id')
  764. ->join('courses','courses.id','=','ta_course.course_id')
  765. ->where('transformative_actions.user_id', Auth::user()->id)
  766. ->where('transformative_actions.is_custom', 1)
  767. ->where('transformative_actions.program_id', $program_id)
  768. ->where('transformative_actions.by_professor', 1)
  769. ->select('courses.id')
  770. ->get();
  771. $course_id = array();
  772. foreach ($courses as $key => $course) {
  773. array_push($course_id, $course->id);
  774. }
  775. }else{
  776. $course_id = array($course_id);
  777. }
  778. // if outcome isnt a desired filter, search all outcomes
  779. if ($outcome_id == 0){
  780. $outcomes = DB::table('transformative_actions')
  781. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  782. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  783. ->join('outcomes','outcomes.id','=','criterion_objective_outcome.outcome_id')
  784. ->where('transformative_actions.user_id', Auth::user()->id)
  785. ->where('transformative_actions.is_custom', 1)
  786. ->where('transformative_actions.program_id', $program_id)
  787. ->where('transformative_actions.by_professor', 1)
  788. ->select('outcomes.id')
  789. ->groupBy('outcomes.id')
  790. ->get();
  791. $outcome_id = array();
  792. foreach ($outcomes as $key => $outcome) {
  793. array_push($outcome_id, $outcome->id);
  794. }
  795. }else{
  796. $outcome_id = array($outcome_id);
  797. }
  798. // search TA with filters
  799. $filtered_at = DB::table('transformative_actions')
  800. ->join('ta_course','ta_course.ta_id','=','transformative_actions.id')
  801. ->join('transformative_objective_program','transformative_objective_program.ta_id','=','transformative_actions.id')
  802. ->join('criterion_objective_outcome','criterion_objective_outcome.objective_id','=','transformative_objective_program.objective_id')
  803. ->where('transformative_actions.user_id', Auth::user()->id)
  804. ->where('transformative_actions.is_custom', 1)
  805. ->where('transformative_actions.program_id',$program_id)
  806. ->where('transformative_actions.by_professor',1)
  807. ->whereIn('criterion_objective_outcome.outcome_id',$outcome_id)
  808. ->whereIn('ta_course.course_id',$course_id)
  809. ->select('transformative_actions.*')
  810. ->groupBy('transformative_actions.id')
  811. ->orderBy('transformative_actions.at_text', 'ASC')
  812. ->get();
  813. return $filtered_at;
  814. }
  815. return 'ilegal';
  816. }
  817. }