暂无描述

SchoolsController.php 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?php
  2. class SchoolsController 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 show($id)
  15. {
  16. ini_set('memory_limit', '256M');
  17. DB::connection()->disableQueryLog();
  18. $school = School::find($id);
  19. $title = $school->name;
  20. $schools = School::all();
  21. $outcomes = Outcome::orderBy('name', 'asc')->get();
  22. $outcomeCount = Outcome::all()->count();
  23. /**
  24. * List of grouped courses (grouped sections)
  25. */
  26. $program_ids = $school->programs->lists('id');
  27. $undergrad_programs = DB::table('programs')
  28. ->select('id', 'name', 'school_id', 'is_graduate')
  29. ->where('is_graduate', '=', 0)
  30. ->where('school_id', '=', $id)
  31. ->orderBy('name', 'ASC')
  32. ->get();
  33. $grad_programs = DB::table('programs')
  34. ->select('id', 'name', 'school_id', 'is_graduate')
  35. ->where('is_graduate', '=', 1)
  36. ->where('school_id', '=', $id)
  37. ->orderBy('name', 'ASC')
  38. ->get();
  39. $grad_grouped_courses = Course::
  40. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  41. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  42. ->with('semester')
  43. ->with('program')
  44. ->whereIn('courses.program_id', $program_ids)
  45. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  46. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  47. ->where('programs.is_graduate', '=', 1)
  48. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  49. ->orderBy('courses.code')
  50. ->orderBy('courses.number')
  51. ->orderBy('courses.semester_id')
  52. ->get();
  53. $undergrad_grouped_courses = Course::
  54. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  55. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  56. ->with('semester')
  57. ->with('program')
  58. ->whereIn('courses.program_id', $program_ids)
  59. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  60. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  61. ->where('programs.is_graduate', '=', 0)
  62. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  63. ->orderBy('courses.code')
  64. ->orderBy('courses.number')
  65. ->orderBy('courses.semester_id')
  66. ->get();
  67. // Fetch programs with participation
  68. $participating_programs = $this->participatingPrograms($school);
  69. /**
  70. * Calculate how many sections are doing assessment
  71. */
  72. $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  73. $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  74. $undergrad_assessed_sections_count = 0;
  75. $undergrad_school_sections_count = 0;
  76. $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  77. $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  78. $grad_assessed_sections_count = 0;
  79. $grad_school_sections_count = 0;
  80. foreach ($school->programs as $program) {
  81. foreach ($program->courses as $course) {
  82. if (!$course->program->is_graduate) {
  83. if ($course->outcomes_achieved != NULL) {
  84. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  85. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  86. for ($i = 1; $i <= count($undergrad_outcomes_attempted); $i++) {
  87. $undergrad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  88. $undergrad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  89. }
  90. $undergrad_assessed_sections_count += 1;
  91. }
  92. $undergrad_school_sections_count += 1;
  93. } else {
  94. if ($course->outcomes_achieved != NULL) {
  95. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  96. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  97. for ($i = 1; $i <= count($grad_outcomes_attempted); $i++) {
  98. $grad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  99. $grad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  100. }
  101. $grad_assessed_sections_count += 1;
  102. }
  103. $grad_school_sections_count += 1;
  104. }
  105. }
  106. }
  107. /**
  108. * Calculate how many programs achieved and attempted each outcome in this school
  109. */
  110. // Number of programs that achieved a particular learning outcome
  111. $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  112. // Number of programs that attempted a particular learning outcome
  113. $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  114. // Fetch programs with participation for the school
  115. $participating_undergrad_programs = DB::table('programs')
  116. ->join('courses', 'courses.program_id', '=', 'programs.id')
  117. ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  118. ->addSelect('courses.semester_id')
  119. ->whereIn('semester_id', Session::get('semesters_ids'))
  120. ->where('is_graduate', 0)
  121. ->where('school_id', $school->id)
  122. ->groupBy('id')
  123. ->get();
  124. $output = array();
  125. // For each outcome
  126. foreach ($outcomes as $outcome) {
  127. // For each program with courses that do assessment
  128. $programs_with_courses = Program::with(array('courses' => function ($query) {
  129. // $query->whereNotNull('outcomes_attempted');
  130. $query->whereIn('semester_id', Session::get('semesters_ids'));
  131. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  132. foreach ($programs_with_courses as $program) {
  133. // To acummulate all criteria for one program
  134. $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  135. $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  136. //Flag for counting programs
  137. $flag = false;
  138. // For each course in the program
  139. foreach ($program->courses as $course) {
  140. // If the outcome in question is being evaluated
  141. $course_outcomes_attempted2 = $course->outcomes_att();
  142. // $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  143. // $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  144. $course_outcomes_achieved2 = $course->outcomes_ach();
  145. if (
  146. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  147. && $course_outcomes_attempted2[$outcome->id] > 0
  148. ) {
  149. $achieved_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  150. $attempted_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  151. // Add one to the programs assessing, if it wasn't added before
  152. if (!$flag) {
  153. $attemptedUndergradProgramsPerOutcome[$outcome->id] += 1;
  154. $flag = true;
  155. }
  156. }
  157. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  158. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  159. }
  160. //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
  161. 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) {
  162. $achievedUndergradProgramsPerOutcome[$outcome->id] += 1;
  163. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  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. $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  172. // Number of programs that attempted a particular learning outcome
  173. $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  174. // Fetch programs with participation for the school
  175. $participating_grad_programs = DB::table('programs')
  176. ->join('courses', 'courses.program_id', '=', 'programs.id')
  177. ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  178. ->addSelect('courses.semester_id')
  179. ->whereIn('semester_id', Session::get('semesters_ids'))
  180. ->where('is_graduate', 1)
  181. ->where('school_id', $school->id)
  182. ->groupBy('id')
  183. ->get();
  184. $output = array();
  185. // For each outcome
  186. foreach ($outcomes as $outcome) {
  187. // For each program with courses that do assessment
  188. $programs_with_courses = Program::with(array('courses' => function ($query) {
  189. // $query->whereNotNull('outcomes_attempted');
  190. $query->whereIn('semester_id', Session::get('semesters_ids'));
  191. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  192. foreach ($programs_with_courses as $program) {
  193. // To acummulate all criteria for one program
  194. $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  195. $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  196. //Flag for counting programs
  197. $flag = false;
  198. // For each course in the program
  199. foreach ($program->courses as $course) {
  200. // If the outcome in question is being evaluated
  201. // $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  202. $course_outcomes_attempted2 = ($course->outcomes_att());
  203. $course_outcomes_achieved2 = ($course->outcomes_ach());
  204. // $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  205. if (
  206. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  207. && $course_outcomes_attempted2[$outcome->id] > 0
  208. ) {
  209. $achieved_outcomes_per_grad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  210. $attempted_outcomes_per_grad_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. $attemptedGradProgramsPerOutcome[$outcome->id] += 1;
  214. $flag = true;
  215. }
  216. }
  217. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_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_grad_program[$outcome->id] != 0 && (float)$achieved_outcomes_per_grad_program[$outcome->id] / $attempted_outcomes_per_grad_program[$outcome->id] * 100 >= $outcome->expected_outcome) {
  222. $achievedGradProgramsPerOutcome[$outcome->id] += 1;
  223. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  224. }
  225. }
  226. }
  227. if ($school->id == 13) {
  228. return View::make('local.managers.shared.school-uhs', 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'));
  229. } else {
  230. 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'));
  231. }
  232. }
  233. public function print_school($id)
  234. {
  235. ini_set('memory_limit', '256M');
  236. DB::connection()->disableQueryLog();
  237. $school = School::find($id);
  238. $title = $school->name . ' Assessment Report - ' . date('m/d/Y');
  239. $outcomes = Outcome::orderBy('name', 'asc')->get();
  240. $outcomeCount = Outcome::all()->count();
  241. /**
  242. * List of courses (grouped sections)
  243. */
  244. $program_ids = $school->programs->lists('id');
  245. $grouped_courses = Course::
  246. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  247. select(DB::raw('name, code, number, semester_id, program_id'))
  248. ->with('semester')
  249. ->with('program')
  250. ->whereIn('program_id', $program_ids)
  251. ->whereIn('semester_id', Session::get('semesters_ids'))
  252. ->groupBy(array('code', 'number', 'semester_id'))
  253. ->orderBy('code')
  254. ->orderBy('number')
  255. ->orderBy('semester_id')
  256. ->get();
  257. // Fetch programs with participation
  258. $participating_programs = $this->participatingPrograms($school);
  259. /**
  260. * Calculate how many sections are doing assessment
  261. */
  262. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  263. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  264. $assessed_sections_count = 0;
  265. $school_sections_count = 0;
  266. foreach ($school->programs as $program) {
  267. foreach ($program->courses as $course) {
  268. if ($course->outcomes_achieved != NULL) {
  269. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  270. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  271. for ($i = 1; $i <= count($outcomes_attempted); $i++) {
  272. $outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  273. $outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  274. }
  275. $assessed_sections_count += 1;
  276. }
  277. $school_sections_count += 1;
  278. }
  279. }
  280. /**
  281. * Calculate how many programs achieved and attempted each outcome in this school
  282. */
  283. // Number of programs that achieved a particular learning outcome
  284. $achievedProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  285. // Number of programs that attempted a particular learning outcome
  286. $attemptedProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  287. $output = array();
  288. // For each outcome
  289. foreach ($outcomes as $outcome) {
  290. // For each program with courses that do assessment
  291. foreach (Program::with(array('courses' => function ($query) {
  292. // $query->whereNotNull('outcomes_attempted');
  293. $query->whereIn('semester_id', Session::get('semesters_ids'));
  294. }))->where('school_id', $school->id)->orderBy('name', 'asc')->get() as $program) {
  295. // To acummulate all criteria for one program
  296. $achieved_outcomes_per_program = array_fill(1, $outcomeCount, 0);
  297. $attempted_outcomes_per_program = array_fill(1, $outcomeCount, 0);
  298. //Flag for counting programs
  299. $flag = false;
  300. // For each course in the program
  301. foreach ($program->courses as $course) {
  302. // If the outcome in question is being evaluated
  303. $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  304. $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  305. if (
  306. array_key_exists($outcome->id, $course_outcomes_attempted2)
  307. && $course_outcomes_attempted2[$outcome->id] > 0
  308. ) {
  309. $achieved_outcomes_per_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  310. $attempted_outcomes_per_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  311. // Add one to the programs assessing, if it wasn't added before
  312. if (!$flag) {
  313. $attemptedProgramsPerOutcome[$outcome->id] += 1;
  314. $flag = true;
  315. }
  316. }
  317. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_program);
  318. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  319. }
  320. //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
  321. if ($attempted_outcomes_per_program[$outcome->id] != 0 && (float)$achieved_outcomes_per_program[$outcome->id] / $attempted_outcomes_per_program[$outcome->id] * 100 >= $outcome->expected_outcome) {
  322. $achievedProgramsPerOutcome[$outcome->id] += 1;
  323. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  324. }
  325. }
  326. }
  327. return View::make('local.managers.shared.print_school', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'school', 'assessed_sections_count', 'school_sections_count', 'achievedProgramsPerOutcome', 'attemptedProgramsPerOutcome', 'grouped_courses', 'participating_programs'));
  328. }
  329. }