설명 없음

SchoolsController.php 19KB

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