Няма описание

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. class SchoolCoordinatorsController extends \BaseController {
  3. private function participatingPrograms($school)
  4. {
  5. return DB::table('VIEW_participating_programs')
  6. ->where('school_id', $school->id)
  7. ->whereIn('semester_id', Session::get('semesters_ids'))
  8. ->lists('id');
  9. }
  10. public function overview()
  11. {
  12. DB::disableQueryLog();
  13. Log::debug('user'.Auth::user()->id);
  14. //TODO Find a better way to prevent non-scoords from reaching the page
  15. switch(Auth::user()->role)
  16. {
  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::
  47. select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  48. ->with('semester')
  49. ->with('program')
  50. ->whereIn('courses.program_id', $program_ids)
  51. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  52. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  53. ->where('programs.is_graduate', '=', 1)
  54. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  55. ->orderBy('courses.code')
  56. ->orderBy('courses.number')
  57. ->orderBy('courses.semester_id')
  58. ->get();
  59. $undergrad_grouped_courses = Course::
  60. select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  61. ->with('semester')
  62. ->with('program')
  63. ->whereIn('courses.program_id', $program_ids)
  64. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  65. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  66. ->where('programs.is_graduate', '=', 0)
  67. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  68. ->orderBy('courses.code')
  69. ->orderBy('courses.number')
  70. ->orderBy('courses.semester_id')
  71. ->get();
  72. // Fetch programs with participation
  73. $participating_programs = $this->participatingPrograms($school);
  74. /**
  75. * Calculate how many sections are doing assessment
  76. */
  77. $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  78. $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  79. $undergrad_assessed_sections_count = 0;
  80. $undergrad_school_sections_count = 0;
  81. $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  82. $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  83. $grad_assessed_sections_count = 0;
  84. $grad_school_sections_count = 0;
  85. foreach($school->programs as $program)
  86. {
  87. foreach ($program->courses as $course)
  88. {
  89. if(!$course->program->is_graduate)
  90. {
  91. if($course->outcomes_achieved != NULL)
  92. {
  93. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  94. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  95. for($i=1; $i<=count($undergrad_outcomes_attempted); $i++)
  96. {
  97. $undergrad_outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  98. $undergrad_outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  99. }
  100. $undergrad_assessed_sections_count+=1;
  101. }
  102. $undergrad_school_sections_count+=1;
  103. }
  104. else
  105. {
  106. if($course->outcomes_achieved != NULL)
  107. {
  108. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  109. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  110. for($i=1; $i<=count($grad_outcomes_attempted); $i++)
  111. {
  112. $grad_outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  113. $grad_outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  114. }
  115. $grad_assessed_sections_count+=1;
  116. }
  117. $grad_school_sections_count+=1;
  118. }
  119. }
  120. }
  121. /**
  122. * Calculate how many programs achieved and attempted each outcome in this school
  123. */
  124. // Number of programs that achieved a particular learning outcome
  125. $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  126. // Number of programs that attempted a particular learning outcome
  127. $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  128. // Fetch programs with participation for the school
  129. $participating_undergrad_programs = DB::table('VIEW_participating_programs')
  130. ->whereIn('semester_id', Session::get('semesters_ids'))
  131. ->where('is_graduate', 0)
  132. ->where('school_id', $school->id)
  133. ->groupBy('id')
  134. ->get();
  135. $output = array();
  136. // For each outcome
  137. foreach ($outcomes as $outcome)
  138. {
  139. // For each program with courses that do assessment
  140. $programs_with_courses = Program::with(array('courses' => function($query){
  141. $query->whereNotNull('outcomes_attempted');
  142. $query->whereIn('semester_id', Session::get('semesters_ids'));
  143. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  144. foreach ($programs_with_courses as $program)
  145. {
  146. // To acummulate all criteria for one program
  147. $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  148. $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  149. //Flag for counting programs
  150. $flag =false;
  151. // For each course in the program
  152. foreach ($program->courses as $course)
  153. {
  154. // If the outcome in question is being evaluated
  155. $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  156. $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  157. if(array_key_exists($outcome->id, $course_outcomes_attempted2 )
  158. && $course_outcomes_attempted2[$outcome->id]>0)
  159. {
  160. $achieved_outcomes_per_undergrad_program[$outcome->id]+=$course_outcomes_achieved2[$outcome->id];
  161. $attempted_outcomes_per_undergrad_program[$outcome->id]+=$course_outcomes_attempted2[$outcome->id];
  162. // Add one to the programs assessing, if it wasn't added before
  163. if(!$flag)
  164. {
  165. $attemptedUndergradProgramsPerOutcome[$outcome->id]+=1;
  166. $flag= true;
  167. }
  168. }
  169. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  170. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  171. }
  172. //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
  173. 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)
  174. {
  175. $achievedUndergradProgramsPerOutcome[$outcome->id]+=1;
  176. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  177. }
  178. }
  179. }
  180. /**
  181. * Calculate how many programs achieved and attempted each outcome in this school
  182. */
  183. // Number of programs that achieved a particular learning outcome
  184. $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  185. // Number of programs that attempted a particular learning outcome
  186. $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  187. // Fetch programs with participation for the school
  188. $participating_grad_programs = DB::table('VIEW_participating_programs')
  189. ->whereIn('semester_id', Session::get('semesters_ids'))
  190. ->where('is_graduate', 1)
  191. ->where('school_id', $school->id)
  192. ->groupBy('id')
  193. ->get();
  194. $output = array();
  195. // For each outcome
  196. foreach ($outcomes as $outcome)
  197. {
  198. // For each program with courses that do assessment
  199. $programs_with_courses = Program::with(array('courses' => function($query){
  200. $query->whereNotNull('outcomes_attempted');
  201. $query->whereIn('semester_id', Session::get('semesters_ids'));
  202. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  203. foreach ($programs_with_courses as $program)
  204. {
  205. // To acummulate all criteria for one program
  206. $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  207. $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  208. //Flag for counting programs
  209. $flag =false;
  210. // For each course in the program
  211. foreach ($program->courses as $course)
  212. {
  213. // If the outcome in question is being evaluated
  214. $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  215. $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  216. if(array_key_exists($outcome->id, $course_outcomes_attempted2 )
  217. && $course_outcomes_attempted2[$outcome->id]>0)
  218. {
  219. $achieved_outcomes_per_grad_program[$outcome->id]+=$course_outcomes_achieved2[$outcome->id];
  220. $attempted_outcomes_per_grad_program[$outcome->id]+=$course_outcomes_attempted2[$outcome->id];
  221. // Add one to the programs assessing, if it wasn't added before
  222. if(!$flag)
  223. {
  224. $attemptedGradProgramsPerOutcome[$outcome->id]+=1;
  225. $flag= true;
  226. }
  227. }
  228. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_program);
  229. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  230. }
  231. //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
  232. 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)
  233. {
  234. $achievedGradProgramsPerOutcome[$outcome->id]+=1;
  235. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  236. }
  237. }
  238. }
  239. 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'));
  240. }
  241. }