Nav apraksta

AdministratorsController.php 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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. $is_graduate=0;
  281. $levels=array(1,3);
  282. $selected_semesters = Semester::find(Session::get('semesters_ids'));
  283. $title = 'Overview';
  284. $semesters = DB::table('overview')
  285. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  286. ->select('semesters.id', 'semesters.name', 'semesters.code')
  287. ->orderBy('semesters.code', 'asc')
  288. ->groupBy('semesters.id')
  289. ->get();
  290. $outcomes = DB::table('overview')
  291. ->rightJoin('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  292. ->whereIn('outcomes.level',$levels)
  293. ->selectRaw('outcomes.name, coalesce(outcomes.new_outcome_id,outcomes.id) as id, sum(overview.total_evaluated) as total_evaluated, sum(overview.total_achieved) as total_achieved')
  294. ->orderBy('outcomes.name', 'asc')
  295. ->groupBy(DB::raw('coalesce(outcomes.new_outcome_id,outcomes.id)'))
  296. ->get();
  297. //outcomes activos
  298. // $outcomes = DB::table('outcomes')
  299. // ->whereNull('deactivation_date')
  300. //
  301. // ->get();
  302. // DB::enableQueryLog();
  303. foreach ($outcomes as $outcome) {
  304. // select semester_id, program_id, sum(`total_evaluated`) eval, sum(`total_achieved`) ach from overview where outcome_id in (select id from outcomes where coalesce(`new_outcome_id`,id) = 12) group by semester_id, program_id
  305. $outcome->semesters = DB::table('overview')
  306. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  307. ->whereIn('overview.outcome_id',function ($query) use ($outcome)
  308. {
  309. $query->select('outcomes.id')
  310. ->from('outcomes')
  311. ->whereRaw('coalesce(outcomes.new_outcome_id,outcomes.id)=?',[$outcome->id]);
  312. })
  313. ->selectRaw('semesters.id, semesters.name, semesters.code, sum(overview.total_evaluated) as total_evaluated, sum(overview.total_achieved) as total_achieved')
  314. ->orderBy('semesters.code', 'asc')
  315. ->groupBy('overview.semester_id')
  316. ->get();
  317. }
  318. // var_dump($outcomes);
  319. // exit();
  320. // dd(DB::getQueryLog());
  321. $filters = array();
  322. $filters['school'] = DB::table('overview')
  323. ->join('programs', 'programs.id', '=', 'overview.program_id')
  324. ->join('schools', 'schools.id', '=', 'programs.school_id')
  325. ->where('programs.is_graduate',$is_graduate)
  326. ->select('schools.id', 'schools.name')
  327. ->orderBy('schools.name', 'asc')
  328. ->groupBy('schools.id')
  329. ->get();
  330. // DB::enableQueryLog();
  331. $filters['program'] = DB::table('overview')
  332. ->join('programs', 'programs.id', '=', 'overview.program_id')
  333. ->where('programs.is_graduate',$is_graduate)
  334. ->select('programs.id', 'programs.name')
  335. ->orderBy('programs.name', 'asc')
  336. ->groupBy('overview.program_id')
  337. ->get();
  338. // dd(DB::getQueryLog());
  339. $filters['semester'] = DB::table('overview')
  340. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  341. ->select('semesters.id', 'semesters.name', 'semesters.code')
  342. ->orderBy('semesters.code', 'asc')
  343. ->groupBy('overview.semester_id')
  344. ->get();
  345. $filters['year'] = DB::table('overview') //
  346. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  347. ->select('semesters.id', 'semesters.start')
  348. ->orderBy('semesters.code', 'asc')
  349. ->groupBy('overview.semester_id')
  350. ->get();
  351. // DB::enableQueryLog();
  352. //select `outcomes`.`id`, `outcomes`.`name` from outcomes where deactivation_date is null and `outcomes`.`id` in (select outcome_id from overview)
  353. $filters['outcome'] = DB::table('outcomes')
  354. ->select('outcomes.id', 'outcomes.name')
  355. ->whereNull('deactivation_date')
  356. ->whereIn('outcomes.id',function($query)
  357. {
  358. $query->select('outcome_id')
  359. ->from('overview');
  360. }
  361. )
  362. ->orderBy('outcomes.name', 'asc')
  363. ->get();
  364. // dd(DB::getQueryLog());
  365. // exit();
  366. $target = 0.70;
  367. return View::make('local.managers.admins.overview2', compact('title', 'selected_semesters', 'outcomes', 'semesters', 'filters', 'target'));
  368. }
  369. // this is called when filters are changed
  370. public function overview2_filter_results()
  371. {
  372. // selected filter data
  373. $schools = Input::get('schools');
  374. $programs = Input::get('programs');
  375. $semesters = Input::get('semesters');
  376. $years = Input::get('years');
  377. $outcomes = Input::get('outcomes');
  378. $is_graduate=Input::get('is_graduate');
  379. // $is_graduate=0;
  380. if($is_graduate)$levels=array(2,3);
  381. else $levels=array(1,3);
  382. // make an array id's of schools selected. if All, use All available id's
  383. if ($schools == array("0")) {
  384. $result = DB::table('overview')
  385. ->join('programs', 'programs.id', '=', 'overview.program_id')
  386. ->join('schools', 'schools.id', '=', 'programs.school_id')
  387. ->where('programs.is_graduate',$is_graduate)
  388. ->select('schools.id')
  389. ->orderBy('schools.name', 'asc')
  390. ->groupBy('schools.id')
  391. ->get();
  392. $schools_id = array();
  393. foreach ($result as $school) {
  394. array_push($schools_id, $school->id);
  395. }
  396. } else {
  397. $schools_id = array();
  398. foreach ($schools as $school_id) {
  399. array_push($schools_id, intval($school_id));
  400. }
  401. }
  402. // make an array id's of programs selected. if All, use All available id's
  403. if ($programs == array("0")) {
  404. $result = DB::table('overview')
  405. ->join('programs', 'programs.id', '=', 'overview.program_id')
  406. ->where('programs.is_graduate',$is_graduate)
  407. ->select('programs.id')
  408. ->orderBy('programs.name', 'asc')
  409. ->groupBy('overview.program_id')
  410. ->get();
  411. $programs_id = array();
  412. foreach ($result as $program) {
  413. array_push($programs_id, $program->id);
  414. }
  415. } else {
  416. $programs_id = array();
  417. foreach ($programs as $program_id) {
  418. array_push($programs_id, intval($program_id));
  419. }
  420. }
  421. // make an array id's of semesters selected. if All, use All available id's
  422. if ($semesters == array("0")) {
  423. $result = DB::table('overview')
  424. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  425. ->select('semesters.id')
  426. ->orderBy('semesters.code', 'asc')
  427. ->groupBy('overview.semester_id')
  428. ->get();
  429. $semesters_id = array();
  430. foreach ($result as $semester) {
  431. array_push($semesters_id, $semester->id);
  432. }
  433. } else {
  434. $semesters_id = array();
  435. foreach ($semesters as $semester_id) {
  436. array_push($semesters_id, intval($semester_id));
  437. }
  438. }
  439. // make an array id's of years selected. if All, use All available id's
  440. // if ($years == array("0")) {
  441. // $result = DB::table('overview') //
  442. // ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  443. // ->select('semesters.id')
  444. // ->orderBy('semesters.code', 'asc')
  445. // ->groupBy('overview.semester_id')
  446. // ->get();
  447. // $years_id = array();
  448. // foreach ($result as $year) {
  449. // array_push($years_id, $year->id);
  450. // }
  451. // } else {
  452. // $years_id = array();
  453. // foreach ($years as $year_id) {
  454. // array_push($years_id, intval($year_id));
  455. // }
  456. // }
  457. // make an array id's of outcomes selected. if All, use All available id's
  458. if ($outcomes == array("0")) {
  459. $result = DB::table('overview')
  460. ->rightJoin('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  461. ->whereIn('outcomes.level',$levels)
  462. ->selectRaw('coalesce(outcomes.new_outcome_id,outcomes.id) as id')
  463. ->orderBy('outcomes.name', 'asc')
  464. ->groupBy(DB::raw('coalesce(outcomes.new_outcome_id,outcomes.id)'))
  465. ->get();
  466. // $result = DB::table('outcomes')
  467. // ->select('outcomes.id')
  468. // ->whereIn('outcomes.level',$levels)
  469. // ->whereNull('deactivation_date')
  470. // // ->whereIn('outcomes.id',function($query)
  471. // // {
  472. // // $query->select('outcome_id')
  473. // // ->from('overview');
  474. // // }
  475. // // )
  476. // ->orderBy('outcomes.name', 'asc')
  477. // ->get();
  478. //
  479. // $result = DB::table('overview')
  480. // ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  481. // ->select('outcomes.id')
  482. // ->orderBy('outcomes.name', 'asc')
  483. // ->groupBy('overview.outcome_id')
  484. // ->get();
  485. $outcomes_id = array();
  486. foreach ($result as $outcome) {
  487. array_push($outcomes_id, $outcome->id);
  488. }
  489. } else {
  490. $outcomes_id = array();
  491. foreach ($outcomes as $outcome_id) {
  492. array_push($outcomes_id, intval($outcome_id));
  493. }
  494. }
  495. // get data for graph
  496. $semesters = DB::table('overview')
  497. ->join('programs', 'programs.id', '=', 'overview.program_id')
  498. ->join('schools', 'schools.id', '=', 'programs.school_id')
  499. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  500. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  501. // ->where('programs.is_graduate',$is_graduate)
  502. ->whereIn('schools.id', $schools_id)
  503. ->whereIn('programs.id', $programs_id)
  504. ->whereIn('semesters.id', $semesters_id)
  505. // ->whereIn('years.id',$years_id)
  506. ->whereIn('outcomes.id', $outcomes_id)
  507. ->select('semesters.name', 'semesters.code')
  508. ->orderBy('semesters.code', 'asc')
  509. ->groupBy('semesters.id')
  510. ->get();
  511. // $outcomes = DB::table('overview')
  512. // ->rightJoin('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  513. // ->join('programs', 'programs.id', '=', 'overview.program_id')
  514. // ->join('schools', 'schools.id', '=', 'programs.school_id')
  515. // ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  516. // ->whereIn('schools.id', $schools_id)
  517. // ->whereIn('programs.id', $programs_id)
  518. // ->whereIn('semesters.id', $semesters_id)
  519. // ->whereIn('outcomes.id', $outcomes_id)
  520. // ->selectRaw('outcomes.name, coalesce(outcomes.new_outcome_id,outcomes.id) as id, sum(overview.total_evaluated) as total_evaluated, sum(overview.total_achieved) as total_achieved')
  521. // ->orderBy('outcomes.name', 'asc')
  522. // ->groupBy(DB::raw('coalesce(outcomes.new_outcome_id,outcomes.id)'))
  523. // ->get();
  524. // $sql=DB::table('overview')
  525. // ->join('programs', 'programs.id', '=', 'overview.program_id')
  526. // ->join('schools', 'schools.id', '=', 'programs.school_id')
  527. // ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  528. // ->select('overview.id','program_id','outcome_id','semester_id','total_evaluated','total_achieved')
  529. // ->whereIn('schools.id', $schools_id)
  530. // ->whereIn('programs.id', $programs_id)
  531. // ->whereIn('semesters.id', $semesters_id);
  532. $schools_text=implode(",", $schools_id);
  533. $programs_text=implode(",", $programs_id);
  534. $semesters_text=implode(",", $semesters_id);
  535. $sql="select overview.* from `overview` inner join `programs` on `programs`.`id` = `overview`.`program_id` inner join `schools` on `schools`.`id` = `programs`.`school_id` inner join `semesters` on `semesters`.`id` = `overview`.`semester_id` where `schools`.`id` in ($schools_text) and `programs`.`id` in ($programs_text) and `semesters`.`id` in ($semesters_text)";
  536. $outcomes = DB::table('outcomes')
  537. ->leftJoin(DB::raw("({$sql}) as overview2"),'outcomes.id', '=', 'overview2.outcome_id')
  538. ->whereIn('outcomes.id', $outcomes_id)
  539. ->selectRaw('outcomes.name, coalesce(outcomes.new_outcome_id,outcomes.id) as id, sum(overview2.total_evaluated) as total_evaluated, sum(overview2.total_achieved) as total_achieved')
  540. ->orderBy('outcomes.name', 'asc')
  541. ->groupBy(DB::raw('coalesce(outcomes.new_outcome_id,outcomes.id)'))
  542. // ->mergeBindings($sql->getQuery())
  543. ->get();
  544. foreach ($outcomes as $outcome) {
  545. // $outcome->semesters = DB::table('overview')
  546. // ->join('programs', 'programs.id', '=', 'overview.program_id')
  547. // ->join('schools', 'schools.id', '=', 'programs.school_id')
  548. // ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  549. // ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  550. // ->whereIn('schools.id', $schools_id)
  551. // ->whereIn('programs.id', $programs_id)
  552. // ->whereIn('semesters.id', $semesters_id)
  553. // // ->whereIn('years.id',$years_id)
  554. // ->whereIn('outcomes.id', $outcomes_id)
  555. // ->where('overview.outcome_id', $outcome->id)
  556. // ->selectRaw('semesters.id, semesters.name, semesters.code, sum(overview.total_evaluated) as total_evaluated, sum(overview.total_achieved) as total_achieved')
  557. // ->orderBy('semesters.code', 'asc')
  558. // ->groupBy('overview.outcome_id')
  559. // ->groupBy('overview.semester_id')
  560. // ->get();
  561. $outcome->semesters = DB::table('overview')
  562. ->join('programs', 'programs.id', '=', 'overview.program_id')
  563. ->join('schools', 'schools.id', '=', 'programs.school_id')
  564. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  565. ->whereIn('schools.id', $schools_id)
  566. ->whereIn('programs.id', $programs_id)
  567. ->whereIn('semesters.id', $semesters_id)
  568. ->whereIn('overview.outcome_id',function ($query) use ($outcome)
  569. {
  570. $query->select('outcomes.id')
  571. ->from('outcomes')
  572. ->whereRaw('coalesce(outcomes.new_outcome_id,outcomes.id)=?',[$outcome->id]);
  573. })
  574. ->selectRaw('semesters.id, semesters.name, semesters.code, sum(overview.total_evaluated) as total_evaluated, sum(overview.total_achieved) as total_achieved')
  575. ->orderBy('semesters.code', 'asc')
  576. ->groupBy('overview.semester_id')
  577. ->get();
  578. }
  579. // get data for filters
  580. $filters = array();
  581. $filters['school'] = DB::table('overview')
  582. ->join('programs', 'programs.id', '=', 'overview.program_id')
  583. ->join('schools', 'schools.id', '=', 'programs.school_id')
  584. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  585. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  586. ->whereIn('schools.id', $schools_id)
  587. ->whereIn('programs.id', $programs_id)
  588. ->whereIn('semesters.id', $semesters_id)
  589. // ->whereIn('years.id',$years_id)
  590. ->whereIn('outcomes.id', $outcomes_id)
  591. ->where('programs.is_graduate',$is_graduate)
  592. ->select('schools.id', 'schools.name')
  593. ->orderBy('schools.name', 'asc')
  594. ->groupBy('schools.id')
  595. ->get();
  596. $filters['program'] = DB::table('overview')
  597. ->join('programs', 'programs.id', '=', 'overview.program_id')
  598. ->join('schools', 'schools.id', '=', 'programs.school_id')
  599. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  600. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  601. ->whereIn('schools.id', $schools_id)
  602. // ->whereIn('programs.id',$programs_id)
  603. ->whereIn('semesters.id', $semesters_id)
  604. // ->whereIn('years.id',$years_id)
  605. ->whereIn('outcomes.id', $outcomes_id)
  606. ->where('programs.is_graduate',$is_graduate)
  607. ->select('programs.id', 'programs.name')
  608. ->orderBy('programs.name', 'asc')
  609. ->groupBy('overview.program_id')
  610. ->get();
  611. $filters['semester'] = DB::table('overview')
  612. ->join('programs', 'programs.id', '=', 'overview.program_id')
  613. ->join('schools', 'schools.id', '=', 'programs.school_id')
  614. ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  615. ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  616. ->whereIn('schools.id', $schools_id)
  617. ->whereIn('programs.id', $programs_id)
  618. // ->whereIn('semesters.id',$semesters_id)
  619. // ->whereIn('years.id',$years_id)
  620. ->whereIn('outcomes.id', $outcomes_id)
  621. ->where('programs.is_graduate',$is_graduate)
  622. ->select('semesters.id', 'semesters.name', 'semesters.code')
  623. ->orderBy('semesters.code', 'asc')
  624. ->groupBy('overview.semester_id')
  625. ->get();
  626. // $filters['year'] = DB::table('overview') ////////////////////////////////////////////
  627. // ->join('programs', 'programs.id', '=', 'overview.program_id')
  628. // ->join('schools', 'schools.id', '=', 'programs.school_id')
  629. // ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  630. // ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  631. // ->whereIn('schools.id', $schools_id)
  632. // ->whereIn('programs.id', $programs_id)
  633. // ->whereIn('semesters.id', $semesters_id)
  634. // // ->whereIn('years.id',$years_id)
  635. // ->whereIn('outcomes.id', $outcomes_id)
  636. //
  637. // ->get();
  638. $sql="select overview.* from `overview` inner join `programs` on `programs`.`id` = `overview`.`program_id` inner join `schools` on `schools`.`id` = `programs`.`school_id` inner join `semesters` on `semesters`.`id` = `overview`.`semester_id` where `schools`.`id` in ($schools_text) and `programs`.`id` in ($programs_text) and `semesters`.`id` in ($semesters_text) and programs.is_graduate=$is_graduate";
  639. $filters['outcome'] = DB::table('outcomes')
  640. ->leftJoin(DB::raw("({$sql}) as overview2"),'outcomes.id', '=', 'overview2.outcome_id')
  641. ->select('outcomes.id', 'outcomes.name')
  642. ->orderBy('outcomes.name', 'asc')
  643. ->groupBy(DB::raw('coalesce(outcomes.new_outcome_id,outcomes.id)'))
  644. // ->mergeBindings($sql->getQuery())
  645. ->get();
  646. // $filters['outcome'] = DB::table('overview')
  647. // ->join('programs', 'programs.id', '=', 'overview.program_id')
  648. // ->join('schools', 'schools.id', '=', 'programs.school_id')
  649. // ->join('semesters', 'semesters.id', '=', 'overview.semester_id')
  650. // ->join('outcomes', 'outcomes.id', '=', 'overview.outcome_id')
  651. // ->whereIn('schools.id', $schools_id)
  652. // ->whereIn('programs.id', $programs_id)
  653. // ->whereIn('semesters.id', $semesters_id)
  654. // // ->whereIn('years.id',$years_id)
  655. // // ->whereIn('outcomes.id',$outcomes_id)
  656. // ->where('programs.is_graduate',$is_graduate)
  657. // ->select('outcomes.id', 'outcomes.name')
  658. // ->orderBy('outcomes.name', 'asc')
  659. // ->groupBy('overview.outcome_id')
  660. // ->get();
  661. return array(
  662. "semesters" => $semesters,
  663. "outcomes_info" => $outcomes,
  664. "filters" => $filters,
  665. );
  666. }
  667. }