Ingen beskrivning

ThreeYearPlanController.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <?php
  2. use Illuminate\Database\Eloquent\Collection;
  3. class ThreeYearPlanController extends \BaseController
  4. {
  5. public function create()
  6. {
  7. try {
  8. DB::beginTransaction();
  9. $yearStart = Input::get('years') + 0;
  10. $yearEnd = $yearStart + 3;
  11. $program_id = Input::get('program_id');
  12. DB::insert("insert into three_year_plan (`year_start`, `year_end`) values ({$yearStart}, {$yearEnd})");
  13. $typ = DB::table('three_year_plan')->where('year_start', '=', $yearStart)
  14. ->where('year_end', '=', $yearEnd)
  15. ->first();
  16. for ($i = $yearStart; $i < $yearEnd; $i++) {
  17. $string = 'First Semester ' . $i . '-' . ($i + 1);
  18. $string2 = 'Second Semester ' . $i . '-' . ($i + 1);
  19. $Firstsemester = DB::table('semesters')->where('name', '=', $string)->first();
  20. $secondSemester = DB::table('semesters')->where('name', '=', $string2)->first();
  21. Log::info($Firstsemester->id);
  22. Log::info($secondSemester->id);
  23. Log::info($typ->id);
  24. DB::insert("insert into typ_semesters (typ_id, semester_id) values ({$typ->id}, {$Firstsemester->id}), ({$typ->id}, {$secondSemester->id})");
  25. }
  26. DB::commit();
  27. Session::flash('status', 'success');
  28. Session::flash('message', '<p> Cycle created.</p>');
  29. return Redirect::to("three-years-plan/{$program_id}");
  30. } catch (Exception $e) {
  31. Session::flash('status', 'danger');
  32. Session::flash('message', "<p>Could not create cycle</p>");
  33. Log::info($e);
  34. DB::rollback();
  35. return Redirect::to("three-years-plan/{$program_id}");
  36. }
  37. }
  38. // load the Three year Plan page
  39. public function threeYearsReport($program_id)
  40. {
  41. $user_id = Auth::user()->id;
  42. $last_year = DB::table('three_year_plan')->select('year_end')
  43. ->orderBy('year_end', 'desc')->first();
  44. if (!$last_year) {
  45. // $last_year = date('Y');
  46. $last_year = 2019;
  47. } else {
  48. $last_year = $last_year->year_end;
  49. }
  50. $program = Program::find($program_id);
  51. // el ID de los semestres que el usuario tiene seleccionado.
  52. $semesters_ids = Session::get('semesters_ids');
  53. // buscar informacion de los semestres seleccionados
  54. $semesters = Semester::whereIn('id', $semesters_ids)->get();
  55. $title = "Three Year Plan for " . $program->name;
  56. $typs = DB::table('three_year_plan')
  57. ->orderBy('year_start', 'asc')
  58. ->get();
  59. $criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
  60. /* $program_id = DB::table('program_user')
  61. ->where('user_id', $user_id)
  62. ->select('program_id')
  63. ->get();
  64. $program_id = $program_id[0]->program_id;*/
  65. $outcomes = DB::table('outcomes')->where('deactivation_date', '=', null)->orderBy('name', 'ASC')->get();
  66. // se annadio la nueva variable
  67. return View::make('global.view-three-year-plan', compact('title', 'last_year', 'outcomes', 'typs', 'criteria', 'semesters', 'program_id'));
  68. }
  69. //when the user select a three year period from the left column, load the corresponding info
  70. public function fetchThreeYears()
  71. {
  72. $id = Input::get('id');
  73. $semesters = DB::table('typ_semesters')
  74. ->join('semesters', 'semesters.id', '=', 'typ_semesters.semester_id')
  75. ->where('typ_semesters.typ_id', $id)
  76. ->orderBy('typ_semesters.semester_id', 'asc')
  77. ->get();
  78. $typs = DB::table('three_year_plan')
  79. ->where('id', $id)
  80. ->orderBy('year_start', 'asc')
  81. ->get();
  82. $typs = $typs[0];
  83. $typs->semesters = $semesters;
  84. return array(
  85. 'typ' => $typs,
  86. );
  87. }
  88. // add or remove a semester associated with an outcome when a user selects a checkbox
  89. public function update_typ_outcomes_semesters()
  90. {
  91. $outcomeSemesterArray = json_decode(Input::get('outcomeSemesterArray'), true);
  92. $typ_id = Input::get('typ_id');
  93. $user_id = auth::user()->id;
  94. $program_id = Input::get('program_id');
  95. $result = DB::table('typ_program')
  96. ->where('three_year_plan_id', $typ_id)
  97. ->where('program_id', $program_id)
  98. ->get();
  99. // create the relation if it doesnt exist
  100. if (count($result) == 0) {
  101. $typ_program_id = DB::table('typ_program')->insertGetId(
  102. array(
  103. 'three_year_plan_id' => $typ_id,
  104. 'program_id' => $program_id
  105. )
  106. );
  107. } else {
  108. $typ_program_id = $result[0]->id;
  109. }
  110. //go through array
  111. foreach ($outcomeSemesterArray as $outcome_semester) {
  112. // foreach of the 6 semesters
  113. foreach ($outcome_semester["semesters"] as $semester) {
  114. $insert = $semester[1];
  115. $outcome_id = explode("-sem", $semester[0])[0];
  116. $semester_code = explode("-sem", $semester[0])[1];
  117. $result = DB::table('semesters')
  118. ->where('code', $semester_code)
  119. ->select('id')
  120. ->get();
  121. if (count($result) == 0) {
  122. continue;
  123. }
  124. $semester_id = $result[0]->id;
  125. // verify if it exists
  126. $result = DB::table('typ_semester_outcome')
  127. ->where('typ_program_id', $typ_program_id)
  128. ->where('semester_id', $semester_id)
  129. ->where('outcome_id', $outcome_id)
  130. ->get();
  131. // if true, it should get inserted
  132. if ($insert == true) {
  133. // if == 0, then insert
  134. if (count($result) == 0) {
  135. $_ = DB::table('typ_semester_outcome')->insertGetId(
  136. array(
  137. 'typ_program_id' => $typ_program_id,
  138. 'semester_id' => $semester_id,
  139. 'outcome_id' => $outcome_id
  140. )
  141. );
  142. }
  143. //if exists, then do nothing
  144. }
  145. // if false, it should get deleted
  146. else { //value == false
  147. // if == 0, it doesnt exist. we do nothing
  148. if (count($result) == 0) {
  149. //pass
  150. }
  151. //if exists, then do nothing
  152. else {
  153. DB::table('typ_semester_outcome')
  154. ->where('typ_program_id', $typ_program_id)
  155. ->where('semester_id', $semester_id)
  156. ->where('outcome_id', $outcome_id)
  157. ->delete();
  158. }
  159. }
  160. }
  161. }
  162. return;
  163. }
  164. // load semesters asociated with the outcomes if previously selected
  165. public function lookup_typ_semester_outcome()
  166. {
  167. $box_value = array();
  168. $info = Input::get('info');
  169. foreach ($info as $values) {
  170. $outcome_id = $values[0];
  171. $semester_code = $values[1];
  172. $program_id = $values[2];
  173. $box_id = $values[3];
  174. $typ_id = $values[4];
  175. //buscar id del typ
  176. $result = DB::table('typ_program')
  177. ->where('three_year_plan_id', $typ_id)
  178. ->where('program_id', $program_id)
  179. ->get();
  180. $typ_program_id = $result[0]->id;
  181. // buscar si existe el outcome_semester
  182. $result = DB::table('typ_semester_outcome')
  183. ->join('semesters', 'semesters.id', '=', 'typ_semester_outcome.semester_id')
  184. ->where('typ_program_id', $typ_program_id)
  185. ->where('semesters.code', $semester_code)
  186. ->where('outcome_id', $outcome_id)
  187. ->get();
  188. // if it doesnt exist
  189. if (count($result) == 0) {
  190. array_push($box_value, array($box_id, 0));
  191. } else {
  192. array_push($box_value, array($box_id, 1));
  193. }
  194. }
  195. return array(
  196. 'box_value' => ($box_value)
  197. );
  198. }
  199. // save or delete Objectives associated with the outcomes and semsters
  200. public function section2_on_change()
  201. {
  202. $typ_id = Input::get('typ_id');
  203. $outcome_id = Input::get('outcome_id');
  204. $semester_id = Input::get('semester_id');
  205. $previous_objective_id = Input::get('previous_objective_id');
  206. $new_objective_id = Input::get('new_objective_id');
  207. $program_id = Input::get('program_id');
  208. // get program_id
  209. $user_id = auth::user()->id;
  210. // get typ_program_id
  211. $result = DB::table('typ_program')
  212. ->where('three_year_plan_id', $typ_id)
  213. ->where('program_id', $program_id)
  214. ->get();
  215. $typ_program_id = $result[0]->id;
  216. // get typ_semester_outcome_id
  217. $result = DB::table('typ_semester_outcome')
  218. ->where('typ_program_id', $typ_program_id)
  219. ->where('semester_id', $semester_id)
  220. ->where('outcome_id', $outcome_id)
  221. ->get();
  222. $typ_semester_outcome_id = $result[0]->id;
  223. //delete old objective relation if it exists
  224. if ($previous_objective_id != 'nothing_selected') {
  225. $result = DB::table('typ_semester_objectives')
  226. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  227. ->where('objective_id', $previous_objective_id)
  228. ->get();
  229. if (count($result) != 0) {
  230. DB::table('typ_semester_objectives')
  231. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  232. ->where('objective_id', $previous_objective_id)
  233. ->delete();
  234. }
  235. }
  236. //create new objective relation
  237. if ($new_objective_id != 'nothing_selected') {
  238. $result = DB::table('typ_semester_objectives')
  239. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  240. ->where('objective_id', $new_objective_id)
  241. ->get();
  242. if (count($result) == 0) {
  243. $_ = DB::table('typ_semester_objectives')->insertGetId(
  244. array(
  245. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  246. 'objective_id' => $new_objective_id
  247. )
  248. );
  249. }
  250. }
  251. return 'update was succes';
  252. }
  253. // load the corresponding info after associating semesters with outcomes
  254. public function section2_arrive()
  255. {
  256. // get program_id
  257. $user_id = auth::user()->id;
  258. $program_id = Input::get('program_id');
  259. // get typ_program_id
  260. $typ_id = Input::get('typ_id');
  261. $result = DB::table('typ_program')
  262. ->where('three_year_plan_id', $typ_id)
  263. ->where('program_id', $program_id)
  264. ->get();
  265. $typ_program_id = $result[0]->id;
  266. //search selected outcomes,semesters and get their objectives
  267. $selected_outcomes = DB::table('typ_semester_outcome')
  268. ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
  269. ->where('typ_semester_outcome.typ_program_id', $typ_program_id)
  270. ->distinct('typ_semester_outcome.outcome_id')
  271. ->select('typ_semester_outcome.outcome_id')
  272. ->orderBy('outcomes.name', 'asc')
  273. ->get();
  274. $selected_objectives_array = array();
  275. $outcomes_info_array = array();
  276. // $objectives_info_array = array();
  277. $semesters_array = array();
  278. $info = array();
  279. foreach ($selected_outcomes as $outcome) {
  280. $outcome_id = $outcome->outcome_id;
  281. $result_outcomes = DB::table('outcomes')
  282. ->where('outcomes.id', $outcome_id)
  283. ->orderBy('outcomes.name', 'asc')
  284. ->get();
  285. foreach ($result_outcomes as $outcome_) {
  286. $result_semesters = DB::table('typ_semester_outcome')
  287. ->join('semesters', 'semesters.id', '=', 'typ_semester_outcome.semester_id')
  288. ->where('typ_semester_outcome.typ_program_id', $typ_program_id)
  289. ->where('typ_semester_outcome.outcome_id', $outcome_->id)
  290. ->select('typ_semester_outcome.id', 'typ_semester_outcome.semester_id', 'semesters.code', 'semesters.name')
  291. ->orderBy('semesters.code')
  292. ->get();
  293. // buscar info sobre selected_semsters
  294. $outcome_->selected_semesters = array();
  295. foreach ($result_semesters as $semesters_) {
  296. $typ_semester_outcome_id = $semesters_->id;
  297. // lookup previusly selected objectives
  298. $result_objectives = DB::table('typ_semester_objectives')
  299. ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  300. ->where('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome_id)
  301. ->orderBy('typ_semester_objectives.id', 'asc')
  302. ->get();
  303. $semesters_->selected_objectives = array();
  304. foreach ($result_objectives as $objectives_) {
  305. array_push($semesters_->selected_objectives, $objectives_);
  306. }
  307. // lookup available objectives
  308. $result_objectives = DB::table('objective_outcome')
  309. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  310. ->join('objectives', 'objectives.id', '=', 'objective_outcome.objective_id')
  311. ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
  312. ->where('objective_program.program_id', $program_id)
  313. ->where('objective_outcome.outcome_id', $outcome_id)
  314. ->where('objective_outcome.objective_id', "<>",0)
  315. ->select('objectives.id', 'objectives.text', 'outcomes.name as outcome_name')
  316. ->orderBy('objectives.text', 'asc')
  317. ->get();
  318. $semesters_->available_objectives = array();
  319. foreach ($result_objectives as $objectives_) {
  320. array_push($semesters_->available_objectives, $objectives_);
  321. }
  322. array_push($outcome_->selected_semesters, $semesters_);
  323. }
  324. array_push($info, $outcome_);
  325. }
  326. }
  327. return $info;
  328. }
  329. // load the corresponding info after associating objectives to semesters outcomes
  330. public function section3_arrive()
  331. {
  332. // get program_id
  333. $user_id = auth::user()->id;
  334. $program_id = Input::get('program_id');
  335. // get typ_program_id
  336. $typ_id = Input::get('typ_id');
  337. $result = DB::table('typ_program')
  338. ->where('three_year_plan_id', $typ_id)
  339. ->where('program_id', $program_id)
  340. ->get();
  341. $typ_program_id = $result[0]->id;
  342. //search selected outcomes,semesters and get their objectives
  343. $selected_outcomes = DB::table('typ_semester_outcome')
  344. ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
  345. ->where('typ_semester_outcome.typ_program_id', $typ_program_id)
  346. ->distinct('typ_semester_outcome.outcome_id')
  347. ->select('typ_semester_outcome.outcome_id')
  348. ->orderBy('outcomes.name', 'asc')
  349. ->get();
  350. $selected_objectives_array = array();
  351. $outcomes_info_array = array();
  352. // $objectives_info_array = array();
  353. $semesters_array = array();
  354. $info = array();
  355. foreach ($selected_outcomes as $outcome) {
  356. $outcome_id = $outcome->outcome_id;
  357. $result_outcomes = DB::table('outcomes')
  358. ->where('outcomes.id', $outcome_id)
  359. ->get();
  360. foreach ($result_outcomes as $outcome_) {
  361. $result_semesters = DB::table('typ_semester_outcome')
  362. ->join('semesters', 'semesters.id', '=', 'typ_semester_outcome.semester_id')
  363. ->where('typ_semester_outcome.typ_program_id', $typ_program_id)
  364. ->where('typ_semester_outcome.outcome_id', $outcome_->id)
  365. ->select('typ_semester_outcome.id', 'typ_semester_outcome.semester_id', 'semesters.code', 'semesters.name')
  366. ->orderBy('semesters.code')
  367. ->get();
  368. // buscar info sobre selected_semsters
  369. $outcome_->selected_semesters = array();
  370. foreach ($result_semesters as $semesters_) {
  371. $typ_semester_outcome_id = $semesters_->id;
  372. $result_objectives = DB::table('typ_semester_objectives')
  373. ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  374. ->where('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome_id)
  375. ->select('typ_semester_objectives.id as typ_semester_objectives_id', 'objectives.*', 'typ_semester_objectives.*')
  376. ->orderBy('typ_semester_objectives.id', 'asc')
  377. ->get();
  378. $semesters_->selected_objectives = array();
  379. foreach ($result_objectives as $objectives_) {
  380. // $result_courses = DB::table('courses')
  381. // ->where('courses.program_id', $program_id)
  382. // ->select('courses.id as course_id', 'courses.name', 'courses.code', 'courses.number', 'courses.program_id')
  383. // ->orderBy('courses.number', 'asc')
  384. // ->groupBy('courses.name', 'courses.code')
  385. // ->get();
  386. $result_courses = DB::table('courses')
  387. ->where('courses.program_id', $program_id)
  388. ->orWhereIn('courses.program_id', function ($q) use ($program_id){
  389. $q->select('other_program_id')
  390. ->from('other_programs_courses_typ')
  391. ->where('program_id',$program_id);
  392. })
  393. ->select('courses.id as course_id', 'courses.name', 'courses.code', 'courses.number', 'courses.program_id')
  394. ->orderBy('courses.code', 'asc')
  395. ->orderBy('courses.number', 'asc')
  396. ->groupBy('courses.name', 'courses.code')
  397. ->get();
  398. #los cursos resultantes creo que deberian ser: todos los que se estan dando en mi programa
  399. $objectives_->available_courses = array();
  400. foreach ($result_courses as $courses_) {
  401. array_push($objectives_->available_courses, $courses_);
  402. }
  403. // search for previusly selected courses
  404. $typ_semester_objective_id = $objectives_->typ_semester_objectives_id;
  405. $result_courses = DB::table('typ_semester_courses')
  406. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  407. ->where('typ_semester_courses.typ_semester_objective_id', $typ_semester_objective_id)
  408. ->select('courses.id as course_id', 'courses.*', 'typ_semester_courses.*')
  409. ->orderBy('courses.name', 'asc')
  410. ->get();
  411. $objectives_->selected_courses = array();
  412. foreach ($result_courses as $courses_) {
  413. array_push($objectives_->selected_courses, $courses_);
  414. }
  415. array_push($semesters_->selected_objectives, $objectives_);
  416. }
  417. array_push($outcome_->selected_semesters, $semesters_);
  418. }
  419. array_push($info, $outcome_);
  420. }
  421. }
  422. return $info;
  423. }
  424. // save or delete courses associated with objectives
  425. public function section3_on_change()
  426. {
  427. $typ_id = Input::get('typ_id');
  428. $outcome_id = Input::get('outcome_id');
  429. $semester_id = Input::get('semester_id');
  430. $objective_id = Input::get('objective_id');
  431. $previous_course_id = Input::get('previous_course_id');
  432. $new_course_id = Input::get('new_course_id');
  433. // get program_id
  434. $program_id = Input::get('program_id');
  435. // get typ_program_id
  436. $result = DB::table('typ_program')
  437. ->where('three_year_plan_id', $typ_id)
  438. ->where('program_id', $program_id)
  439. ->get();
  440. $typ_program_id = $result[0]->id;
  441. // get typ_semester_outcome_id
  442. $result = DB::table('typ_semester_outcome')
  443. ->where('typ_program_id', $typ_program_id)
  444. ->where('semester_id', $semester_id)
  445. ->where('outcome_id', $outcome_id)
  446. ->get();
  447. $typ_semester_outcome_id = $result[0]->id;
  448. // get typ_semester_objective_id
  449. $result = DB::table('typ_semester_objectives')
  450. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  451. ->where('objective_id', $objective_id)
  452. ->get();
  453. $typ_semester_objective_id = $result[0]->id;
  454. //delete old objective relation if it exists
  455. if ($previous_course_id != 'nothing_selected') {
  456. $result = DB::table('typ_semester_courses')
  457. ->where('typ_semester_objective_id', $typ_semester_objective_id)
  458. ->where('course_id', $previous_course_id)
  459. ->get();
  460. if (count($result) != 0) {
  461. DB::table('typ_semester_courses')
  462. ->where('typ_semester_objective_id', $typ_semester_objective_id)
  463. ->where('course_id', $previous_course_id)
  464. ->delete();
  465. }
  466. }
  467. //create new objective relation
  468. if ($new_course_id != 'nothing_selected') {
  469. $result = DB::table('typ_semester_courses')
  470. ->where('typ_semester_objective_id', $typ_semester_objective_id)
  471. ->where('course_id', $new_course_id)
  472. ->get();
  473. if (count($result) == 0) {
  474. $_ = DB::table('typ_semester_courses')->insertGetId(
  475. array(
  476. 'typ_semester_objective_id' => $typ_semester_objective_id,
  477. 'course_id' => $new_course_id
  478. )
  479. );
  480. }
  481. }
  482. return 'update succes?';
  483. }
  484. public function createAnnualPlan($program_id)
  485. {
  486. $input_id = Input::get('typ_id');
  487. $current_typ = DB::select("select * from three_year_plan where id = {$input_id}")[0];
  488. $count = 0;
  489. $yearStartPlusOne = $current_typ->year_start + 1;
  490. $yearStart = $current_typ->year_start;
  491. Log::info($yearStart);
  492. Log::info($yearStartPlusOne);
  493. while ($count < 3) {
  494. $firstSemester = DB::select("select * from semesters where name like 'First Semester {$yearStart}-{$yearStartPlusOne}'");
  495. $secondSemester = DB::select("select * from semesters where name like 'Second Semester {$yearStart}-{$yearStartPlusOne}'");
  496. if (count($firstSemester) && count($secondSemester)) {
  497. Log::info($firstSemester);
  498. Log::info($secondSemester);
  499. $query = DB::select("select * from annual_cycle where semester_start ={$firstSemester[0]->id} and semester_end ={$secondSemester[0]->id} ");
  500. if (!count($query)) {
  501. DB::insert("insert into annual_cycle (academic_year, semester_start, semester_end) values ('{$yearStart}-{$yearStartPlusOne}', {$firstSemester[0]->id}, {$secondSemester[0]->id})");
  502. }
  503. $an_cycle = DB::table('annual_cycle')->where('semester_start', '=', $firstSemester[0]->id)
  504. ->where('semester_end', '=', $secondSemester[0]->id)
  505. ->first();
  506. $query = DB::table('annual_plans')->where("annual_cycle_id", '=', $an_cycle->id)
  507. ->where('program_id', '=', $program_id)->first();
  508. if (!$query) {
  509. DB::insert("insert into annual_plans (`annual_cycle_id`, `program_id`) values ({$an_cycle->id}, {$program_id})");
  510. }
  511. }
  512. $count++;
  513. $yearStart++;
  514. $yearStartPlusOne++;
  515. }
  516. }
  517. public function printPlan($program_id, $typ)
  518. {
  519. $program = DB::table('programs')->where('id', $program_id)->first();
  520. $three_year_plan = DB::table('three_year_plan')->where('id', $typ)->first();
  521. $typ_program_id = DB::table('typ_program')->where('three_year_plan_id', $three_year_plan->id)
  522. ->where('program_id', $program->id)
  523. ->first()->id;
  524. $typ_semesters = DB::table('semesters')
  525. ->join('typ_semesters', 'semesters.id', '=', 'typ_semesters.semester_id')
  526. ->where('typ_id', $three_year_plan->id)
  527. ->orderBy('semester_id')
  528. ->get();
  529. foreach ($typ_semesters as $semester) {
  530. $typ_semester_outcome[$semester->semester_id] = DB::table('typ_semester_outcome')
  531. ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
  532. ->where('typ_program_id', $typ_program_id)
  533. ->where('semester_id', $semester->semester_id)
  534. ->select('typ_semester_outcome.id as typ_id')
  535. ->addSelect('outcomes.id as outcome_id', 'outcomes.name')
  536. ->get();
  537. foreach ($typ_semester_outcome[$semester->semester_id] as $outcome) {
  538. $outcome->objectives = DB::table('typ_semester_objectives')
  539. ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  540. ->where('typ_semester_outcome_id', $outcome->typ_id)
  541. ->select('typ_semester_objectives.id as typ_obj_id')
  542. ->addSelect('objectives.text', 'objectives.id as objective_id')
  543. ->get();
  544. foreach ($outcome->objectives as $objective) {
  545. $objective->courses = DB::table('typ_semester_courses')
  546. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  547. ->where('typ_semester_objective_id', $objective->typ_obj_id)
  548. ->get();
  549. }
  550. }
  551. }
  552. Log::info($typ_semester_outcome);
  553. return View::make('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome'));
  554. }
  555. }