Brak opisu

ThreeYearPlanController.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <?php
  2. use Illuminate\Database\Eloquent\Collection;
  3. class ThreeYearPlanController extends \BaseController
  4. {
  5. public function threeYearsReport()
  6. {
  7. $user_id = auth::user()->id;
  8. // el ID de los semestres que el usuario tiene seleccionado.
  9. $semesters_ids = Session::get('semesters_ids');
  10. // buscar informacion de los semestres seleccionados
  11. $semesters = Semester::whereIn('id',$semesters_ids)->get();
  12. $title = "Three Year Plans Planning";
  13. $outcomes = Outcome::orderBy('name', 'ASC')
  14. ->where('deactivation_date','=','0000-00-00')
  15. ->orWhereNull('deactivation_date')
  16. ->get();
  17. // $outcomes = DB::table('outcomes')
  18. // ->orderBy('name', 'asc')
  19. // ->get();
  20. $typs = DB::table('three_year_plan')
  21. ->orderBy('year_start', 'asc')
  22. ->get();
  23. $criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
  24. // $criteria = DB::table('criteria')
  25. // ->orderBy('name', 'asc')
  26. // ->get();
  27. $program_id = DB::table('program_user')
  28. ->where('user_id',$user_id)
  29. // ->where('user_id',8) //voy a usar 8 porque user 60 no tiene
  30. ->select('program_id')
  31. ->get();
  32. $program_id = $program_id[0]->program_id; //program id 15 debido al user 8
  33. // se annadio la nueva variable
  34. return View::make('global.view-three-year-plan', compact('title', 'outcomes', 'typs', 'criteria', 'semesters', 'program_id'));
  35. }
  36. public function fetchThreeYears()
  37. {
  38. $id = Input::get('id');
  39. $semesters = DB::table('typ_semesters')
  40. ->join('semesters','semesters.id','=','typ_semesters.semester_id')
  41. ->where('typ_semesters.typ_id',$id)
  42. // ->select('semesters.*')
  43. ->orderBy('typ_semesters.semester_id', 'asc')
  44. ->get();
  45. $typs = DB::table('three_year_plan')
  46. ->where('id',$id)
  47. ->orderBy('year_start', 'asc')
  48. ->get();
  49. $typs = $typs[0];
  50. $typs->semesters = $semesters;
  51. return array
  52. (
  53. 'typ' => $typs,
  54. );
  55. }
  56. public function update_typ_outcomes_semesters()
  57. {
  58. $outcomeSemesterArray = json_decode(Input::get('outcomeSemesterArray'), true);
  59. $typ_id = Input::get('typ_id');
  60. $user_id = auth::user()->id; //ya, tester es 60
  61. $program_id = DB::table('program_user')
  62. ->where('user_id',$user_id)
  63. // ->where('user_id',8) //voy a usar 8 porque user 60 no tiene
  64. ->select('program_id')
  65. ->get();
  66. $program_id = $program_id[0]->program_id; //program id 15 debido al user 8
  67. $result = DB::table('typ_program')
  68. ->where('three_year_plan_id',$typ_id)
  69. ->where('program_id',$program_id)
  70. ->get();
  71. // create the relation if it doesnt exist
  72. if(count($result) == 0){
  73. $typ_program_id = DB::table('typ_program')->insertGetId(
  74. array('three_year_plan_id' => $typ_id,
  75. 'program_id' => $program_id)
  76. );
  77. } else {
  78. $typ_program_id = $result[0]->id;
  79. }
  80. //go through array
  81. foreach ($outcomeSemesterArray as $outcome_semester) {
  82. // foreach of the 6 semesters
  83. foreach ($outcome_semester["semesters"] as $semester) {
  84. $insert = $semester[1];
  85. $outcome_id = explode("-sem",$semester[0])[0];
  86. $semester_code = explode("-sem",$semester[0])[1];
  87. $result = DB::table('semesters')
  88. ->where('code',$semester_code)
  89. ->select('id')
  90. ->get();
  91. if(count($result) == 0){
  92. continue;
  93. }
  94. $semester_id = $result[0]->id;
  95. // verify if it exists
  96. $result = DB::table('typ_semester_outcome')
  97. ->where('typ_program_id',$typ_program_id)
  98. ->where('semester_id',$semester_id)
  99. ->where('outcome_id',$outcome_id)
  100. ->get();
  101. // if true, it should get inserted
  102. if ($insert == true) {
  103. // if == 0, then insert
  104. if(count($result) == 0){
  105. $_ = DB::table('typ_semester_outcome')->insertGetId(
  106. array('typ_program_id' => $typ_program_id,
  107. 'semester_id' => $semester_id,
  108. 'outcome_id' => $outcome_id)
  109. );
  110. }
  111. //if exists, then do nothing
  112. }
  113. // if false, it should get deleted
  114. else { //value == false
  115. // if == 0, it doesnt exist. we do nothing
  116. if(count($result) == 0){
  117. //pass
  118. }
  119. //if exists, then do nothing
  120. else {
  121. DB::table('typ_semester_outcome')
  122. ->where('typ_program_id', $typ_program_id)
  123. ->where('semester_id', $semester_id)
  124. ->where('outcome_id', $outcome_id)
  125. ->delete();
  126. }
  127. }
  128. }
  129. }
  130. return;
  131. }
  132. public function lookup_typ_semester_outcome()
  133. {
  134. $box_value = array();
  135. $info = Input::get('info');
  136. foreach ($info as $values) {
  137. $outcome_id = $values[0];
  138. $semester_code = $values[1];
  139. $program_id = $values[2];
  140. $box_id = $values[3];
  141. $typ_id = $values[4];
  142. //buscar id del typ
  143. $result = DB::table('typ_program')
  144. ->where('three_year_plan_id',$typ_id)
  145. ->where('program_id',$program_id)
  146. ->get();
  147. $typ_program_id = $result[0]->id;
  148. // buscar si existe el outcome_semester
  149. $result = DB::table('typ_semester_outcome')
  150. ->join('semesters','semesters.id','=','typ_semester_outcome.semester_id')
  151. ->where('typ_program_id',$typ_program_id)
  152. ->where('semesters.code',$semester_code)
  153. ->where('outcome_id',$outcome_id)
  154. ->get();
  155. // if it doesnt exist
  156. if (count($result)==0){
  157. array_push($box_value,array($box_id,0));
  158. } else {
  159. array_push($box_value,array($box_id,1));
  160. }
  161. }
  162. return array
  163. (
  164. 'box_value' => ($box_value)
  165. );
  166. }
  167. public function section2_on_change()
  168. {
  169. $typ_id = Input::get('typ_id');
  170. // typ_id: (typ_id),
  171. $outcome_id = Input::get('outcome_id');
  172. // outcome_id: (outcome_id),
  173. $semester_id = Input::get('semester_id');
  174. // semester_id: (semester_id),
  175. $previous_objective_id = Input::get('previous_objective_id');
  176. // previous_objective_id: (previous_objective_id),
  177. $new_objective_id = Input::get('new_objective_id');
  178. // new_objective_id: (new_objective_id)
  179. // get program_id
  180. $user_id = auth::user()->id; //ya, tester es 60
  181. $program_id = DB::table('program_user')
  182. ->where('user_id',$user_id)
  183. // ->where('user_id',8) //voy a usar 8 porque user 60 no tiene
  184. ->select('program_id')
  185. ->get();
  186. $program_id = $program_id[0]->program_id; //program id 15 debido al user 8
  187. // get typ_program_id
  188. $result = DB::table('typ_program')
  189. ->where('three_year_plan_id',$typ_id)
  190. ->where('program_id',$program_id)
  191. ->get();
  192. $typ_program_id = $result[0]->id;
  193. // get typ_semester_outcome_id
  194. $result = DB::table('typ_semester_outcome')
  195. ->where('typ_program_id',$typ_program_id)
  196. ->where('semester_id',$semester_id)
  197. ->where('outcome_id',$outcome_id)
  198. ->get();
  199. $typ_semester_outcome_id = $result[0]->id;
  200. //delete old objective relation if it exists
  201. if ($previous_objective_id != 'nothing_selected') {
  202. $result = DB::table('typ_semester_objectives')
  203. ->where('typ_semester_outcome_id',$typ_semester_outcome_id)
  204. ->where('objective_id',$previous_objective_id)
  205. ->get();
  206. if (count($result) != 0) {
  207. DB::table('typ_semester_objectives')
  208. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  209. ->where('objective_id', $previous_objective_id)
  210. ->delete();
  211. }
  212. }
  213. //create new objective relation
  214. if ($new_objective_id != 'nothing_selected') {
  215. $result = DB::table('typ_semester_objectives')
  216. ->where('typ_semester_outcome_id',$typ_semester_outcome_id)
  217. ->where('objective_id',$new_objective_id)
  218. ->get();
  219. if (count($result) == 0) {
  220. $_ = DB::table('typ_semester_objectives')->insertGetId(
  221. array(
  222. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  223. 'objective_id' => $new_objective_id)
  224. );
  225. }
  226. }
  227. return 'update was succes';
  228. }
  229. public function section2_arrive()
  230. {
  231. // get program_id
  232. $user_id = auth::user()->id; //ya, tester es 60
  233. $program_id = DB::table('program_user')
  234. ->where('user_id',$user_id)
  235. // ->where('user_id',8) //voy a usar 8 porque user 60 no tiene
  236. ->select('program_id')
  237. ->get();
  238. $program_id = $program_id[0]->program_id; //program id 15 debido al user 8
  239. // get typ_program_id
  240. $typ_id = Input::get('typ_id');
  241. $result = DB::table('typ_program')
  242. ->where('three_year_plan_id',$typ_id)
  243. ->where('program_id',$program_id)
  244. ->get();
  245. $typ_program_id = $result[0]->id;
  246. //search selected outcomes,semesters and get their objectives
  247. $selected_outcomes = DB::table('typ_semester_outcome')
  248. ->join('outcomes','outcomes.id','=','typ_semester_outcome.outcome_id')
  249. ->where('typ_semester_outcome.typ_program_id',$typ_program_id)
  250. ->distinct('typ_semester_outcome.outcome_id')
  251. ->select('typ_semester_outcome.outcome_id')
  252. ->orderBy('outcomes.name', 'asc')
  253. ->get();
  254. $selected_objectives_array = array();
  255. $outcomes_info_array = array();
  256. // $objectives_info_array = array();
  257. $semesters_array = array();
  258. $info = array();
  259. foreach ($selected_outcomes as $outcome) {
  260. $outcome_id = $outcome->outcome_id;
  261. $result_outcomes = DB::table('outcomes')
  262. ->where('outcomes.id',$outcome_id)
  263. ->orderBy('outcomes.name', 'asc')
  264. ->get();
  265. foreach ($result_outcomes as $outcome_) {
  266. $result_semesters = DB::table('typ_semester_outcome')
  267. ->join('semesters','semesters.id','=','typ_semester_outcome.semester_id')
  268. ->where('typ_semester_outcome.typ_program_id',$typ_program_id)
  269. ->where('typ_semester_outcome.outcome_id',$outcome_->id)
  270. ->select('typ_semester_outcome.id','typ_semester_outcome.semester_id','semesters.code','semesters.name')
  271. ->get();
  272. // buscar info sobre selected_semsters
  273. $outcome_->selected_semesters = array();
  274. foreach ($result_semesters as $semesters_) {
  275. $typ_semester_outcome_id = $semesters_->id;
  276. // lookup previusly selected objectives
  277. $result_objectives = DB::table('typ_semester_objectives')
  278. ->join('objectives','objectives.id','=','typ_semester_objectives.objective_id')
  279. ->where('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome_id)
  280. ->orderBy('typ_semester_objectives.id', 'asc')
  281. ->get();
  282. $semesters_->selected_objectives = array();
  283. foreach ($result_objectives as $objectives_) {
  284. array_push($semesters_->selected_objectives, $objectives_);
  285. }
  286. // lookup available objectives
  287. $result_objectives = DB::table('criterion_objective_outcome')
  288. ->join('outcomes','outcomes.id','=','criterion_objective_outcome.outcome_id')
  289. ->join('objectives','objectives.id','=','criterion_objective_outcome.objective_id')
  290. ->join('objective_program','objective_program.objective_id','=','objectives.id')
  291. ->where('objective_program.program_id',$program_id)
  292. ->where('criterion_objective_outcome.outcome_id',$outcome_id)
  293. ->select('objectives.id','objectives.text','outcomes.name as outcome_name')
  294. ->orderBy('objectives.text', 'asc')
  295. ->get();
  296. $semesters_->available_objectives = array();
  297. foreach ($result_objectives as $objectives_) {
  298. array_push($semesters_->available_objectives, $objectives_);
  299. }
  300. array_push($outcome_->selected_semesters, $semesters_);
  301. }
  302. array_push($info, $outcome_);
  303. }
  304. }
  305. return $info;
  306. }
  307. public function section3_arrive()
  308. {
  309. // get program_id
  310. $user_id = auth::user()->id; //ya, tester es 60
  311. $program_id = DB::table('program_user')
  312. ->where('user_id',$user_id)
  313. // ->where('user_id',8) //voy a usar 8 porque user 60 no tiene
  314. ->select('program_id')
  315. ->get();
  316. $program_id = $program_id[0]->program_id; //program id 15 debido al user 8
  317. // get typ_program_id
  318. $typ_id = Input::get('typ_id');
  319. $result = DB::table('typ_program')
  320. ->where('three_year_plan_id',$typ_id)
  321. ->where('program_id',$program_id)
  322. ->get();
  323. $typ_program_id = $result[0]->id;
  324. //search selected outcomes,semesters and get their objectives
  325. $selected_outcomes = DB::table('typ_semester_outcome')
  326. ->join('outcomes','outcomes.id','=','typ_semester_outcome.outcome_id')
  327. ->where('typ_semester_outcome.typ_program_id',$typ_program_id)
  328. ->distinct('typ_semester_outcome.outcome_id')
  329. ->select('typ_semester_outcome.outcome_id')
  330. ->orderBy('outcomes.name', 'asc')
  331. ->get();
  332. $selected_objectives_array = array();
  333. $outcomes_info_array = array();
  334. // $objectives_info_array = array();
  335. $semesters_array = array();
  336. $info = array();
  337. foreach ($selected_outcomes as $outcome) {
  338. $outcome_id = $outcome->outcome_id;
  339. $result_outcomes = DB::table('outcomes')
  340. ->where('outcomes.id',$outcome_id)
  341. ->get();
  342. foreach ($result_outcomes as $outcome_) {
  343. $result_semesters = DB::table('typ_semester_outcome')
  344. ->join('semesters','semesters.id','=','typ_semester_outcome.semester_id')
  345. ->where('typ_semester_outcome.typ_program_id',$typ_program_id)
  346. ->where('typ_semester_outcome.outcome_id',$outcome_->id)
  347. ->select('typ_semester_outcome.id','typ_semester_outcome.semester_id','semesters.code','semesters.name')
  348. ->get();
  349. // buscar info sobre selected_semsters
  350. $outcome_->selected_semesters = array();
  351. foreach ($result_semesters as $semesters_) {
  352. $semester_id = $semesters_->semester_id;
  353. $typ_semester_outcome_id = $semesters_->id;
  354. $result_objectives = DB::table('typ_semester_objectives')
  355. ->join('objectives','objectives.id','=','typ_semester_objectives.objective_id')
  356. ->where('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome_id)
  357. ->select('typ_semester_objectives.id as typ_semester_objectives_id','objectives.*','typ_semester_objectives.*')
  358. ->orderBy('typ_semester_objectives.id', 'asc')
  359. ->get();
  360. $semesters_->selected_objectives = array();
  361. foreach ($result_objectives as $objectives_) {
  362. $objective_id = $objectives_->objective_id;
  363. $program_id = $objectives_->program_id;
  364. $result_courses = DB::table('objective_program')
  365. ->join('objectives','objectives.id','=','objective_program.objective_id')
  366. ->join('courses','courses.program_id','=','objective_program.program_id')
  367. ->where('objective_program.objective_id', $objective_id)
  368. ->where('objective_program.program_id', $program_id)
  369. ->where('courses.semester_id', $semester_id)
  370. ->distinct('courses.name','courses.code')
  371. ->select('courses.id as course_id','courses.name','courses.code','objective_program.objective_id','objective_program.program_id')
  372. ->orderBy('courses.name', 'asc')
  373. ->groupBy('courses.name','courses.code')
  374. ->get();
  375. $objectives_->available_courses = array();
  376. foreach ($result_courses as $courses_) {
  377. array_push($objectives_->available_courses, $courses_);
  378. }
  379. // search for previusly selected courses
  380. $typ_semester_objective_id = $objectives_->typ_semester_objectives_id;
  381. $result_courses = DB::table('typ_semester_courses')
  382. ->join('courses','courses.id','=','typ_semester_courses.course_id')
  383. ->where('typ_semester_courses.typ_semester_objective_id', $typ_semester_objective_id)
  384. ->select('courses.id as course_id','courses.*','typ_semester_courses.*')
  385. ->orderBy('courses.name', 'asc')
  386. ->get();
  387. $objectives_->selected_courses = array();
  388. foreach ($result_courses as $courses_) {
  389. array_push($objectives_->selected_courses, $courses_);
  390. }
  391. array_push($semesters_->selected_objectives, $objectives_);
  392. }
  393. array_push($outcome_->selected_semesters, $semesters_);
  394. }
  395. array_push($info, $outcome_);
  396. }
  397. }
  398. return $info;
  399. }
  400. public function section3_on_change()
  401. {
  402. $typ_id = Input::get('typ_id');
  403. // typ_id: (typ_id),
  404. $outcome_id = Input::get('outcome_id');
  405. // outcome_id: (outcome_id),
  406. $semester_id = Input::get('semester_id');
  407. // semester_id: (semester_id),
  408. $objective_id = Input::get('objective_id');
  409. // objective_id: (objective_id),
  410. $previous_course_id = Input::get('previous_course_id');
  411. // previous_course_id: (previous_course_id),
  412. $new_course_id = Input::get('new_course_id');
  413. // new_course_id: (new_course_id)
  414. // get program_id
  415. $user_id = auth::user()->id; //ya, tester es 60
  416. $program_id = DB::table('program_user')
  417. ->where('user_id',$user_id)
  418. // ->where('user_id',8) //voy a usar 8 porque user 60 no tiene
  419. ->select('program_id')
  420. ->get();
  421. $program_id = $program_id[0]->program_id; //program id 15 debido al user 8
  422. // get typ_program_id
  423. $result = DB::table('typ_program')
  424. ->where('three_year_plan_id',$typ_id)
  425. ->where('program_id',$program_id)
  426. ->get();
  427. $typ_program_id = $result[0]->id;
  428. // get typ_semester_outcome_id
  429. $result = DB::table('typ_semester_outcome')
  430. ->where('typ_program_id',$typ_program_id)
  431. ->where('semester_id',$semester_id)
  432. ->where('outcome_id',$outcome_id)
  433. ->get();
  434. $typ_semester_outcome_id = $result[0]->id;
  435. // get typ_semester_objective_id
  436. $result = DB::table('typ_semester_objectives')
  437. ->where('typ_semester_outcome_id',$typ_semester_outcome_id)
  438. ->where('objective_id',$objective_id)
  439. ->get();
  440. $typ_semester_objective_id = $result[0]->id;
  441. //delete old objective relation if it exists
  442. if ($previous_course_id != 'nothing_selected') {
  443. $result = DB::table('typ_semester_courses')
  444. ->where('typ_semester_objective_id',$typ_semester_objective_id)
  445. ->where('course_id',$previous_course_id)
  446. ->get();
  447. if (count($result) != 0) {
  448. DB::table('typ_semester_courses')
  449. ->where('typ_semester_objective_id', $typ_semester_objective_id)
  450. ->where('course_id', $previous_course_id)
  451. ->delete();
  452. }
  453. }
  454. //create new objective relation
  455. if ($new_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',$new_course_id)
  459. ->get();
  460. if (count($result) == 0) {
  461. $_ = DB::table('typ_semester_courses')->insertGetId(
  462. array(
  463. 'typ_semester_objective_id' => $typ_semester_objective_id,
  464. 'course_id' => $new_course_id)
  465. );
  466. }
  467. }
  468. return 'update succes?';
  469. }
  470. }