Aucune description

TransformativeActionsController.php 56KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522
  1. <?php
  2. use Illuminate\Support\Facades\Input;
  3. use Illuminate\Support\Facades\Session;
  4. class TransformativeActionsController extends \BaseController
  5. {
  6. // load the Tranformative actions page
  7. public function editTA()
  8. {
  9. $title = "Transformative Action";
  10. $role = Auth::user()['role'];
  11. $outcomes = Outcome::orderBy('name', 'ASC')->lists('name', 'id');
  12. $schools = School::orderBy('name', 'ASC')->get();
  13. $criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
  14. $programs = Program::orderBy('name', 'ASC')->get();
  15. $user_id = auth::user()->id;
  16. switch ($role) {
  17. case 3:
  18. $program_id = DB::table('program_user')
  19. ->where('user_id', $user_id)
  20. ->select('program_id')
  21. ->lists('program_id');
  22. break;
  23. case 2:
  24. $program_id = DB::table('programs')
  25. ->where('school_id', Auth::user()->school_id)
  26. ->lists('id');
  27. break;
  28. }
  29. /*$program_id = DB::table('program_user')
  30. ->where('user_id', $user_id)
  31. ->select('program_id')
  32. ->get();
  33. $program_id = $program_id[0]->program_id; */ //program id 15 debido al user 8
  34. $outcomes = Outcome::orderBy('name', 'ASC')
  35. ->where('deactivation_date', '=', '0000-00-00')
  36. ->orWhereNull('deactivation_date')
  37. ->get();
  38. $objectives = array();
  39. $types = DB::table('transformative_actions')
  40. ->select('type_of_TA')
  41. ->where('type_of_TA', '<>', '')
  42. ->groupBy('type_of_TA')
  43. ->get();
  44. // if user is program coordinator
  45. //1 edit panel: load the TA that
  46. // are custom ('transformative_actions.by_professor' == 0)
  47. // were approved in past ('transformative_actions.is_custom' == 1)
  48. $ta_edit_panel = DB::table('transformative_actions')
  49. ->where('transformative_actions.is_custom', 1)
  50. ->whereIn('transformative_actions.program_id', $program_id)
  51. ->where('transformative_actions.by_professor', 0)
  52. ->orderBy('at_text', 'ASC')
  53. ->get();
  54. //2 approve panel: load TAs that
  55. // can be approved ('transformative_actions.by_professor' == 1)
  56. $ta_approval_panel = DB::table('transformative_actions')
  57. ->where('transformative_actions.is_custom', 1)
  58. ->whereIn('transformative_actions.program_id', $program_id)
  59. ->where('transformative_actions.by_professor', 1)
  60. ->orderBy('at_text', 'ASC')
  61. ->get();
  62. //2.1 approve panel: load the filter options.
  63. // the "->where()" should be the same from $ta_approval_panel,
  64. // but with aditional joins and different select
  65. //
  66. // get the names of the professors
  67. $professor_filter_approvePanel = DB::table('transformative_actions')
  68. ->join('users', 'users.id', '=', 'transformative_actions.user_id')
  69. ->where('transformative_actions.is_custom', 1)
  70. ->whereIn('transformative_actions.program_id', $program_id)
  71. ->where('transformative_actions.by_professor', 1)
  72. ->select('users.*')
  73. ->groupBy('transformative_actions.user_id')
  74. ->orderBy('users.first_name', 'ASC')
  75. ->get();
  76. // get the courses from asociated with a TA
  77. $course_filter_approvePanel = DB::table('ta_course')
  78. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  79. ->join('courses', function ($join) {
  80. $join->on('courses.number', '=', 'ta_course.course_number');
  81. $join->on('courses.code', '=', 'ta_course.course_code');
  82. })
  83. ->where('transformative_actions.is_custom', 1)
  84. ->whereIn('transformative_actions.program_id', $program_id)
  85. ->where('transformative_actions.by_professor', 1)
  86. ->select('courses.*')
  87. ->groupBy('courses.number', 'courses.code', 'courses.name')
  88. ->orderBy('courses.name', 'ASC')
  89. ->orderBy('courses.code', 'ASC')
  90. ->get();
  91. // get the outcome asociated with a TA
  92. $outcome_filter_approvePanel = DB::table('transformative_actions')
  93. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  94. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  95. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  96. ->where('transformative_actions.is_custom', 1)
  97. ->whereIn('transformative_actions.program_id', $program_id)
  98. ->where('transformative_actions.by_professor', 1)
  99. ->select('outcomes.*')
  100. ->groupBy('outcomes.id')
  101. ->orderBy('outcomes.name', 'ASC')
  102. ->get();
  103. //3 edit panel: load the filter options.
  104. // the "->where()" should be the same from $ta_edit_panel,
  105. // but with aditional joins and different select
  106. //
  107. $professor_filter_editPanel = DB::table('transformative_actions')
  108. ->join('users', 'users.id', '=', 'transformative_actions.user_id')
  109. ->where('transformative_actions.is_custom', 1)
  110. ->whereIn('transformative_actions.program_id', $program_id)
  111. ->where('transformative_actions.by_professor', 0)
  112. ->select('users.*')
  113. ->groupBy('transformative_actions.user_id')
  114. ->orderBy('users.first_name', 'ASC')
  115. ->get();
  116. $course_filter_editPanel = DB::table('ta_course')
  117. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  118. ->join('courses', function ($join) {
  119. $join->on('courses.number', '=', 'ta_course.course_number');
  120. $join->on('courses.code', '=', 'ta_course.course_code');
  121. })
  122. ->where('transformative_actions.is_custom', 1)
  123. ->whereIn('transformative_actions.program_id', $program_id)
  124. ->where('transformative_actions.by_professor', 0)
  125. ->select('courses.*')
  126. ->groupBy('courses.number', 'courses.code', 'courses.name')
  127. ->orderBy('courses.name', 'ASC')
  128. ->orderBy('courses.code', 'ASC')
  129. ->get();
  130. $outcome_filter_editPanel = DB::table('transformative_actions')
  131. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  132. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  133. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  134. ->where('transformative_actions.is_custom', 1)
  135. ->whereIn('transformative_actions.program_id', $program_id)
  136. ->where('transformative_actions.by_professor', 0)
  137. ->select('outcomes.*')
  138. ->groupBy('outcomes.id')
  139. ->orderBy('outcomes.name', 'ASC')
  140. ->get();
  141. // 4 create panel: search all courses
  142. $courses_create = DB::table('courses')
  143. ->whereIn('courses.program_id', $program_id)
  144. ->select('courses.*')
  145. ->groupBy('courses.number', 'courses.code', 'courses.name')
  146. ->orderBy('courses.code', 'ASC')
  147. ->orderBy('courses.number', 'ASC')
  148. ->get();
  149. /*
  150. // if user is profesor
  151. elseif ($role == 4) {
  152. // 1 the user can only edit TA that need approval and has been submited by the same user
  153. $ta_edit_panel = DB::table('transformative_actions')
  154. ->where('transformative_actions.is_custom', 1)
  155. ->where('transformative_actions.program_id', $program_id)
  156. ->where('transformative_actions.user_id', Auth::user()->id)
  157. ->where('transformative_actions.by_professor', 1)
  158. ->select('transformative_actions.*')
  159. ->orderBy('at_text', 'ASC')
  160. ->get();
  161. // 2 approve panel: dont load TA since professors cant approve them
  162. $ta_approval_panel = array();
  163. // 3 edit panel: load professor filter for his courses
  164. $professor_filter_editPanel = array();
  165. $course_filter_editPanel = DB::table('ta_course')
  166. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  167. ->join('courses', 'courses.id', '=', 'ta_course.course_id')
  168. ->where('transformative_actions.is_custom', 1)
  169. ->where('transformative_actions.user_id', Auth::user()->id)
  170. ->where('transformative_actions.program_id', $program_id)
  171. ->where('transformative_actions.by_professor', 1)
  172. ->select('courses.*')
  173. ->groupBy('courses.name', 'courses.code')
  174. ->orderBy('courses.name', 'ASC')
  175. ->orderBy('courses.code', 'ASC')
  176. ->get();
  177. $outcome_filter_editPanel = DB::table('transformative_actions')
  178. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  179. ->join('criterion_objective_outcome', 'criterion_objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  180. ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  181. ->where('transformative_actions.is_custom', 1)
  182. ->where('transformative_actions.user_id', Auth::user()->id)
  183. ->where('transformative_actions.program_id', $program_id)
  184. ->where('transformative_actions.by_professor', 1)
  185. ->select('outcomes.*')
  186. ->groupBy('outcomes.id')
  187. ->orderBy('outcomes.name', 'ASC')
  188. ->get();
  189. // these arent used by professors
  190. $professor_filter_approvePanel = array();
  191. $course_filter_approvePanel = array();
  192. $outcome_filter_approvePanel = array();
  193. // 4 create panel: search courses given by the professor
  194. $courses_create = DB::table('courses')
  195. ->where('courses.program_id', $program_id)
  196. ->where('courses.user_id', Auth::user()->id)
  197. ->select('courses.*')
  198. ->groupBy('courses.name', 'courses.code')
  199. ->orderBy('courses.name', 'ASC')
  200. ->orderBy('courses.code', 'ASC')
  201. ->get();
  202. }
  203. */
  204. return View::make('local.managers.admins.transformativeAction', compact(
  205. 'title',
  206. 'role',
  207. 'types',
  208. 'outcomes',
  209. 'schools',
  210. 'criteria',
  211. 'programs',
  212. 'outcomes',
  213. 'objectives',
  214. 'ta_edit_panel',
  215. 'ta_approval_panel',
  216. 'courses_create',
  217. 'professor_filter_approvePanel',
  218. 'course_filter_approvePanel',
  219. 'outcome_filter_approvePanel',
  220. 'professor_filter_editPanel',
  221. 'outcome_filter_editPanel',
  222. 'course_filter_editPanel'
  223. ));
  224. }
  225. private function cleanInput()
  226. {
  227. $clean_input = array();
  228. $trimmed = trim(preg_replace('/\t+/', '', Input::get('text')));
  229. Log::info('trimmed 1 -->' . $trimmed . '<--');
  230. // if ($trimmed == '') {
  231. // $trimmed = NULL;
  232. // } else {
  233. // $trimmed = json_encode(preg_split('/\r\n/', $trimmed));
  234. // }
  235. Log::info('trimmed 2 -->' . $trimmed . '<--');
  236. $clean_input['text'] = $trimmed;
  237. //////
  238. $trimmed = trim(preg_replace('/\t+/', '', Input::get('description')));
  239. Log::info('trimmed 3 -->' . $trimmed . '<--');
  240. // if ($trimmed == '') {
  241. // $trimmed = NULL;
  242. // } else {
  243. // $trimmed = json_encode(preg_split('/\r\n/', $trimmed));
  244. // }
  245. Log::info('trimmed 4 -->' . $trimmed . '<--');
  246. $clean_input['description'] = $trimmed;
  247. $clean_input['objectiveid'] = Input::get('objectiveid');
  248. $clean_input['courseid'] = Input::get('courseid');
  249. $clean_input['approval'] = Input::get('approval');
  250. $clean_input['type'] = Input::get('type_of_ta');
  251. $clean_input['ta_id'] = Input::get('ta_id');
  252. $clean_input['new_type'] = Input::get('new_type');
  253. return $clean_input;
  254. }
  255. private function makeValidator($clean_input)
  256. {
  257. /** Validation rules */
  258. return Validator::make(
  259. array(
  260. 'text' => $clean_input['text'],
  261. 'description' => $clean_input['description'],
  262. 'objectiveid' => $clean_input['objectiveid'],
  263. 'courseid' => $clean_input['courseid'],
  264. 'approval' => $clean_input['approval'],
  265. 'ta_id' => $clean_input['ta_id'],
  266. 'type_of_ta' => $clean_input['type'],
  267. ),
  268. array(
  269. 'text' => 'required|string',
  270. 'description' => 'required|string',
  271. 'objectiveid' => 'required|array',
  272. 'courseid' => 'required|string',
  273. 'approval' => 'integer',
  274. 'ta_id' => 'integer',
  275. 'type_of_ta' => 'required|string'
  276. )
  277. );
  278. }
  279. // Create a Transformative Action
  280. public function createTA()
  281. {
  282. $clean_input = $this->cleanInput();
  283. /** Validation rules */
  284. $validator = $this->makeValidator($clean_input);
  285. /** If validation fails */
  286. if ($validator->fails()) {
  287. /** Prepare error message */
  288. $message = '<p>Error(s) creating a new Transformative Action:</p><ul>';
  289. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  290. $message .= $validationError;
  291. }
  292. $message .= '</ul>';
  293. /** Send error message and old data */
  294. Session::flash('status', 'danger');
  295. Session::flash('message', $message);
  296. $role = Auth::user()['role'];
  297. return Redirect::to('transformativeAction')->withInput();
  298. } else {
  299. $user_id = Auth::user()->id;
  300. /*$program_id = DB::table('program_user')
  301. ->where('user_id', $user_id)
  302. ->select('program_id')
  303. ->get();
  304. $program_id = $program_id[0]->program_id;*/
  305. $role = Auth::user()['role'];
  306. $by_professor = 1;
  307. if ($role != 4) {
  308. $by_professor = 0;
  309. }
  310. Log::info($clean_input['courseid']);
  311. // $by_professor = $clean_input['approval'];
  312. $parentesis = array('(', ')');
  313. $course_code_number = str_replace($parentesis, '', $clean_input['courseid']);
  314. $course_code_number = explode(',', $course_code_number);
  315. $program_id = DB::table('courses')
  316. ->where('code', $course_code_number[0])
  317. ->where('number', $course_code_number[1])
  318. ->select('program_id')
  319. ->first()->program_id;
  320. $current_timestamp = date('Y/m/d H:i:s', time());
  321. if ($clean_input['new_type']) $type = $clean_input['new_type'];
  322. else $type = $clean_input['type'];
  323. // insert the TA
  324. $ta_id = DB::table('transformative_actions')->insertGetId(
  325. array(
  326. 'at_text' => $clean_input['text'],
  327. 'description' => $clean_input['description'],
  328. 'is_custom' => 1,
  329. 'user_id' => $user_id,
  330. 'program_id' => $program_id,
  331. 'created_at' => $current_timestamp,
  332. 'by_professor' => $by_professor,
  333. 'type_of_TA' => $type
  334. )
  335. );
  336. //
  337. // // insert the multiple TA_objective_program
  338. foreach ($clean_input['objectiveid'] as $objective_id) {
  339. DB::table('transformative_objective')->insert(
  340. array(
  341. 'ta_id' => $ta_id,
  342. 'objective_id' => $objective_id,
  343. )
  344. );
  345. }
  346. //
  347. // // insert the multiple TA_course
  348. DB::table('ta_course')->insert(
  349. array(
  350. 'ta_id' => $ta_id,
  351. 'course_number' => $course_code_number[1],
  352. 'course_code' => $course_code_number[0],
  353. )
  354. );
  355. Session::flash('status', 'success');
  356. Session::flash('message', 'Transformative Action created: "' . $clean_input['text'] . '".');
  357. $role = Auth::user()['role'];
  358. return Redirect::to('transformativeAction')->withInput();
  359. }
  360. }
  361. // apporve a Transformative Action
  362. public function approveTA()
  363. {
  364. $role = Auth::user()['role'];
  365. if ($role != 3) {
  366. $message = 'Only Program Coordinators can approve a TA';
  367. Session::flash('status', 'danger');
  368. Session::flash('message', $message);
  369. return Redirect::to('transformativeAction')->withInput();
  370. }
  371. $ta_id = Input::get('ta_id');
  372. $text = Input::get('at_text');
  373. if ($ta_id == 0) {
  374. $message = 'Please select a Transformative Action</p>';
  375. Session::flash('status', 'danger');
  376. Session::flash('message', $message);
  377. $role = Auth::user()['role'];
  378. return Redirect::to('transformativeAction')->withInput();
  379. }
  380. $current_timestamp = date('Y/m/d H:i:s', time());
  381. if (Input::get('new_type')) {
  382. $type = Input::get('new_type');
  383. } else {
  384. $type = Input::get('type_of_ta');
  385. }
  386. // edit the TA
  387. DB::table('transformative_actions')
  388. ->where('id', $ta_id)
  389. ->update([
  390. 'by_professor' => 0,
  391. 'updated_at' => $current_timestamp,
  392. 'type_of_TA' => $type
  393. ]);
  394. Session::flash('status', 'success');
  395. Session::flash('message', 'Approved the Transformative Action: "' . $text . '".');
  396. $role = Auth::user()['role'];
  397. return Redirect::to('transformativeAction')->withInput();
  398. }
  399. // update a Tranformative Action
  400. public function updateTA()
  401. {
  402. $clean_input = $this->cleanInput();
  403. /** Validation rules */
  404. $validator = $this->makeValidator($clean_input);
  405. /** If validation fails */
  406. if ($validator->fails()) {
  407. /** Prepare error message */
  408. $message = 'Error(s) updating the Transformative Action: <ul>';
  409. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  410. $message .= $validationError;
  411. }
  412. $message .= '</ul>';
  413. /** Send error message and old data */
  414. Session::flash('status', 'danger');
  415. Session::flash('message', $message);
  416. $role = Auth::user()['role'];
  417. return Redirect::to('transformativeAction')->withInput();
  418. } else {
  419. $parentesis = array('(', ')');
  420. $course_code_number = str_replace($parentesis, '', $clean_input['courseid']);
  421. $course_code_number = explode(',', $course_code_number);
  422. $program_id = DB::table('courses')
  423. ->where('code', $course_code_number[0])
  424. ->where('number', $course_code_number[1])
  425. ->select('program_id')
  426. ->first()->program_id;
  427. $user_id = auth::user()->id;
  428. /* $program_id = DB::table('program_user')
  429. ->where('user_id', $user_id)
  430. ->select('program_id')
  431. ->get();
  432. $program_id = $program_id[0]->program_id;*/
  433. $role = Auth::user()['role'];
  434. $by_professor = $clean_input['approval'];
  435. if ($role == 4) {
  436. $by_professor = 1;
  437. }
  438. // $by_professor = $clean_input['approval'];
  439. if ($clean_input['new_type']) $type = $clean_input['new_type'];
  440. else $type = $clean_input['type'];
  441. $current_timestamp = date('Y/m/d H:i:s', time());
  442. // edit the TA
  443. DB::table('transformative_actions')
  444. ->where('id', $clean_input['ta_id'])
  445. ->update([
  446. 'by_professor' => $by_professor,
  447. 'at_text' => $clean_input['text'],
  448. 'description' => $clean_input['description'],
  449. 'updated_at' => $current_timestamp,
  450. 'type_of_TA' => $type
  451. ]);
  452. $ta_id = $clean_input['ta_id'];
  453. $new_objective_id = $clean_input['objectiveid'];
  454. $old_objective_id = DB::table('transformative_objective')
  455. ->where('ta_id', $ta_id)
  456. ->select('objective_id')
  457. ->lists('objective_id');
  458. //delete existing objective_id if it isnt in new_ids array
  459. foreach ($old_objective_id as $old_id) {
  460. if (in_array($old_id, $new_objective_id)) {
  461. //do nothing if a new id is already in atble
  462. } else {
  463. //if old id not in new id, delete
  464. DB::table('transformative_objective')
  465. ->where('ta_id', $ta_id)
  466. ->where('objective_id', $old_id)
  467. ->delete();
  468. }
  469. }
  470. //
  471. foreach ($new_objective_id as $new_id) {
  472. $result = DB::table('transformative_objective')
  473. ->where('objective_id', $new_id)
  474. ->select('objective_id')
  475. ->lists('objective_id');
  476. if (count($result) == 0) {
  477. //if the new_id does not exists, do nothing
  478. DB::table('transformative_objective')->insert(
  479. array(
  480. 'ta_id' => $ta_id,
  481. 'objective_id' => $new_id,
  482. // 'created_at' => $current_timestamp,
  483. )
  484. );
  485. } else {
  486. //if the new_id already exists, do nothing
  487. }
  488. }
  489. DB::update(
  490. "UPDATE `ta_course` set `course_number` = '{$course_code_number[1]}', `course_code` = '{$course_code_number[0]}' where ta_id = {$ta_id}"
  491. );
  492. /*$new_course_id = $clean_input['courseid'];
  493. $old_course_id = DB::table('ta_course')
  494. ->where('ta_id', $ta_id)
  495. ->select('course_id')
  496. ->lists('course_id');
  497. //delete existing course_id if it isnt in new_ids array
  498. foreach ($old_course_id as $old_id) {
  499. if (in_array($old_id, $new_course_id)) {
  500. //do nothing if a new id is already in atble
  501. } else {
  502. //if old id not in new id, delete
  503. DB::table('ta_course')
  504. ->where('ta_id', $ta_id)
  505. ->where('course_id', $old_id)
  506. ->delete();
  507. }
  508. }
  509. //add course_id if it isnt already inserted
  510. foreach ($new_course_id as $new_id) {
  511. $result = DB::table('ta_course')
  512. ->where('ta_id', $ta_id)
  513. ->where('course_id', $new_id)
  514. ->select('course_id')
  515. ->lists('course_id');
  516. if (count($result) == 0) {
  517. //if the new_id does not exists, do nothing
  518. DB::table('ta_course')->insert(
  519. array(
  520. 'ta_id' => $ta_id,
  521. 'course_id' => $new_id,
  522. )
  523. );
  524. } else {
  525. //if the new_id already exists, do nothing
  526. }
  527. } */
  528. Session::flash('status', 'success');
  529. Session::flash('message', 'Updated Transformative Action: "' . $clean_input['text'] . '".');
  530. $role = Auth::user()['role'];
  531. return Redirect::to('transformativeAction')->withInput();
  532. }
  533. }
  534. // delete a Transformative Action
  535. public function deleteTA()
  536. {
  537. $ta_id = array(Input::get('ta_id'));
  538. // si envia id 0, el backend se queja en la linea: $ta = $ta[0];
  539. // nunca deberia ocurrir, pero es un safity measure.
  540. if ($ta_id == 0) {
  541. $message = 'Please select a Transformative Action</p>';
  542. Session::flash('status', 'danger');
  543. Session::flash('message', $message);
  544. //$role = Auth::user()['role'];
  545. return Redirect::to('transformativeAction')->withInput();
  546. }
  547. $ta = DB::table('transformative_actions')
  548. ->where('transformative_actions.is_custom', 1)
  549. ->where('id', $ta_id)
  550. ->get();
  551. $ta = $ta[0];
  552. $used = DB::table('annual_plan_transformative')
  553. ->where('id', $ta_id)
  554. ->get();
  555. $recommended = $ta->by_professor;
  556. // the TA can only be deleted if error if the TA is not currently as "Recommended"
  557. // and isnt used in an anual plan
  558. if ($recommended == 1 && count($used) == 0) {
  559. // delete the TA if it qualifies
  560. DB::delete("delete from transformative_actions where id = ?", $ta_id);
  561. $name = $ta->at_text;
  562. $message = 'The Transformative Action has been deleted:</p><ul>';
  563. $message .= '<li> ' . $name . ' </li>';
  564. $message .= '</ul>';
  565. Session::flash('status', 'success');
  566. Session::flash('message', $message);
  567. $role = Auth::user()['role'];
  568. return Redirect::to('transformativeAction')->withInput();
  569. }
  570. $message = 'Transformative Actions can only be deleted if:</p><ul>';
  571. $message .= '<li> It has a status of "Recommended"</li>';
  572. $message .= '<li> It is not currently used in a plan</li>';
  573. $message .= '</ul>';
  574. Session::flash('status', 'danger');
  575. Session::flash('message', $message);
  576. $role = Auth::user()['role'];
  577. return Redirect::to('transformativeAction')->withInput();
  578. }
  579. // load the information of a Tranformative Action when its
  580. // selected on the approve or edit panel
  581. public function selectTA()
  582. {
  583. $ta_id = Input::get("ta_id");
  584. $user_role = Auth::user()->role;
  585. switch ($user_role) {
  586. case 1:
  587. $program_ids = DB::table('programs')->lists('id');
  588. break;
  589. case 2:
  590. $user_school = Auth::user()->school_id;
  591. $program_ids = DB::table('programs')
  592. ->where('school_id', $user_school)
  593. ->lists('id');
  594. break;
  595. case 3:
  596. $user_id = Auth::user()->id;
  597. $program_ids = DB::table('program_user')
  598. ->where('user_id', $user_id)
  599. ->select('program_id')
  600. ->lists('program_id');
  601. break;
  602. }
  603. //$program_id = DB::table('program_user')
  604. // ->where('user_id', $user_id)
  605. // ->select('program_id')
  606. // ->get();
  607. //$program_id = $program_id[0]->program_id;
  608. $objectives = DB::table('transformative_actions')
  609. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  610. ->join('objectives', 'objectives.id', '=', 'transformative_objective.objective_id')
  611. ->where('transformative_actions.id', $ta_id)
  612. ->where('objectives.id', '<>', 0)
  613. ->select('objectives.text as text', 'objectives.id as id')
  614. ->orderBy('objectives.text', 'ASC')
  615. ->get();
  616. $objective_ids = DB::table('transformative_actions')
  617. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  618. ->join('objectives', 'objectives.id', '=', 'transformative_objective.objective_id')
  619. ->where('transformative_actions.id', $ta_id)
  620. ->where('objectives.id', '<>', 0)
  621. ->select('objectives.text as text', 'objectives.id as id')
  622. ->orderBy('objectives.text', 'ASC')
  623. ->lists('objectives.id');
  624. Log::info($ta_id);
  625. //$an_objective = $objectives[0]->id;
  626. $outcome_ids = DB::table('objective_outcome')
  627. ->whereIn('objective_outcome.objective_id', $objective_ids)
  628. ->select('objective_outcome.outcome_id')
  629. ->lists('outcome_id');
  630. //$outcome_id = $outcome_id[0]->outcome_id;
  631. Log::info("outcomes");
  632. Log::info($outcome_ids);
  633. $objectives_from_outcome = DB::table('objectives')
  634. ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
  635. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
  636. ->whereIn('objective_outcome.outcome_id', $outcome_ids)
  637. ->whereIn('objective_program.program_id', $program_ids)
  638. ->where('objective_outcome.objective_id', '<>', 0)
  639. ->orderBy('objectives.text', 'ASC')
  640. ->select('objectives.text as text', 'objectives.id as id')
  641. ->distinct()
  642. ->get();
  643. $selected_courses = DB::table('ta_course')
  644. ->join('courses', function ($join) {
  645. $join->on('courses.number', '=', 'ta_course.course_number');
  646. $join->on('courses.code', '=', 'ta_course.course_code');
  647. })
  648. ->where('ta_id', $ta_id)
  649. ->orderBy('courses.name', 'ASC')
  650. ->orderBy('courses.code', 'ASC')
  651. ->select('courses.*')
  652. ->get();
  653. $name = DB::table('transformative_actions')
  654. ->where('id', $ta_id)
  655. ->select('at_text as name')
  656. ->lists('name');
  657. $description = DB::table('transformative_actions')
  658. ->where('id', $ta_id)
  659. ->select('description')
  660. ->lists('description');
  661. $status = DB::table('transformative_actions')
  662. ->where('id', $ta_id)
  663. ->select('by_professor as status')
  664. ->lists('status');
  665. $status = $status[0];
  666. $plans_count = DB::table('annual_plan_transformative')
  667. ->where('trans_id', $ta_id)
  668. ->get();
  669. $plans_count = count($plans_count);
  670. $can_be_deleted = false;
  671. if ($plans_count == 0 /*&& $status == 1*/) {
  672. $can_be_deleted = true;
  673. }
  674. return array(
  675. 'objectives' => $objectives,
  676. 'objectives_from_outcome' => $objectives_from_outcome,
  677. 'selected_courses' => $selected_courses,
  678. 'name' => $name,
  679. 'description' => $description,
  680. 'status' => $status,
  681. 'can_be_deleted' => $can_be_deleted,
  682. 'plans_count' => $plans_count,
  683. );
  684. }
  685. // load the available objectieves from an outcome when creating a Tranformative Action
  686. public function objectivesFromOutcome()
  687. {
  688. $user_role = Auth::user()->role;
  689. switch ($user_role) {
  690. case 1:
  691. $program_ids = DB::table('programs')->lists('id');
  692. break;
  693. case 2:
  694. $user_school = Auth::user()->school_id;
  695. $program_ids = DB::table('programs')
  696. ->where('school_id', $user_school)
  697. ->lists('id');
  698. break;
  699. case 3:
  700. $user_id = Auth::user()->id;
  701. $program_ids = DB::table('program_user')
  702. ->where('user_id', $user_id)
  703. ->select('program_id')
  704. ->lists('program_id');
  705. break;
  706. }
  707. //$program_id = DB::table('program_user')
  708. // ->where('user_id', $user_id)
  709. // ->select('program_id')
  710. // ->get();
  711. //$program_id = $program_id[0]->program_id;
  712. $ta_id = Input::get("ta_id");
  713. $outcome_id = Input::get("outcome_id");
  714. $objectives = DB::table('objectives')
  715. ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
  716. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
  717. ->where('objective_outcome.outcome_id', $outcome_id)
  718. ->where('objective_outcome.objective_id', '<>', 0)
  719. ->whereIn('objective_program.program_id', $program_ids)
  720. ->orderBy('objectives.text', 'ASC')
  721. ->select('objectives.text as text', 'objectives.id as id')
  722. ->distinct()
  723. ->get();
  724. return array(
  725. 'objectives' => $objectives,
  726. );
  727. }
  728. // return Transformative Actions that meet the filter criterias
  729. public function filterTA()
  730. {
  731. $user_id = Auth::user()->id;
  732. $role = Auth::user()['role'];
  733. $professor_id = Input::get('professor_id');
  734. $course_id = Input::get('course_id');
  735. $outcome_id = Input::get('outcome_id');
  736. $panel_id = Input::get('panel_id');
  737. switch ($role) {
  738. case 1:
  739. $program_id = DB::table('programs')->lists('id');
  740. break;
  741. case 2:
  742. $program_id = DB::table('programs')->where('school_id', Auth::user()->school_id)
  743. ->lists('id');
  744. break;
  745. case 3:
  746. $program_id = DB::table('program_user')
  747. ->where('user_id', $user_id)
  748. ->lists('program_id');
  749. break;
  750. }
  751. // if the user is a coordinator filtering the approvePanel
  752. /*if ($role == '3' && $panel_id == 'approvePanel') {
  753. // if professor isnt a desired filter, search all professors
  754. if ($professor_id == 0) {
  755. $all_ta_users = DB::table('transformative_actions')
  756. ->where('transformative_actions.is_custom', 1)
  757. ->where('transformative_actions.program_id', $program_id)
  758. ->where('transformative_actions.by_professor', 1)
  759. ->select('transformative_actions.user_id')
  760. ->get();
  761. $professor_id = array();
  762. foreach ($all_ta_users as $key => $user) {
  763. array_push($professor_id, $user->user_id);
  764. }
  765. } else {
  766. $professor_id = array($professor_id);
  767. }
  768. // if course isnt a desired filter, search all courses
  769. if ($course_id == 0) {
  770. $courses = DB::table('ta_course')
  771. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  772. ->join('courses', function ($join) {
  773. $join->on('courses.number', '=', 'ta_course.course_number');
  774. $join->on('courses.code', '=', 'ta_course.course_code');
  775. })
  776. ->where('transformative_actions.is_custom', 1)
  777. ->where('transformative_actions.program_id', $program_id)
  778. ->where('transformative_actions.by_professor', 1)
  779. ->select('ta_course.course_number', 'ta_course.course_code')
  780. ->distinct()
  781. ->get();
  782. $course_id = array();
  783. foreach ($courses as $key => $course) {
  784. array_push($course_id["number"], $course->course_number);
  785. array_push($course_id["code"], $course->code);
  786. }
  787. } else {
  788. $parentesis = array('(', ')');
  789. $course_code_number = str_replace($parentesis, '', $course_id);
  790. $course_code_number = explode(',', $course_code_number);
  791. $course_id = array();
  792. $course_id['number'] = $course_code_number[1];
  793. $course_id['code'] = $course_code_number[0];
  794. }
  795. // if outcome isnt a desired filter, search all outcomes
  796. if ($outcome_id == 0) {
  797. $outcomes = DB::table('transformative_actions')
  798. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  799. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  800. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  801. ->where('transformative_actions.is_custom', 1)
  802. ->where('transformative_actions.program_id', $program_id)
  803. ->where('transformative_actions.by_professor', 1)
  804. ->select('outcomes.id')
  805. ->groupBy('outcomes.id')
  806. ->get();
  807. $outcome_id = array();
  808. foreach ($outcomes as $key => $outcome) {
  809. array_push($outcome_id, $outcome->id);
  810. }
  811. } else {
  812. $outcome_id = array($outcome_id);
  813. }
  814. // search TA with filters
  815. $filtered_at = DB::table('transformative_actions')
  816. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  817. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  818. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  819. ->where('transformative_actions.is_custom', 1)
  820. ->where('transformative_actions.program_id', $program_id)
  821. ->where('transformative_actions.by_professor', 1)
  822. ->whereIn('transformative_actions.user_id', $professor_id)
  823. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  824. ->whereIn('ta_course.course_code', $course_id['code'])
  825. ->whereIn('ta_course.course_number', $course_id['number'])
  826. ->select('transformative_actions.*')
  827. ->groupBy('transformative_actions.id')
  828. ->orderBy('transformative_actions.at_text', 'ASC')
  829. ->get();
  830. return $filtered_at;
  831. }*/
  832. // if the user is a coordinator filtering the editPanel
  833. if ($panel_id == 'editPanel') {
  834. // if professor isnt a desired filter, search all professors
  835. if ($professor_id == 0) {
  836. $all_ta_users = DB::table('transformative_actions')
  837. ->where('transformative_actions.is_custom', 1)
  838. ->where('transformative_actions.program_id', $program_id)
  839. ->where('transformative_actions.by_professor', 0)
  840. ->select('transformative_actions.user_id')
  841. ->get();
  842. $professor_id = array();
  843. foreach ($all_ta_users as $key => $user) {
  844. array_push($professor_id, $user->user_id);
  845. }
  846. } else {
  847. $professor_id = array($professor_id);
  848. }
  849. // if course isnt a desired filter, search all courses
  850. if ($course_id == 0) {
  851. $courses = DB::table('ta_course')
  852. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  853. ->join('courses', function ($join) {
  854. $join->on('courses.number', '=', 'ta_course.course_number');
  855. $join->on('courses.code', '=', 'ta_course.course_code');
  856. })
  857. ->where('transformative_actions.is_custom', 1)
  858. ->where('transformative_actions.program_id', $program_id)
  859. ->where('transformative_actions.by_professor', 0)
  860. ->select('ta_course.course_number', 'ta_course.course_code')
  861. ->distinct()
  862. ->get();
  863. $course_id = array();
  864. foreach ($courses as $key => $course) {
  865. array_push($course_id["number"], $course->course_number);
  866. array_push($course_id["code"], $course->code);
  867. }
  868. } else {
  869. $parentesis = array('(', ')');
  870. $course_code_number = str_replace($parentesis, '', $course_id);
  871. $course_code_number = explode(',', $course_code_number);
  872. $course_id = array();
  873. $course_id['number'] = $course_code_number[1];
  874. $course_id['code'] = $course_code_number[0];
  875. }
  876. // if outcome isnt a desired filter, search all outcomes
  877. if ($outcome_id == 0) {
  878. $outcomes = DB::table('transformative_actions')
  879. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  880. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  881. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  882. ->where('transformative_actions.is_custom', 1)
  883. ->where('transformative_actions.program_id', $program_id)
  884. ->where('transformative_actions.by_professor', 0)
  885. ->select('outcomes.id')
  886. ->groupBy('outcomes.id')
  887. ->get();
  888. $outcome_id = array();
  889. foreach ($outcomes as $key => $outcome) {
  890. array_push($outcome_id, $outcome->id);
  891. }
  892. } else {
  893. $outcome_id = array($outcome_id);
  894. }
  895. // search TA with filters
  896. $filtered_at = DB::table('transformative_actions')
  897. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  898. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  899. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  900. ->where('transformative_actions.is_custom', 1)
  901. ->where('transformative_actions.program_id', $program_id)
  902. ->where('transformative_actions.by_professor', 0)
  903. ->whereIn('transformative_actions.user_id', $professor_id)
  904. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  905. ->whereIn('ta_course.course_code', $course_id['code'])
  906. ->whereIn('ta_course.course_number', $course_id['number'])
  907. ->select('transformative_actions.*')
  908. ->groupBy('transformative_actions.id')
  909. ->orderBy('transformative_actions.at_text', 'ASC')
  910. ->get();
  911. return $filtered_at;
  912. }
  913. // if the user is a professor filtering the editPanel
  914. /*elseif ($role == '4' && $panel_id == 'editPanel') {
  915. // if course isnt a desired filter, search all courses
  916. if ($course_id == 0) {
  917. $courses = DB::table('ta_course')
  918. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  919. ->join('courses', 'courses.id', '=', 'ta_course.course_id')
  920. ->where('transformative_actions.user_id', Auth::user()->id)
  921. ->where('transformative_actions.is_custom', 1)
  922. ->where('transformative_actions.program_id', $program_id)
  923. ->where('transformative_actions.by_professor', 1)
  924. ->select('ta_course.course_number', 'ta_course.course_code')
  925. ->distinct()
  926. ->get();
  927. $course_id = array();
  928. foreach ($courses as $key => $course) {
  929. array_push($course_id["number"], $course->course_number);
  930. array_push($course_id["code"], $course->code);
  931. }
  932. } else {
  933. $parentesis = array('(', ')');
  934. $course_code_number = str_replace($parentesis, '', $course_id);
  935. $course_code_number = explode(',', $course_code_number);
  936. $course_id = array();
  937. $course_id['number'] = $course_code_number[1];
  938. $course_id['code'] = $course_code_number[0];
  939. }
  940. // if outcome isnt a desired filter, search all outcomes
  941. if ($outcome_id == 0) {
  942. $outcomes = DB::table('transformative_actions')
  943. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  944. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  945. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  946. ->where('transformative_actions.user_id', Auth::user()->id)
  947. ->where('transformative_actions.is_custom', 1)
  948. ->where('transformative_actions.program_id', $program_id)
  949. ->where('transformative_actions.by_professor', 1)
  950. ->select('outcomes.id')
  951. ->groupBy('outcomes.id')
  952. ->get();
  953. $outcome_id = array();
  954. foreach ($outcomes as $key => $outcome) {
  955. array_push($outcome_id, $outcome->id);
  956. }
  957. } else {
  958. $outcome_id = array($outcome_id);
  959. }
  960. // search TA with filters
  961. $filtered_at = DB::table('transformative_actions')
  962. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  963. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  964. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  965. ->where('transformative_actions.user_id', Auth::user()->id)
  966. ->where('transformative_actions.is_custom', 1)
  967. ->where('transformative_actions.program_id', $program_id)
  968. ->where('transformative_actions.by_professor', 1)
  969. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  970. ->whereIn('ta_course.course_code', $course_id['code'])
  971. ->whereIn('ta_course.course_number', $course_id['number'])
  972. ->select('transformative_actions.*')
  973. ->groupBy('transformative_actions.id')
  974. ->orderBy('transformative_actions.at_text', 'ASC')
  975. ->get();
  976. return $filtered_at;
  977. }*/
  978. return 'ilegal';
  979. }
  980. function postActivityCriterion($activity_id)
  981. {
  982. DB::beginTransaction();
  983. $existing_transformative_action = DB::table('transformative_actions')
  984. ->join('transformative_activity_criterion', 'transformative_activity_criterion.trans_action_id', '=', 'transformative_actions.id')
  985. ->join('activity_criterion', 'activity_criterion.id', '=', 'transformative_activity_criterion.activity_criterion_id')
  986. ->where('activity_id', $activity_id)
  987. ->delete();
  988. $activity_criterion = Input::get('trans_act');
  989. $trans = new TransformativeAction;
  990. $trans->user_id = Auth::user()['id'];
  991. $program_id = DB::table('activities')
  992. ->join('courses', 'activities.course_id', '=', 'courses.id')
  993. ->where('activities.id', $activity_id)
  994. ->lists('program_id');
  995. $trans->program_id = $program_id[0];
  996. $trans->is_custom = 1;
  997. $trans->by_professor = 1;
  998. $trans->at_text = Input::get('name_trans');
  999. $trans->description = Input::get('transforming_actions');
  1000. $activity = DB::table('activities')
  1001. ->where('id', $activity_id)
  1002. ->first();
  1003. $course_credentials = DB::table('courses')
  1004. ->where('id', $activity->course_id)
  1005. ->first();
  1006. if ($trans->save()) {
  1007. foreach ($activity_criterion as $single_ac) {
  1008. $result = DB::insert("insert into `transformative_activity_criterion` (`trans_action_id`, `activity_criterion_id`) values ($trans->id, $single_ac)");
  1009. if (!$result) {
  1010. DB::rollback();
  1011. Session::flash('status', 'danger');
  1012. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1013. return Redirect::to("professor/activities/{$activity_id}");
  1014. }
  1015. }
  1016. $criteria = DB::table('activity_criterion')
  1017. ->whereIn('id', $activity_criterion)
  1018. ->lists('criterion_id');
  1019. $allObjectives = DB::table('criterion_objective_outcome')
  1020. ->whereIn('criterion_id', $criteria)
  1021. ->select('objective_id')
  1022. ->distinct()
  1023. ->lists('objective_id');
  1024. foreach ($allObjectives as $objective) {
  1025. $result2 = DB::insert("insert into `transformative_objective` (`ta_id`, `objective_id`) values ({$trans->id},{$objective})");
  1026. if (!$result2) {
  1027. DB::rollback();
  1028. Session::flash('status', 'danger');
  1029. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1030. return Redirect::to("professor/activities/{$activity_id}");
  1031. }
  1032. }
  1033. $result3 = DB::insert("insert into `ta_course` (`ta_id`, `course_number`, `course_code`) values ({$trans->id}, '{$course_credentials->number}', '{$course_credentials->code}')");
  1034. if (!($result3)) {
  1035. DB::rollback();
  1036. Session::flash('status', 'danger');
  1037. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1038. return Redirect::to("professor/activities/{$activity_id}");
  1039. }
  1040. DB::commit();
  1041. Session::flash('status', 'success');
  1042. Session::flash('message', 'Formative Actions Saved.');
  1043. return Redirect::to("professor/activities/{$activity_id}");
  1044. } else {
  1045. DB::rollback();
  1046. Session::flash('status', 'danger');
  1047. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1048. return Redirect::to("professor/activities/{$activity_id}");
  1049. }
  1050. }
  1051. public function viewFormativeActions()
  1052. {
  1053. $title = "Formative Actions";
  1054. $semesters = Session::get('semesters_ids');
  1055. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  1056. Log::info($semesters->start);
  1057. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  1058. ->whereNull('deleted_at')
  1059. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  1060. ->orderBy('name', 'ASC')->get();
  1061. $semesters = DB::table('semesters')->where('is_visible', 1)->orderBy('end', 'DESC')->get();
  1062. $role = Auth::user()->role;
  1063. switch ($role) {
  1064. case 1:
  1065. $schools = DB::table('schools')->get();
  1066. $programs = DB::table('programs')->get();
  1067. break;
  1068. case 2:
  1069. $schools = DB::table('schools')->where('id', Auth::user()->school_id)->get();
  1070. $programs = DB::table('programs')->where('school_id', $schools[0]->id)->get();
  1071. break;
  1072. case 3:
  1073. $programs = DB::table('programs')
  1074. ->join('program_user', 'programs.id', '=', 'program_user.program_id')
  1075. ->where('user_id', Auth::user()->id)
  1076. ->select('programs.*')
  1077. ->get();
  1078. $schools = DB::table('schools')->where('id', $programs[0]->school_id)->get();
  1079. break;
  1080. }
  1081. return View::make('local.managers.shared.view_formative', compact('title', 'outcomes', 'schools', 'programs', 'semesters'));
  1082. }
  1083. public function fetchCourses()
  1084. {
  1085. $school = Input::get('schools');
  1086. $programs = Input::get('programs');
  1087. $semesters = Input::get('semesters');
  1088. $outcome_id = Input::get('id');
  1089. Log::info($programs);
  1090. Log::info($semesters);
  1091. /* if (in_array(0, $semesters)) {
  1092. $semesters = DB::table('semesters')->where('is_visible', 1)->lists('id');
  1093. }*/
  1094. /* if (in_array(0, $programs)) {
  1095. $role = Auth::user()->role;
  1096. switch ($role) {
  1097. case 1:
  1098. $programs = DB::table('programs')->lists('id');
  1099. break;
  1100. case 2:
  1101. $programs = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
  1102. break;
  1103. case 3:
  1104. $programs = DB::table('program_user')->where('user_id', Auth::user()->id)->lists('program_id');
  1105. break;
  1106. }
  1107. }*/
  1108. $typ_semester_outcome = DB::table('typ_semester_outcome')
  1109. ->where('semester_id', $semesters)
  1110. ->where('outcome_id', $outcome_id)
  1111. ->lists('id');
  1112. //each row has objectives, repeated ta, but distinct activity_criterion_id
  1113. /* $objective_ta = DB::table('typ_semester_objectives')
  1114. ->join('transformative_objective as trob', 'trob.objective_id', '=', 'typ_semester_objectives.objective_id')
  1115. ->join('objectives', 'trob.objective_id', '=', 'objective_id')
  1116. ->join('transformative_actions', 'transformative_actions.id', 'trob.ta_id')
  1117. ->whereIn('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome)
  1118. ->select('transformative_actions.*')
  1119. ->addSelect('objectives.*')
  1120. ->distinct()
  1121. ->get();
  1122. $objective_ta = DB::table('typ_semester_objectives')
  1123. ->join('transformative_objective as trob', 'trob.objective_id', '=', 'typ_semester_objectives.objective_id')
  1124. ->join('objectives', 'trob.objective_id', '=', 'objective_id')
  1125. ->join('transformative_actions', 'transformative_actions.id', 'trob.ta_id')
  1126. ->whereIn('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome)
  1127. ->select('transformative_actions.*')
  1128. ->addSelect('objectives.*')
  1129. ->distinct()
  1130. ->lists();*/
  1131. $grouped_courses = DB::table('courses')
  1132. ->where('program_id', $programs)
  1133. ->where('semester_id', $semesters)
  1134. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1135. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  1136. ->join('transformative_activity_criterion as tac', 'tac.activity_criterion_id', '=', 'activity_criterion.id')
  1137. ->select('courses.*')
  1138. ->groupBy(array('courses.code', 'courses.name', 'courses.semester_id'))
  1139. ->orderBy('courses.code')
  1140. ->orderBy('courses.number')
  1141. ->get();
  1142. foreach ($grouped_courses as $course_name) {
  1143. $course_name->sections = DB::table('courses')
  1144. ->where('code', $course_name->code)
  1145. ->where('name', $course_name->name)
  1146. ->where('semester_id', $course_name->semester_id)
  1147. ->where('program_id', $course_name->program_id)
  1148. ->get();
  1149. foreach ($course_name->sections as $section) {
  1150. $section->activities = DB::table('activities')
  1151. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  1152. ->join('transformative_activity_criterion', 'transformative_activity_criterion.activity_criterion_id', '=', 'activity_criterion.id')
  1153. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  1154. ->join('transformative_actions', 'transformative_activity_criterion.trans_action_id', '=', 'transformative_actions.id')
  1155. ->where('activities.course_id', $section->id)
  1156. ->where('activities.draft', 0)
  1157. ->where('activities.diagnostic', 0)
  1158. ->where('criterion_objective_outcome.outcome_id', $outcome_id)
  1159. ->select('activities.id as activity_id', 'activities.name')
  1160. ->addSelect('transformative_actions.*', 'transformative_activity_criterion.trans_action_id as trans_action_id')
  1161. ->groupBy('transformative_actions.id')
  1162. ->get();
  1163. //If section has activity that assessess outcome
  1164. if (count($section->activities)) {
  1165. $course_name->outcome_assessed = true;
  1166. }
  1167. foreach ($section->activities as $activity) {
  1168. /*$activity->criterion = DB::table('transformative_activity_criterion')
  1169. ->join('activity_criterion','activity_criterion.id','=','transformative_activity_criterion.activity_criterion_id')
  1170. ->join('activities','activities.id','=','activity_criterion.activity_id')
  1171. ->join('criteria','activity_criterion.criterion_id','=','criteria.id')
  1172. ->where('activity_id', $activity->id)
  1173. ->select('criteria')*/
  1174. //Log::info($activity->trans_action_id);
  1175. $activity->criterion_with_objective = DB::table('transformative_activity_criterion')
  1176. ->join('activity_criterion', 'activity_criterion.id', '=', 'transformative_activity_criterion.activity_criterion_id')
  1177. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  1178. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  1179. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  1180. ->where('activity_id', $activity->activity_id)
  1181. ->where('trans_action_id', $activity->trans_action_id)
  1182. ->get();
  1183. /*$activity->objectives = DB::table('transformative_objective')
  1184. ->join('objectives', 'transformative_objective.objective_id', '=', 'objectives.id')
  1185. ->where('ta_id', $activity->trans_action_id)
  1186. ->get();*/
  1187. /*foreach ($activity->objectives as $objective) {
  1188. // Log::info($activity->activity_id);
  1189. // Log::info($objective->objective_id);
  1190. /* Log::info(DB::table('criterion_objective_outcome')
  1191. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
  1192. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  1193. ->where('activity_criterion.activity_id', $activity->activity_id)
  1194. ->where('objective_id', $objective->objective_id)
  1195. ->select('criteria.*')
  1196. ->distinct()
  1197. ->toSql());
  1198. $objective->criterion = DB::table('criterion_objective_outcome')
  1199. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
  1200. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  1201. ->where('activity_criterion.activity_id', $activity->activity_id)
  1202. ->where('objective_id', $objective->objective_id)
  1203. ->select('criteria.*')
  1204. ->distinct()
  1205. ->get();
  1206. }*/
  1207. }
  1208. }
  1209. }
  1210. return $grouped_courses;
  1211. }
  1212. public function createTAForOutcome()
  1213. {
  1214. $is_custom = Input::get('is_custom');
  1215. $category = Input::get('category');
  1216. $is_new = Input::get('is_new');
  1217. $name = Input::get('name');
  1218. $description = Input::get('description');
  1219. $edit_ta_id = Input::get('edit');
  1220. if ($is_new || $is_custom)
  1221. $program_id = Input::get('program_id');
  1222. else $program_id = NULL;
  1223. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  1224. if (!$edit_ta_id) {
  1225. $ta_id = DB::table('transformative_actions')->insertGetId(array(
  1226. 'program_id' => $program_id,
  1227. 'type_of_TA' => $category,
  1228. 'at_text' => $name,
  1229. 'description' => $description,
  1230. 'user_id' => Auth::user()->id,
  1231. 'created_at' => date('Y-m-d H:i:s'),
  1232. 'updated_at' => date('Y-m-d H:i:s'),
  1233. 'by_professor' => 0,
  1234. 'is_custom' => $is_custom
  1235. ));
  1236. DB::table('transformative_typ_outcome')->insert(array(
  1237. 'trans_id' => $ta_id,
  1238. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  1239. 'proposing_coordinator_id' => Auth::user()->id,
  1240. ));
  1241. } else {
  1242. DB::table('transformative_actions')
  1243. ->where('id', $edit_ta_id)
  1244. ->update(array(
  1245. 'program_id' => $program_id,
  1246. 'type_of_TA' => $category,
  1247. 'at_text' => $name,
  1248. 'description' => $description,
  1249. 'user_id' => Auth::user()->id,
  1250. 'created_at' => date('Y-m-d H:i:s'),
  1251. 'updated_at' => date('Y-m-d H:i:s'),
  1252. 'by_professor' => 0,
  1253. 'is_custom' => $is_custom
  1254. ));
  1255. $ta_id = $edit_ta_id;
  1256. }
  1257. return $ta_id;
  1258. }
  1259. public function deleteTaFromOutcome()
  1260. {
  1261. DB::table('transformative_actions')
  1262. ->where('id', Input::get('trans_id'))
  1263. ->delete();
  1264. return;
  1265. }
  1266. public function fetchStatus()
  1267. {
  1268. $trans_id = Input::get('trans_id');
  1269. $semester_id = Input::get('semester_id');
  1270. $transformative_action = DB::table('transformative_actions')
  1271. ->where('id', $trans_id)
  1272. ->first();
  1273. $transformative_action->status = DB::table('transformative_action_status')
  1274. ->where('trans_id', $transformative_action->id)
  1275. ->where('semester_id', $semester_id)
  1276. ->first();
  1277. //TransformativeAction::find($trans_id)->status($semester_id);
  1278. return array($transformative_action);
  1279. }
  1280. public function saveTransStatus()
  1281. {
  1282. $semester_id = Input::get('semester_id');
  1283. $trans_id = Input::get('trans_id');
  1284. $results = Input::get('results');
  1285. $comments = Input::get('comments');
  1286. $accomplished = Input::get('accomplished');
  1287. $was_it_useful = Input::get('was_it_useful');
  1288. $existing_status = DB::table('transformative_action_status')
  1289. ->where('semester_id', $semester_id)
  1290. ->where('trans_id', $trans_id)
  1291. ->first();
  1292. if ($existing_status) {
  1293. DB::table('transformative_action_status')
  1294. ->where('trans_id', $trans_id)
  1295. ->update(array(
  1296. 'results' => $results,
  1297. 'comments' => $comments,
  1298. 'accomplished' => $accomplished,
  1299. 'it_was_useful' => $was_it_useful,
  1300. 'supervised_coordinator_id' => Auth::user()->id
  1301. ));
  1302. } else {
  1303. DB::table('transformative_action_status')->insert(array(
  1304. 'trans_id' => $trans_id,
  1305. 'results' => $results,
  1306. 'comments' => $comments,
  1307. 'accomplished' => $accomplished,
  1308. 'it_was_useful' => $was_it_useful,
  1309. 'semester_id' => $semester_id,
  1310. 'supervised_coordinator_id' => Auth::user()->id
  1311. ));
  1312. }
  1313. return "done";
  1314. }
  1315. }