Ei kuvausta

ThreeYearPlanController.php 24KB

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