Sin descripción

AdministratorsController.php 29KB

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