Brak opisu

SchoolCoordinatorsController.php 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. class SchoolCoordinatorsController extends \BaseController
  3. {
  4. private function participatingPrograms($school)
  5. {
  6. return DB::table('VIEW_participating_programs')
  7. ->where('school_id', $school->id)
  8. ->whereIn('semester_id', Session::get('semesters_ids'))
  9. ->lists('id');
  10. }
  11. public function overview()
  12. {
  13. DB::disableQueryLog();
  14. Log::debug('user' . Auth::user()->id);
  15. //TODO Find a better way to prevent non-scoords from reaching the page
  16. switch (Auth::user()->role) {
  17. case 1:
  18. return Redirect::to('administrator');
  19. break;
  20. case 3:
  21. return Redirect::to('program-coordinator');
  22. break;
  23. }
  24. $schools = School::orderBy('name', 'asc')->get();
  25. $school = Auth::user()->school;
  26. $title = $school->name . ' ' . 'Overview';
  27. $id = $school->id;
  28. $outcomes = Outcome::orderBy('name', 'asc')->get();
  29. $outcomeCount = Outcome::all()->count();
  30. /**
  31. * List of grouped courses (grouped sections)
  32. */
  33. $program_ids = $school->programs->lists('id');
  34. $undergrad_programs = DB::table('programs')
  35. ->select('id', 'name', 'school_id', 'is_graduate')
  36. ->where('is_graduate', '=', 0)
  37. ->where('school_id', '=', $id)
  38. ->orderBy('name', 'ASC')
  39. ->get();
  40. $grad_programs = DB::table('programs')
  41. ->select('id', 'name', 'school_id', 'is_graduate')
  42. ->where('is_graduate', '=', 1)
  43. ->where('school_id', '=', $id)
  44. ->orderBy('name', 'ASC')
  45. ->get();
  46. /*$grad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  47. ->with('semester')
  48. ->with('program')
  49. ->whereIn('courses.program_id', $program_ids)
  50. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  51. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  52. ->where('programs.is_graduate', '=', 1)
  53. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  54. ->orderBy('courses.code')
  55. ->orderBy('courses.number')
  56. ->orderBy('courses.semester_id')
  57. ->get();*/
  58. $grad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  59. ->with('semester')
  60. ->with('program')
  61. ->whereIn('courses.program_id', $program_ids)
  62. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  63. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  64. ->where('programs.is_graduate', '=', 1)
  65. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  66. ->orderBy('courses.code')
  67. ->orderBy('courses.number')
  68. ->orderBy('courses.semester_id')
  69. ->get();
  70. /*$undergrad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  71. ->with('semester')
  72. ->with('program')
  73. ->whereIn('courses.program_id', $program_ids)
  74. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  75. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  76. ->where('programs.is_graduate', '=', 0)
  77. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  78. ->orderBy('courses.code')
  79. ->orderBy('courses.number')
  80. ->orderBy('courses.semester_id')
  81. ->get();*/
  82. $undergrad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  83. ->with('semester')
  84. ->with('program')
  85. ->whereIn('courses.program_id', $program_ids)
  86. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  87. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  88. ->where('programs.is_graduate', '=', 0)
  89. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  90. ->orderBy('courses.code')
  91. ->orderBy('courses.number')
  92. ->orderBy('courses.semester_id')
  93. ->get();
  94. // Fetch programs with participation
  95. $participating_programs = $this->participatingPrograms($school);
  96. /**
  97. * Calculate how many sections are doing assessment
  98. */
  99. $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  100. $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  101. $undergrad_assessed_sections_count = 0;
  102. $undergrad_school_sections_count = 0;
  103. $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  104. $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  105. $grad_assessed_sections_count = 0;
  106. $grad_school_sections_count = 0;
  107. /*
  108. foreach ($school->programs as $program) {
  109. foreach ($program->courses as $course) {
  110. if (!$course->program->is_graduate) {
  111. if ($course->outcomes_achieved != NULL) {
  112. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  113. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  114. for ($i = 1; $i <= count($undergrad_outcomes_attempted); $i++) {
  115. $undergrad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  116. $undergrad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  117. }
  118. $undergrad_assessed_sections_count += 1;
  119. }
  120. $undergrad_school_sections_count += 1;
  121. } else {
  122. if ($course->outcomes_achieved != NULL) {
  123. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  124. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  125. for ($i = 1; $i <= count($grad_outcomes_attempted); $i++) {
  126. $grad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  127. $grad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  128. }
  129. $grad_assessed_sections_count += 1;
  130. }
  131. $grad_school_sections_count += 1;
  132. }
  133. }
  134. }
  135. */
  136. foreach ($school->programs as $program) {
  137. foreach ($program->courses as $course) {
  138. if (!$course->program->is_graduate) {
  139. if ($course->outcomes_achieved != NULL) {
  140. $course_outcomes_achieved = $course->outcomes_ach();
  141. $course_outcomes_attempted = $course->outcomes_att();
  142. foreach ($course_outcomes_attempted as $i => $score) {
  143. $undergrad_outcomes_attempted[$i] += $score;
  144. }
  145. foreach ($course_outcomes_achieved as $i => $score) {
  146. $undergrad_outcomes_achieved[$i] += $score;
  147. }
  148. $undergrad_assessed_sections_count += 1;
  149. }
  150. $undergrad_school_sections_count += 1;
  151. } else {
  152. if ($course->outcomes_achieved != NULL) {
  153. $course_outcomes_achieved = $course->outcomes_ach();
  154. $course_outcomes_attempted = $course->outcomes_att();
  155. foreach ($course_outcomes_attempted as $i => $score) {
  156. $grad_outcomes_attempted[$i] += $score;
  157. }
  158. foreach ($course_outcomes_achieved as $i => $score) {
  159. $grad_outcomes_achieved[$i] += $score;
  160. }
  161. $grad_assessed_sections_count += 1;
  162. }
  163. $grad_school_sections_count += 1;
  164. }
  165. }
  166. }
  167. /**
  168. * Calculate how many programs achieved and attempted each outcome in this school
  169. */
  170. // Number of programs that achieved a particular learning outcome
  171. $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  172. // Number of programs that attempted a particular learning outcome
  173. $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  174. // Fetch programs with participation for the school
  175. $participating_undergrad_programs = DB::table('VIEW_participating_programs')
  176. ->whereIn('semester_id', Session::get('semesters_ids'))
  177. ->where('is_graduate', 0)
  178. ->where('school_id', $school->id)
  179. ->groupBy('id')
  180. ->get();
  181. $output = array();
  182. // For each outcome
  183. foreach ($outcomes as $outcome) {
  184. // For each program with courses that do assessment
  185. $programs_with_courses = Program::with(array('courses' => function ($query) {
  186. // $query->whereNotNull('outcomes_attempted');
  187. $query->whereIn('semester_id', Session::get('semesters_ids'));
  188. $query->join('activities', 'activities.course_id', '=', 'courses.id')
  189. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  190. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  191. ->where('activities.draft', 0)
  192. ->select('courses.*')->distinct();
  193. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  194. foreach ($programs_with_courses as $program) {
  195. // To acummulate all criteria for one program
  196. $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  197. $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  198. //Flag for counting programs
  199. $flag = false;
  200. // For each course in the program
  201. foreach ($program->courses as $course) {
  202. // If the outcome in question is being evaluated
  203. $course_outcomes_attempted2 = $course->outcomes_att(); //json_decode($course->outcomes_attempted, true);
  204. $course_outcomes_achieved2 = $course->outcomes_ach(); //json_decode($course->outcomes_achieved, true);
  205. if (
  206. array_key_exists($outcome->id, $course_outcomes_attempted2)
  207. && $course_outcomes_attempted2[$outcome->id] > 0
  208. ) {
  209. $achieved_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  210. $attempted_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  211. // Add one to the programs assessing, if it wasn't added before
  212. if (!$flag) {
  213. $attemptedUndergradProgramsPerOutcome[$outcome->id] += 1;
  214. $flag = true;
  215. }
  216. }
  217. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  218. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  219. }
  220. //If the accumulated achieved criteria for a specific outcome in a program divided by the accumulated attempted criteria for a specific outcome in a program is greated than the expected outcome
  221. if ($attempted_outcomes_per_undergrad_program[$outcome->id] != 0 && (float)$achieved_outcomes_per_undergrad_program[$outcome->id] / $attempted_outcomes_per_undergrad_program[$outcome->id] * 100 >= $outcome->expected_outcome) {
  222. $achievedUndergradProgramsPerOutcome[$outcome->id] += 1;
  223. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  224. }
  225. }
  226. }
  227. /**
  228. * Calculate how many programs achieved and attempted each outcome in this school
  229. */
  230. // Number of programs that achieved a particular learning outcome
  231. $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  232. // Number of programs that attempted a particular learning outcome
  233. $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  234. // Fetch programs with participation for the school
  235. $participating_grad_programs = DB::table('VIEW_participating_programs')
  236. ->whereIn('semester_id', Session::get('semesters_ids'))
  237. ->where('is_graduate', 1)
  238. ->where('school_id', $school->id)
  239. ->groupBy('id')
  240. ->get();
  241. $output = array();
  242. // For each outcome
  243. foreach ($outcomes as $outcome) {
  244. // For each program with courses that do assessment
  245. $programs_with_courses = Program::with(array('courses' => function ($query) {
  246. //$query->whereNotNull('outcomes_attempted');
  247. $query->whereIn('semester_id', Session::get('semesters_ids'));
  248. $query->join('activities', 'activities.course_id', '=', 'courses.id')
  249. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  250. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  251. ->where('activities.draft', 0)
  252. ->select('courses.*')->distinct();
  253. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  254. foreach ($programs_with_courses as $program) {
  255. // To acummulate all criteria for one program
  256. $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  257. $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  258. //Flag for counting programs
  259. $flag = false;
  260. // For each course in the program
  261. foreach ($program->courses as $course) {
  262. // If the outcome in question is being evaluated
  263. $course_outcomes_attempted2 = $course->outcomes_att(); // json_decode($course->outcomes_attempted, true);
  264. $course_outcomes_achieved2 = $course->outcomes_ach(); //json_decode($course->outcomes_achieved, true);
  265. if (
  266. array_key_exists($outcome->id, $course_outcomes_attempted2)
  267. && $course_outcomes_attempted2[$outcome->id] > 0
  268. ) {
  269. $achieved_outcomes_per_grad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  270. $attempted_outcomes_per_grad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  271. // Add one to the programs assessing, if it wasn't added before
  272. if (!$flag) {
  273. $attemptedGradProgramsPerOutcome[$outcome->id] += 1;
  274. $flag = true;
  275. }
  276. }
  277. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_program);
  278. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  279. }
  280. //If the accumulated achieved criteria for a specific outcome in a program divided by the accumulated attempted criteria for a specific outcome in a program is greated than the expected outcome
  281. 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) {
  282. $achievedGradProgramsPerOutcome[$outcome->id] += 1;
  283. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  284. }
  285. }
  286. }
  287. return View::make('local.managers.shared.school', compact('title', 'outcomes', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs', 'participating_undergrad_programs', 'participating_grad_programs'));
  288. }
  289. }