Brak opisu

SchoolsController.php 20KB

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