Bez popisu

AdministratorsController.php 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <?php
  2. class AdministratorsController extends \BaseController
  3. {
  4. private function outcomes_semesters($selected_semesters, $level)
  5. {
  6. $min_start = "9000-01-01 00:00:00";
  7. $max_end = "1000-01-01 00:00:00";
  8. foreach ($selected_semesters as $semester) {
  9. if ($min_start > $semester->start) {
  10. $min_start = $semester->start;
  11. }
  12. if ($max_end < $semester->end) {
  13. $max_end = $semester->end;
  14. }
  15. }
  16. $outcomes = Outcome::where(function ($query) use ($min_start) {
  17. $query->where('deactivation_date', '>=', $min_start)
  18. ->orWhere('deactivation_date', null);
  19. })
  20. ->where('activation_date', '<=', $max_end)
  21. ->where(function ($query2) use ($level) {
  22. $query2->where("level", $level + 1)
  23. ->orWhere("level", 3);
  24. })
  25. ->orderBy('name', 'ASC')
  26. ->get();
  27. $outcomeCount = Outcome::where(function ($query) use ($min_start) {
  28. $query->where('deactivation_date', '>=', $min_start)
  29. ->orWhere('deactivation_date', null);
  30. })
  31. ->where('activation_date', '<=', $max_end)
  32. ->where(function ($query2) use ($level) {
  33. $query2->where("level", $level + 1)
  34. ->orWhere("level", 3);
  35. })
  36. ->count();
  37. foreach ($outcomes as $outcome) {
  38. // var_dump($outcome->id);
  39. // print "<br>";
  40. $outcomes_attempted[$outcome->id] = $outcome->attempted($selected_semesters, $level);
  41. $outcomes_achieved[$outcome->id] = $outcome->achieved($selected_semesters, $level);
  42. }
  43. $uhs_school_id = School::where('name', 'LIKE', '%UHS%')->first()->id;
  44. $uhs_program_id = Program::where('name', 'LIKE', '%UHS%')->first()->id;
  45. foreach ($outcomes as $outcome) {
  46. $achievedProgramsPerOutcome[$outcome->id] = 0; // For each program with courses that do assessment
  47. $attemptedProgramsPerOutcome[$outcome->id] = 0; // For each program with courses that do assessment
  48. foreach (Program::with(array('courses' => function ($query) {
  49. // $query->whereNotNull('outcomes_attempted');
  50. $query->where('code', '!=', 'TEST');
  51. $query->whereIn('semester_id', Session::get('semesters_ids'));
  52. }))->where('is_graduate', $level)->where('school_id', '!=', $uhs_school_id)->orderBy('name', 'asc')->get() as $program) {
  53. $achieved_outcomes_per_program[$program->id] = 0;
  54. $attempted_outcomes_per_program[$program->id] = 0;
  55. $participating_programs[$program->id] = (object)array('id' => $program->id, 'name' => $program->name, 'is_graduate' => $program->is_graduate, 'school_id' => $program->school_id);
  56. // SELECT ac.id activity_criterion_id, ac.activity_id, ac.expected_student_score, ac.expected_percentage_students_achieving, co.program_id FROM activity_criterion ac, criteria c, activities a, objectives o, courses co where co.id=a.course_id and co.semester_id=13 and a.id=ac.activity_id and c.id = ac.criterion_id and o.id=c.objective_id and o.outcome_id = 2 order by program_id
  57. $program_attempted_outcome = $program->attempted_outcome($outcome->id, $selected_semesters);
  58. $attempted_outcomes_per_program[$program->id] += $program_attempted_outcome;
  59. // var_dump($program_attempted_outcome);
  60. // exit();
  61. if ($program_attempted_outcome) {
  62. $program_achieved_outcome = $program->achieved_outcome($outcome->id, $selected_semesters);
  63. $achieved_outcomes_per_program[$program->id] += $program_achieved_outcome;
  64. $attemptedProgramsPerOutcome[$outcome->id] += $program_attempted_outcome;
  65. // $attemptedProgramsPerOutcome[$outcome->id]+=1;
  66. $achievedProgramsPerOutcome[$outcome->id] += $program_achieved_outcome;
  67. // $achieved_outcomes_per_program[$outcome->id]=$program->achieved_outcome($outcome->id, $selected_semesters);
  68. // if($attempted_outcomes_per_program[$outcome->id]!=0 && 100.0*$achieved_outcomes_per_program[$outcome->id]/$attempted_outcomes_per_program[$outcome->id] >= $outcome->expected_outcome)
  69. // {
  70. // $achievedProgramsPerOutcome[$outcome->id]+=1;
  71. // // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  72. // }
  73. }
  74. }
  75. }
  76. return array('outcomes' => $outcomes, 'outcomes_attempted' => $outcomes_attempted, 'outcomes_achieved' => $outcomes_achieved, 'attemptedProgramsPerOutcome' => $attemptedProgramsPerOutcome, 'achievedProgramsPerOutcome' => $achievedProgramsPerOutcome, 'participating_programs' => $participating_programs);
  77. }
  78. public function overview()
  79. {
  80. $selected_semesters = Semester::find(Session::get('semesters_ids'));
  81. $subgraduado = $this->outcomes_semesters($selected_semesters, 0);
  82. $outcomes_subgrad = $subgraduado['outcomes'];
  83. $undergrad_outcomes_achieved = $subgraduado['outcomes_achieved'];
  84. $undergrad_outcomes_attempted = $subgraduado['outcomes_attempted'];
  85. $attemptedUndergradProgramsPerOutcome = $subgraduado['attemptedProgramsPerOutcome'];
  86. $achievedUndergradProgramsPerOutcome = $subgraduado['achievedProgramsPerOutcome'];
  87. $participating_undergrad_programs = $subgraduado['participating_programs'];
  88. $graduado = $this->outcomes_semesters($selected_semesters, 1);
  89. $outcomes_grad = $graduado['outcomes'];
  90. $grad_outcomes_achieved = $graduado['outcomes_achieved'];
  91. $grad_outcomes_attempted = $graduado['outcomes_attempted'];
  92. $attemptedGradProgramsPerOutcome = $graduado['attemptedProgramsPerOutcome'];
  93. $achievedGradProgramsPerOutcome = $graduado['achievedProgramsPerOutcome'];
  94. $participating_grad_programs = $graduado['participating_programs'];
  95. //Total amount of learning outcomes
  96. // $outcomeCount = Outcome::withTrashed()->count();
  97. // $selected_semester = Semester::find(Session::get('semesters_ids')[0]);
  98. // $outcomes_subgrad = Outcome::where(function($query) use ($selected_semester)
  99. // {
  100. // $query->where('deactivation_date', '>=', $selected_semester->start)
  101. // ->orWhere('deactivation_date', null);
  102. // })
  103. // ->where('activation_date', '<=', $selected_semester->end)
  104. // ->where(function($query2)
  105. // {
  106. // $query2->where("level",1)
  107. // ->orWhere("level",3);
  108. // })
  109. // ->orderBy('name', 'ASC')
  110. // ->get();
  111. // $outcomeCount_subgrad = Outcome::where(function($query) use ($selected_semester)
  112. // {
  113. // $query->where('deactivation_date', '>=', $selected_semester->start)
  114. // ->orWhere('deactivation_date', null);
  115. // })
  116. // ->where('activation_date', '<=', $selected_semester->end)
  117. // ->where(function($query2)
  118. // {
  119. // $query2->where("level",1)
  120. // ->orWhere("level",3);
  121. // })
  122. // ->count();
  123. //
  124. // $outcomes_grad = Outcome::where(function($query) use ($selected_semester){$query->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null);})->where(function($query2){$query2->where("level",2)->orWhere("level",3);})->orderBy('name', 'ASC')->get();
  125. // $outcomeCount_grad = Outcome::where(function($query) use ($selected_semester){$query->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null);})->where(function($query2){$query2->where("level",2)->orWhere("level",3);})->count();
  126. // print($outcomeCount_subgrad);
  127. // print($outcomeCount_grad);
  128. // Id for excluding UHS from records
  129. $uhs_school_id = School::where('name', 'LIKE', '%UHS%')->first()->id;
  130. // $uhs_program_id = Program::where('name', 'LIKE', '%UHS%')->first()->id;
  131. $schools = School::where('id', '!=', $uhs_school_id)->orderBy('name', 'asc')->get();
  132. $title = 'Campus Overview';
  133. /**
  134. * Calculate campus wide outcome performance by counting the number of students
  135. $undergrad_outcomes_attempted will have the number of criteria that was assessed in undergradute courses during the selected semester
  136. $undergrad_outcomes_achieved will have the number of criteria that was assessed in undergradute courses during the selected semester
  137. where the percentage of students that obtained a better or equal score than the expected_student_score established in the
  138. activity_criterion table is greater or equal than the expected_percentage_students_achieving also established in the
  139. activity_criterion table
  140. */
  141. // foreach($outcomes_subgrad as $outcome)
  142. // {
  143. // $undergrad_outcomes_attempted[$outcome->id]=$outcome->attempted($selected_semester->id,0);
  144. // $undergrad_outcomes_achieved[$outcome->id]=$outcome->achieved($selected_semester->id,0);
  145. // }
  146. // var_dump($undergrad_outcomes_attempted);
  147. // print"<br>";
  148. // var_dump($undergrad_outcomes_achieved);
  149. // print"<br>";
  150. // foreach($outcomes_grad as $outcome)
  151. // {
  152. // $grad_outcomes_attempted[$outcome->id]=$outcome->attempted($selected_semester->id,1);
  153. // $grad_outcomes_achieved[$outcome->id]=$outcome->achieved($selected_semester->id,1);
  154. // }
  155. /**
  156. * Calculate how many programs achieved and attempted each outcome
  157. */
  158. // Number of programs that achieved a particular learning outcome
  159. // $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount_subgrad, 0);
  160. // Number of programs that attempted a particular learning outcome
  161. // $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount_subgrad, 0);
  162. // Names of programs doing assessment
  163. // Fetch programs with participation
  164. // $participating_undergrad_programs = DB::table('VIEW_participating_programs')
  165. // ->whereIn('semester_id', Session::get('semesters_ids'))
  166. // ->where('is_graduate', 0)
  167. // ->groupBy('id')
  168. // ->orderBy('name', 'asc')
  169. // ->get();
  170. // $output = array();
  171. /**
  172. * Calculate how many undergrad programs achieved and attempted each outcome
  173. */
  174. // foreach ($outcomes_subgrad as $outcome)
  175. // {
  176. // $achieved_outcomes_per_undergrad_program[$outcome->id]=0;
  177. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  178. // $achievedUndergradProgramsPerOutcome[$outcome->id]=0; // For each program with courses that do assessment
  179. // $attemptedUndergradProgramsPerOutcome[$outcome->id]=0; // For each program with courses that do assessment
  180. // foreach (Program::with(array('courses' => function($query){
  181. // // $query->whereNotNull('outcomes_attempted');
  182. // $query->where('code', '!=', 'TEST');
  183. // $query->whereIn('semester_id', Session::get('semesters_ids'));
  184. // }))->where('is_graduate', 0)->where('school_id', '!=', $uhs_school_id)->orderBy('name', 'asc')->get() as $program)
  185. // {
  186. // $participating_undergrad_programs[$program->id]=(object)array('id'=>$program->id, 'name'=>$program->name, 'is_graduate'=> $program->is_graduate, 'school_id'=>$program->school_id,'semestre_id',$selected_semester);
  187. //
  188. // // SELECT ac.id activity_criterion_id, ac.activity_id, ac.expected_student_score, ac.expected_percentage_students_achieving, co.program_id FROM activity_criterion ac, criteria c, activities a, objectives o, courses co where co.id=a.course_id and co.semester_id=13 and a.id=ac.activity_id and c.id = ac.criterion_id and o.id=c.objective_id and o.outcome_id = 2 order by program_id
  189. // $program_attempted_outcome=$program->attempted_outcome($outcome->id, $selected_semester->id);
  190. // $attempted_outcomes_per_undergrad_program[$outcome->id]+=$program_attempted_outcome;
  191. // // var_dump($program_attempted_outcome);
  192. // // exit();
  193. // if($program_attempted_outcome)
  194. // {
  195. // $attemptedUndergradProgramsPerOutcome[$outcome->id]+=1;
  196. // $achieved_outcomes_per_undergrad_program[$outcome->id]=$program->achieved_outcome($outcome->id, $selected_semester->id);
  197. // if($attempted_outcomes_per_undergrad_program[$outcome->id]!=0 && 100.0*$achieved_outcomes_per_undergrad_program[$outcome->id]/$attempted_outcomes_per_undergrad_program[$outcome->id] >= $outcome->expected_outcome)
  198. // {
  199. // $achievedUndergradProgramsPerOutcome[$outcome->id]+=1;
  200. // // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedUndergradProgramsPerOutcome);
  201. // }
  202. // }
  203. // }
  204. // }
  205. // var_dump($attempted_outcomes_per_undergrad_program);
  206. // print"<br>";
  207. // var_dump($achieved_outcomes_per_undergrad_program);
  208. // print"<br>";
  209. // var_dump($attemptedUndergradProgramsPerOutcome);
  210. // print"<br>";
  211. // var_dump($achievedUndergradProgramsPerOutcome);
  212. // print"<br>";
  213. // exit();
  214. /**
  215. * Calculate how many grad programs achieved and attempted each outcome
  216. $grad_outcomes_attempted will have the number of criteria that was assessed in gradute courses during the selected semester
  217. $grad_outcomes_achieved will have the number of criteria that was assessed in gradute courses during the selected semester
  218. where the percentage of students that obtained a better or equal score than the expected_student_score established in the
  219. activity_criterion table is greater or equal than the expected_percentage_students_achieving also established in the
  220. activity_criterion table
  221. */
  222. // Names of programs doing assessment
  223. // $participating_grad_programs = DB::table('VIEW_participating_programs')
  224. // ->whereIn('semester_id', Session::get('semesters_ids'))
  225. // ->where('is_graduate', 1)
  226. // ->groupBy('id')
  227. // ->orderBy('name', 'asc')
  228. // ->get();
  229. // foreach ($outcomes_grad as $outcome)
  230. // {
  231. // $achieved_outcomes_per_grad_program[$outcome->id]=0;
  232. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  233. // $achievedGradProgramsPerOutcome[$outcome->id]=0; // For each program with courses that do assessment
  234. // $attemptedGradProgramsPerOutcome[$outcome->id]=0; // For each program with courses that do assessment
  235. // foreach (Program::with(array('courses' => function($query){
  236. // $query->whereNotNull('outcomes_attempted');
  237. // $query->where('code', '!=', 'TEST');
  238. // $query->whereIn('semester_id', Session::get('semesters_ids'));
  239. // }))->where('is_graduate', 1)->where('school_id', '!=', $uhs_school_id)->orderBy('name', 'asc')->get() as $program)
  240. // {
  241. // $participating_grad_programs[$program->id]=(object)array('id'=>$program->id, 'name'=>$program->name, 'is_graduate'=> $program->is_graduate, 'school_id'=>$program->school_id,'semestre_id',$selected_semester);
  242. // // SELECT ac.id activity_criterion_id, ac.activity_id, ac.expected_student_score, ac.expected_percentage_students_achieving, co.program_id FROM activity_criterion ac, criteria c, activities a, objectives o, courses co where co.id=a.course_id and co.semester_id=13 and a.id=ac.activity_id and c.id = ac.criterion_id and o.id=c.objective_id and o.outcome_id = 2 order by program_id
  243. // $program_attempted_outcome=$program->attempted_outcome($outcome->id, $selected_semester->id);
  244. // $attempted_outcomes_per_grad_program[$outcome->id]+=$program_attempted_outcome;
  245. // // var_dump($attempted_outcomes_per_undergrad_program);
  246. // // exit();
  247. // if($program_attempted_outcome)
  248. // {
  249. // $attemptedGradProgramsPerOutcome[$outcome->id]+=1;
  250. // $achieved_outcomes_per_grad_program[$outcome->id]=$program->achieved_outcome($outcome->id, $selected_semester->id);
  251. // if($attempted_outcomes_per_grad_program[$outcome->id]!=0 && (float)$achieved_outcomes_per_grad_program[$outcome->id]/$attempted_outcomes_per_grad_program[$outcome->id]*100 >= $outcome->expected_outcome)
  252. // {
  253. // $achievedGradProgramsPerOutcome[$outcome->id]+=1;
  254. // // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedUndergradProgramsPerOutcome);
  255. // }
  256. // }
  257. // }
  258. // }
  259. // var_dump($grad_outcomes_attempted);
  260. // print("<br>");
  261. // var_dump($grad_outcomes_achieved);
  262. // exit();
  263. return View::make('local.managers.admins.overview', compact('title', 'schools', 'outcomes_subgrad', 'outcomes_grad', 'undergrad_outcomes_achieved', 'undergrad_outcomes_attempted', 'grad_outcomes_achieved', 'grad_outcomes_attempted', 'attemptedUndergradProgramsPerOutcome', 'participating_undergrad_programs', 'achievedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'participating_grad_programs', 'achievedGradProgramsPerOutcome'));
  264. }
  265. public function overview2()
  266. {
  267. // '''
  268. //stucture of outcomes array:
  269. //
  270. // $outcome->id
  271. // $outcome->name
  272. // $outcome->semesters
  273. //
  274. // $outcome->semesters[i]->id
  275. // $outcome->semesters[i]->code
  276. // $outcome->semesters[i]->name
  277. // $outcome->semesters[i]->tested
  278. // $outcome->semesters[i]->achievers
  279. // '''
  280. $selected_semesters = Semester::find(Session::get('semesters_ids'));
  281. $title = 'Overview2';
  282. $semesters = DB::table('overview')
  283. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  284. ->select('semesters.name', 'semesters.code')
  285. ->orderBy('semesters.code', 'asc')
  286. ->groupBy('semesters.id')
  287. ->get();
  288. $outcomes = DB::table('overview')
  289. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  290. ->selectRaw('outcomes.name, overview.outcome_id as id, sum(overview.total_evaluated) as total_evaluated, sum(overview.total_achieved) as total_achieved')
  291. ->orderBy('outcomes.name', 'asc')
  292. ->groupBy('overview.outcome_id')
  293. ->get();
  294. foreach ($outcomes as $outcome) {
  295. $outcome->semesters = DB::table('overview')
  296. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  297. ->where('overview.outcome_id', $outcome->id)
  298. ->selectRaw('semesters.id, semesters.name, semesters.code, sum(overview.total_evaluated) as total_evaluated, sum(overview.total_achieved) as total_achieved')
  299. ->orderBy('semesters.code', 'asc')
  300. ->groupBy('overview.outcome_id')
  301. ->groupBy('overview.semester_id')
  302. ->get();
  303. }
  304. $filters = array();
  305. $filters['school'] = DB::table('overview')
  306. ->join('programs', 'programs.id', '=', 'overview.program_id')
  307. ->join('schools', 'schools.id', '=', 'programs.school_id')
  308. ->select('schools.id', 'schools.name')
  309. ->orderBy('schools.name', 'asc')
  310. ->groupBy('schools.id')
  311. ->get();
  312. $filters['program'] = DB::table('overview')
  313. ->join('programs', 'programs.id', '=', 'overview.program_id')
  314. ->select('programs.id', 'programs.name')
  315. ->orderBy('programs.name', 'asc')
  316. ->groupBy('overview.program_id')
  317. ->get();
  318. $filters['semester'] = DB::table('overview')
  319. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  320. ->select('semesters.id', 'semesters.name', 'semesters.code')
  321. ->orderBy('semesters.code', 'asc')
  322. ->groupBy('overview.semester_id')
  323. ->get();
  324. $filters['year'] = DB::table('overview') //
  325. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  326. ->select('semesters.id', 'semesters.start')
  327. ->orderBy('semesters.code', 'asc')
  328. ->groupBy('overview.semester_id')
  329. ->get();
  330. $filters['outcome'] = DB::table('overview')
  331. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  332. ->select('outcomes.id', 'outcomes.name')
  333. ->orderBy('outcomes.name', 'asc')
  334. ->groupBy('overview.outcome_id')
  335. ->get();
  336. $target = 0.70;
  337. return View::make('local.managers.admins.overview2', compact('title', 'selected_semesters', 'outcomes', 'semesters', 'filters', 'target'));
  338. }
  339. // this is called when filters are changed
  340. public function overview2_filter_results()
  341. {
  342. // selected filter data
  343. $schools = Input::get('schools');
  344. $programs = Input::get('programs');
  345. $semesters = Input::get('semesters');
  346. $years = Input::get('years');
  347. $outcomes = Input::get('outcomes');
  348. // make an array id's of schools selected. if All, use All available id's
  349. if ($schools == array("0")) {
  350. $result = DB::table('overview')
  351. ->join('programs', 'programs.id', '=', 'overview.program_id')
  352. ->join('schools', 'schools.id', '=', 'programs.school_id')
  353. ->select('schools.id')
  354. ->orderBy('schools.name', 'asc')
  355. ->groupBy('schools.id')
  356. ->get();
  357. $schools_id = array();
  358. foreach ($result as $school) {
  359. array_push($schools_id, $school->id);
  360. }
  361. } else {
  362. $schools_id = array();
  363. foreach ($schools as $school_id) {
  364. array_push($schools_id, intval($school_id));
  365. }
  366. }
  367. // make an array id's of programs selected. if All, use All available id's
  368. if ($programs == array("0")) {
  369. $result = DB::table('overview')
  370. ->join('programs', 'programs.id', '=', 'overview.program_id')
  371. ->select('programs.id')
  372. ->orderBy('programs.name', 'asc')
  373. ->groupBy('overview.program_id')
  374. ->get();
  375. $programs_id = array();
  376. foreach ($result as $program) {
  377. array_push($programs_id, $program->id);
  378. }
  379. } else {
  380. $programs_id = array();
  381. foreach ($programs as $program_id) {
  382. array_push($programs_id, intval($program_id));
  383. }
  384. }
  385. // make an array id's of semesters selected. if All, use All available id's
  386. if ($semesters == array("0")) {
  387. $result = DB::table('overview')
  388. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  389. ->select('semesters.id')
  390. ->orderBy('semesters.code', 'asc')
  391. ->groupBy('overview.semester_id')
  392. ->get();
  393. $semesters_id = array();
  394. foreach ($result as $semester) {
  395. array_push($semesters_id, $semester->id);
  396. }
  397. } else {
  398. $semesters_id = array();
  399. foreach ($semesters as $semester_id) {
  400. array_push($semesters_id, intval($semester_id));
  401. }
  402. }
  403. // make an array id's of years selected. if All, use All available id's
  404. if ($years == array("0")) {
  405. $result = DB::table('overview') //
  406. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  407. ->select('semesters.id')
  408. ->orderBy('semesters.code', 'asc')
  409. ->groupBy('overview.semester_id')
  410. ->get();
  411. $years_id = array();
  412. foreach ($result as $year) {
  413. array_push($years_id, $year->id);
  414. }
  415. } else {
  416. $years_id = array();
  417. foreach ($years as $year_id) {
  418. array_push($years_id, intval($year_id));
  419. }
  420. }
  421. // make an array id's of outcomes selected. if All, use All available id's
  422. if ($outcomes == array("0")) {
  423. $result = DB::table('overview')
  424. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  425. ->select('outcomes.id')
  426. ->orderBy('outcomes.name', 'asc')
  427. ->groupBy('overview.outcome_id')
  428. ->get();
  429. $outcomes_id = array();
  430. foreach ($result as $outcome) {
  431. array_push($outcomes_id, $outcome->id);
  432. }
  433. } else {
  434. $outcomes_id = array();
  435. foreach ($outcomes as $outcome_id) {
  436. array_push($outcomes_id, intval($outcome_id));
  437. }
  438. }
  439. // get data for graph
  440. $semesters = DB::table('overview')
  441. ->join('programs', 'programs.id', '=', 'overview.program_id')
  442. ->join('schools', 'schools.id', '=', 'programs.school_id')
  443. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  444. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  445. ->whereIn('schools.id', $schools_id)
  446. ->whereIn('programs.id', $programs_id)
  447. ->whereIn('semesters.id', $semesters_id)
  448. // ->whereIn('years.id',$years_id)
  449. ->whereIn('outcomes.id', $outcomes_id)
  450. ->select('semesters.name', 'semesters.code')
  451. ->orderBy('semesters.code', 'asc')
  452. ->groupBy('semesters.id')
  453. ->get();
  454. $outcomes = DB::table('overview')
  455. ->join('programs', 'programs.id', '=', 'overview.program_id')
  456. ->join('schools', 'schools.id', '=', 'programs.school_id')
  457. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  458. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  459. ->whereIn('schools.id', $schools_id)
  460. ->whereIn('programs.id', $programs_id)
  461. ->whereIn('semesters.id', $semesters_id)
  462. // ->whereIn('years.id',$years_id)
  463. ->whereIn('outcomes.id', $outcomes_id)
  464. ->selectRaw('outcomes.name, overview.outcome_id as id, sum(overview.total_evaluated) as total_evaluated, sum(overview.total_achieved) as total_achieved')
  465. ->orderBy('outcomes.name', 'asc')
  466. ->groupBy('overview.outcome_id')
  467. ->get();
  468. foreach ($outcomes as $outcome) {
  469. $outcome->semesters = DB::table('overview')
  470. ->join('programs', 'programs.id', '=', 'overview.program_id')
  471. ->join('schools', 'schools.id', '=', 'programs.school_id')
  472. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  473. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  474. ->whereIn('schools.id', $schools_id)
  475. ->whereIn('programs.id', $programs_id)
  476. ->whereIn('semesters.id', $semesters_id)
  477. // ->whereIn('years.id',$years_id)
  478. ->whereIn('outcomes.id', $outcomes_id)
  479. ->where('overview.outcome_id', $outcome->id)
  480. ->selectRaw('semesters.id, semesters.name, semesters.code, sum(overview.total_evaluated) as total_evaluated, sum(overview.total_achieved) as total_achieved')
  481. ->orderBy('semesters.code', 'asc')
  482. ->groupBy('overview.outcome_id')
  483. ->groupBy('overview.semester_id')
  484. ->get();
  485. }
  486. // get data for filters
  487. $filters = array();
  488. $filters['school'] = DB::table('overview')
  489. ->join('programs', 'programs.id', '=', 'overview.program_id')
  490. ->join('schools', 'schools.id', '=', 'programs.school_id')
  491. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  492. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  493. ->whereIn('schools.id', $schools_id)
  494. ->whereIn('programs.id', $programs_id)
  495. ->whereIn('semesters.id', $semesters_id)
  496. // ->whereIn('years.id',$years_id)
  497. ->whereIn('outcomes.id', $outcomes_id)
  498. ->select('schools.id', 'schools.name')
  499. ->orderBy('schools.name', 'asc')
  500. ->groupBy('schools.id')
  501. ->get();
  502. $filters['program'] = DB::table('overview')
  503. ->join('programs', 'programs.id', '=', 'overview.program_id')
  504. ->join('schools', 'schools.id', '=', 'programs.school_id')
  505. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  506. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  507. ->whereIn('schools.id', $schools_id)
  508. // ->whereIn('programs.id',$programs_id)
  509. ->whereIn('semesters.id', $semesters_id)
  510. // ->whereIn('years.id',$years_id)
  511. ->whereIn('outcomes.id', $outcomes_id)
  512. ->select('programs.id', 'programs.name')
  513. ->orderBy('programs.name', 'asc')
  514. ->groupBy('overview.program_id')
  515. ->get();
  516. $filters['semester'] = DB::table('overview')
  517. ->join('programs', 'programs.id', '=', 'overview.program_id')
  518. ->join('schools', 'schools.id', '=', 'programs.school_id')
  519. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  520. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  521. ->whereIn('schools.id', $schools_id)
  522. ->whereIn('programs.id', $programs_id)
  523. // ->whereIn('semesters.id',$semesters_id)
  524. // ->whereIn('years.id',$years_id)
  525. ->whereIn('outcomes.id', $outcomes_id)
  526. ->select('semesters.id', 'semesters.name', 'semesters.code')
  527. ->orderBy('semesters.code', 'asc')
  528. ->groupBy('overview.semester_id')
  529. ->get();
  530. $filters['year'] = DB::table('overview') ////////////////////////////////////////////
  531. ->join('programs', 'programs.id', '=', 'overview.program_id')
  532. ->join('schools', 'schools.id', '=', 'programs.school_id')
  533. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  534. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  535. ->whereIn('schools.id', $schools_id)
  536. ->whereIn('programs.id', $programs_id)
  537. ->whereIn('semesters.id', $semesters_id)
  538. // ->whereIn('years.id',$years_id)
  539. ->whereIn('outcomes.id', $outcomes_id)
  540. ->get();
  541. $filters['outcome'] = DB::table('overview')
  542. ->join('programs', 'programs.id', '=', 'overview.program_id')
  543. ->join('schools', 'schools.id', '=', 'programs.school_id')
  544. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  545. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  546. ->whereIn('schools.id', $schools_id)
  547. ->whereIn('programs.id', $programs_id)
  548. ->whereIn('semesters.id', $semesters_id)
  549. // ->whereIn('years.id',$years_id)
  550. // ->whereIn('outcomes.id',$outcomes_id)
  551. ->select('outcomes.id', 'outcomes.name')
  552. ->orderBy('outcomes.name', 'asc')
  553. ->groupBy('overview.outcome_id')
  554. ->get();
  555. return array(
  556. "semesters" => $semesters,
  557. "outcomes_info" => $outcomes,
  558. "filters" => $filters,
  559. );
  560. }
  561. }