説明なし

SchoolCoordinatorsController.php 18KB

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