Нет описания

AdministratorsController.php 34KB

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