Keine Beschreibung

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. Log::info($course_id);
  896. // search TA with filters
  897. $filtered_at = DB::table('transformative_actions')
  898. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  899. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  900. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  901. ->where('transformative_actions.is_custom', 1)
  902. ->where('transformative_actions.program_id', $program_id)
  903. ->where('transformative_actions.by_professor', 0)
  904. ->whereIn('transformative_actions.user_id', $professor_id)
  905. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  906. ->whereIn('ta_course.course_code', $course_id['code'])
  907. ->whereIn('ta_course.course_number', $course_id['number'])
  908. ->select('transformative_actions.*')
  909. ->groupBy('transformative_actions.id')
  910. ->orderBy('transformative_actions.at_text', 'ASC')
  911. ->get();
  912. return $filtered_at;
  913. }
  914. // if the user is a professor filtering the editPanel
  915. /*elseif ($role == '4' && $panel_id == 'editPanel') {
  916. // if course isnt a desired filter, search all courses
  917. if ($course_id == 0) {
  918. $courses = DB::table('ta_course')
  919. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  920. ->join('courses', 'courses.id', '=', 'ta_course.course_id')
  921. ->where('transformative_actions.user_id', Auth::user()->id)
  922. ->where('transformative_actions.is_custom', 1)
  923. ->where('transformative_actions.program_id', $program_id)
  924. ->where('transformative_actions.by_professor', 1)
  925. ->select('ta_course.course_number', 'ta_course.course_code')
  926. ->distinct()
  927. ->get();
  928. $course_id = array();
  929. foreach ($courses as $key => $course) {
  930. array_push($course_id["number"], $course->course_number);
  931. array_push($course_id["code"], $course->code);
  932. }
  933. } else {
  934. $parentesis = array('(', ')');
  935. $course_code_number = str_replace($parentesis, '', $course_id);
  936. $course_code_number = explode(',', $course_code_number);
  937. $course_id = array();
  938. $course_id['number'] = $course_code_number[1];
  939. $course_id['code'] = $course_code_number[0];
  940. }
  941. // if outcome isnt a desired filter, search all outcomes
  942. if ($outcome_id == 0) {
  943. $outcomes = DB::table('transformative_actions')
  944. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  945. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  946. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  947. ->where('transformative_actions.user_id', Auth::user()->id)
  948. ->where('transformative_actions.is_custom', 1)
  949. ->where('transformative_actions.program_id', $program_id)
  950. ->where('transformative_actions.by_professor', 1)
  951. ->select('outcomes.id')
  952. ->groupBy('outcomes.id')
  953. ->get();
  954. $outcome_id = array();
  955. foreach ($outcomes as $key => $outcome) {
  956. array_push($outcome_id, $outcome->id);
  957. }
  958. } else {
  959. $outcome_id = array($outcome_id);
  960. }
  961. // search TA with filters
  962. $filtered_at = DB::table('transformative_actions')
  963. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  964. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  965. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  966. ->where('transformative_actions.user_id', Auth::user()->id)
  967. ->where('transformative_actions.is_custom', 1)
  968. ->where('transformative_actions.program_id', $program_id)
  969. ->where('transformative_actions.by_professor', 1)
  970. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  971. ->whereIn('ta_course.course_code', $course_id['code'])
  972. ->whereIn('ta_course.course_number', $course_id['number'])
  973. ->select('transformative_actions.*')
  974. ->groupBy('transformative_actions.id')
  975. ->orderBy('transformative_actions.at_text', 'ASC')
  976. ->get();
  977. return $filtered_at;
  978. }*/
  979. return 'ilegal';
  980. }
  981. function postActivityCriterion($activity_id)
  982. {
  983. DB::beginTransaction();
  984. $existing_transformative_action = DB::table('transformative_actions')
  985. ->join('transformative_activity_criterion', 'transformative_activity_criterion.trans_action_id', '=', 'transformative_actions.id')
  986. ->join('activity_criterion', 'activity_criterion.id', '=', 'transformative_activity_criterion.activity_criterion_id')
  987. ->where('activity_id', $activity_id)
  988. ->delete();
  989. $activity_criterion = Input::get('trans_act');
  990. $trans = new TransformativeAction;
  991. $trans->user_id = Auth::user()['id'];
  992. $program_id = DB::table('activities')
  993. ->join('courses', 'activities.course_id', '=', 'courses.id')
  994. ->where('activities.id', $activity_id)
  995. ->lists('program_id');
  996. $trans->program_id = $program_id[0];
  997. $trans->is_custom = 1;
  998. $trans->by_professor = 1;
  999. $trans->at_text = Input::get('name_trans');
  1000. $trans->description = Input::get('transforming_actions');
  1001. $activity = DB::table('activities')
  1002. ->where('id', $activity_id)
  1003. ->first();
  1004. $course_credentials = DB::table('courses')
  1005. ->where('id', $activity->course_id)
  1006. ->first();
  1007. if ($trans->save()) {
  1008. foreach ($activity_criterion as $single_ac) {
  1009. $result = DB::insert("insert into `transformative_activity_criterion` (`trans_action_id`, `activity_criterion_id`) values ($trans->id, $single_ac)");
  1010. if (!$result) {
  1011. DB::rollback();
  1012. Session::flash('status', 'danger');
  1013. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1014. return Redirect::to("professor/activities/{$activity_id}");
  1015. }
  1016. }
  1017. $criteria = DB::table('activity_criterion')
  1018. ->whereIn('id', $activity_criterion)
  1019. ->lists('criterion_id');
  1020. $allObjectives = DB::table('criterion_objective_outcome')
  1021. ->whereIn('criterion_id', $criteria)
  1022. ->select('objective_id')
  1023. ->distinct()
  1024. ->lists('objective_id');
  1025. foreach ($allObjectives as $objective) {
  1026. $result2 = DB::insert("insert into `transformative_objective` (`ta_id`, `objective_id`) values ({$trans->id},{$objective})");
  1027. if (!$result2) {
  1028. DB::rollback();
  1029. Session::flash('status', 'danger');
  1030. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1031. return Redirect::to("professor/activities/{$activity_id}");
  1032. }
  1033. }
  1034. $result3 = DB::insert("insert into `ta_course` (`ta_id`, `course_number`, `course_code`) values ({$trans->id}, '{$course_credentials->number}', '{$course_credentials->code}')");
  1035. if (!($result3)) {
  1036. DB::rollback();
  1037. Session::flash('status', 'danger');
  1038. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1039. return Redirect::to("professor/activities/{$activity_id}");
  1040. }
  1041. DB::commit();
  1042. Session::flash('status', 'success');
  1043. Session::flash('message', 'Formative Actions Saved.');
  1044. return Redirect::to("professor/activities/{$activity_id}");
  1045. } else {
  1046. DB::rollback();
  1047. Session::flash('status', 'danger');
  1048. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1049. return Redirect::to("professor/activities/{$activity_id}");
  1050. }
  1051. }
  1052. public function viewFormativeActions()
  1053. {
  1054. $title = "Formative Actions";
  1055. $semesters = Session::get('semesters_ids');
  1056. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  1057. Log::info($semesters->start);
  1058. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  1059. ->whereNull('deleted_at')
  1060. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  1061. ->orderBy('name', 'ASC')->get();
  1062. $semesters = DB::table('semesters')->where('is_visible', 1)->orderBy('end', 'DESC')->get();
  1063. $role = Auth::user()->role;
  1064. switch ($role) {
  1065. case 1:
  1066. $schools = DB::table('schools')->get();
  1067. $programs = DB::table('programs')->get();
  1068. break;
  1069. case 2:
  1070. $schools = DB::table('schools')->where('id', Auth::user()->school_id)->get();
  1071. $programs = DB::table('programs')->where('school_id', $schools[0]->id)->get();
  1072. break;
  1073. case 3:
  1074. $programs = DB::table('programs')
  1075. ->join('program_user', 'programs.id', '=', 'program_user.program_id')
  1076. ->where('user_id', Auth::user()->id)
  1077. ->select('programs.*')
  1078. ->get();
  1079. $schools = DB::table('schools')->where('id', $programs[0]->school_id)->get();
  1080. break;
  1081. }
  1082. return View::make('local.managers.shared.view_formative', compact('title', 'outcomes', 'schools', 'programs', 'semesters'));
  1083. }
  1084. public function fetchCourses()
  1085. {
  1086. $school = Input::get('schools');
  1087. $programs = Input::get('programs');
  1088. $semesters = Input::get('semesters');
  1089. $outcome_id = Input::get('id');
  1090. Log::info($programs);
  1091. Log::info($semesters);
  1092. /* if (in_array(0, $semesters)) {
  1093. $semesters = DB::table('semesters')->where('is_visible', 1)->lists('id');
  1094. }*/
  1095. /* if (in_array(0, $programs)) {
  1096. $role = Auth::user()->role;
  1097. switch ($role) {
  1098. case 1:
  1099. $programs = DB::table('programs')->lists('id');
  1100. break;
  1101. case 2:
  1102. $programs = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
  1103. break;
  1104. case 3:
  1105. $programs = DB::table('program_user')->where('user_id', Auth::user()->id)->lists('program_id');
  1106. break;
  1107. }
  1108. }*/
  1109. $typ_semester_outcome = DB::table('typ_semester_outcome')
  1110. ->where('semester_id', $semesters)
  1111. ->where('outcome_id', $outcome_id)
  1112. ->lists('id');
  1113. //each row has objectives, repeated ta, but distinct activity_criterion_id
  1114. /* $objective_ta = DB::table('typ_semester_objectives')
  1115. ->join('transformative_objective as trob', 'trob.objective_id', '=', 'typ_semester_objectives.objective_id')
  1116. ->join('objectives', 'trob.objective_id', '=', 'objective_id')
  1117. ->join('transformative_actions', 'transformative_actions.id', 'trob.ta_id')
  1118. ->whereIn('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome)
  1119. ->select('transformative_actions.*')
  1120. ->addSelect('objectives.*')
  1121. ->distinct()
  1122. ->get();
  1123. $objective_ta = DB::table('typ_semester_objectives')
  1124. ->join('transformative_objective as trob', 'trob.objective_id', '=', 'typ_semester_objectives.objective_id')
  1125. ->join('objectives', 'trob.objective_id', '=', 'objective_id')
  1126. ->join('transformative_actions', 'transformative_actions.id', 'trob.ta_id')
  1127. ->whereIn('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome)
  1128. ->select('transformative_actions.*')
  1129. ->addSelect('objectives.*')
  1130. ->distinct()
  1131. ->lists();*/
  1132. $grouped_courses = DB::table('courses')
  1133. ->where('program_id', $programs)
  1134. ->where('semester_id', $semesters)
  1135. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1136. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  1137. ->join('transformative_activity_criterion as tac', 'tac.activity_criterion_id', '=', 'activity_criterion.id')
  1138. ->select('courses.*')
  1139. ->groupBy(array('courses.code', 'courses.name', 'courses.semester_id'))
  1140. ->orderBy('courses.code')
  1141. ->orderBy('courses.number')
  1142. ->get();
  1143. foreach ($grouped_courses as $course_name) {
  1144. $course_name->sections = DB::table('courses')
  1145. ->where('code', $course_name->code)
  1146. ->where('name', $course_name->name)
  1147. ->where('semester_id', $course_name->semester_id)
  1148. ->where('program_id', $course_name->program_id)
  1149. ->get();
  1150. foreach ($course_name->sections as $section) {
  1151. $section->activities = DB::table('activities')
  1152. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  1153. ->join('transformative_activity_criterion', 'transformative_activity_criterion.activity_criterion_id', '=', 'activity_criterion.id')
  1154. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  1155. ->join('transformative_actions', 'transformative_activity_criterion.trans_action_id', '=', 'transformative_actions.id')
  1156. ->where('activities.course_id', $section->id)
  1157. ->where('activities.draft', 0)
  1158. ->where('activities.diagnostic', 0)
  1159. ->where('criterion_objective_outcome.outcome_id', $outcome_id)
  1160. ->select('activities.id as activity_id', 'activities.name')
  1161. ->addSelect('transformative_actions.*', 'transformative_activity_criterion.trans_action_id as trans_action_id')
  1162. ->groupBy('transformative_actions.id')
  1163. ->get();
  1164. //If section has activity that assessess outcome
  1165. if (count($section->activities)) {
  1166. $course_name->outcome_assessed = true;
  1167. }
  1168. foreach ($section->activities as $activity) {
  1169. /*$activity->criterion = DB::table('transformative_activity_criterion')
  1170. ->join('activity_criterion','activity_criterion.id','=','transformative_activity_criterion.activity_criterion_id')
  1171. ->join('activities','activities.id','=','activity_criterion.activity_id')
  1172. ->join('criteria','activity_criterion.criterion_id','=','criteria.id')
  1173. ->where('activity_id', $activity->id)
  1174. ->select('criteria')*/
  1175. //Log::info($activity->trans_action_id);
  1176. $activity->criterion_with_objective = DB::table('transformative_activity_criterion')
  1177. ->join('activity_criterion', 'activity_criterion.id', '=', 'transformative_activity_criterion.activity_criterion_id')
  1178. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  1179. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  1180. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  1181. ->where('activity_id', $activity->activity_id)
  1182. ->where('trans_action_id', $activity->trans_action_id)
  1183. ->get();
  1184. /*$activity->objectives = DB::table('transformative_objective')
  1185. ->join('objectives', 'transformative_objective.objective_id', '=', 'objectives.id')
  1186. ->where('ta_id', $activity->trans_action_id)
  1187. ->get();*/
  1188. /*foreach ($activity->objectives as $objective) {
  1189. // Log::info($activity->activity_id);
  1190. // Log::info($objective->objective_id);
  1191. /* Log::info(DB::table('criterion_objective_outcome')
  1192. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
  1193. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  1194. ->where('activity_criterion.activity_id', $activity->activity_id)
  1195. ->where('objective_id', $objective->objective_id)
  1196. ->select('criteria.*')
  1197. ->distinct()
  1198. ->toSql());
  1199. $objective->criterion = DB::table('criterion_objective_outcome')
  1200. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
  1201. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  1202. ->where('activity_criterion.activity_id', $activity->activity_id)
  1203. ->where('objective_id', $objective->objective_id)
  1204. ->select('criteria.*')
  1205. ->distinct()
  1206. ->get();
  1207. }*/
  1208. }
  1209. }
  1210. }
  1211. return $grouped_courses;
  1212. }
  1213. public function createTAForOutcome()
  1214. {
  1215. $is_custom = Input::get('is_custom');
  1216. $category = Input::get('category');
  1217. $is_new = Input::get('is_new');
  1218. $name = Input::get('name');
  1219. $description = Input::get('description');
  1220. $edit_ta_id = Input::get('edit');
  1221. if ($is_new || $is_custom)
  1222. $program_id = Input::get('program_id');
  1223. else $program_id = NULL;
  1224. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  1225. if (!$edit_ta_id) {
  1226. $ta_id = DB::table('transformative_actions')->insertGetId(array(
  1227. 'program_id' => $program_id,
  1228. 'type_of_TA' => $category,
  1229. 'at_text' => $name,
  1230. 'description' => $description,
  1231. 'user_id' => Auth::user()->id,
  1232. 'created_at' => date('Y-m-d H:i:s'),
  1233. 'updated_at' => date('Y-m-d H:i:s'),
  1234. 'by_professor' => 0,
  1235. 'is_custom' => $is_custom
  1236. ));
  1237. DB::table('transformative_typ_outcome')->insert(array(
  1238. 'trans_id' => $ta_id,
  1239. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  1240. 'proposing_coordinator_id' => Auth::user()->id,
  1241. ));
  1242. } else {
  1243. DB::table('transformative_actions')
  1244. ->where('id', $edit_ta_id)
  1245. ->update(array(
  1246. 'program_id' => $program_id,
  1247. 'type_of_TA' => $category,
  1248. 'at_text' => $name,
  1249. 'description' => $description,
  1250. 'user_id' => Auth::user()->id,
  1251. 'created_at' => date('Y-m-d H:i:s'),
  1252. 'updated_at' => date('Y-m-d H:i:s'),
  1253. 'by_professor' => 0,
  1254. 'is_custom' => $is_custom
  1255. ));
  1256. $ta_id = $edit_ta_id;
  1257. }
  1258. return $ta_id;
  1259. }
  1260. public function deleteTaFromOutcome()
  1261. {
  1262. DB::table('transformative_actions')
  1263. ->where('id', Input::get('trans_id'))
  1264. ->delete();
  1265. return;
  1266. }
  1267. public function fetchStatus()
  1268. {
  1269. $trans_id = Input::get('trans_id');
  1270. $semester_id = Input::get('semester_id');
  1271. $transformative_action = DB::table('transformative_actions')
  1272. ->where('id', $trans_id)
  1273. ->first();
  1274. $transformative_action->status = DB::table('transformative_action_status')
  1275. ->where('trans_id', $transformative_action->id)
  1276. ->where('semester_id', $semester_id)
  1277. ->first();
  1278. //TransformativeAction::find($trans_id)->status($semester_id);
  1279. return array($transformative_action);
  1280. }
  1281. public function saveTransStatus()
  1282. {
  1283. $semester_id = Input::get('semester_id');
  1284. $trans_id = Input::get('trans_id');
  1285. $results = Input::get('results');
  1286. $comments = Input::get('comments');
  1287. $accomplished = Input::get('accomplished');
  1288. $was_it_useful = Input::get('was_it_useful');
  1289. $existing_status = DB::table('transformative_action_status')
  1290. ->where('semester_id', $semester_id)
  1291. ->where('trans_id', $trans_id)
  1292. ->first();
  1293. if ($existing_status) {
  1294. DB::table('transformative_action_status')
  1295. ->where('trans_id', $trans_id)
  1296. ->update(array(
  1297. 'results' => $results,
  1298. 'comments' => $comments,
  1299. 'accomplished' => $accomplished,
  1300. 'it_was_useful' => $was_it_useful,
  1301. 'supervised_coordinator_id' => Auth::user()->id
  1302. ));
  1303. } else {
  1304. DB::table('transformative_action_status')->insert(array(
  1305. 'trans_id' => $trans_id,
  1306. 'results' => $results,
  1307. 'comments' => $comments,
  1308. 'accomplished' => $accomplished,
  1309. 'it_was_useful' => $was_it_useful,
  1310. 'semester_id' => $semester_id,
  1311. 'supervised_coordinator_id' => Auth::user()->id
  1312. ));
  1313. }
  1314. return "done";
  1315. }
  1316. }