No Description

TransformativeActionsController.php 49KB

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