Nav apraksta

ProgramCoordinatorsController.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. use Illuminate\Support\Facades\Auth;
  3. use Illuminate\Support\Facades\Log;
  4. class ProgramCoordinatorsController extends \BaseController
  5. {
  6. public function overview()
  7. {
  8. //TODO Find a better way to prevent non-scoords from reaching the page
  9. switch (Auth::user()->role) {
  10. case 1:
  11. return Redirect::to('administrator');
  12. break;
  13. case 2:
  14. return Redirect::to('school/' . Auth::user()->school->id);
  15. break;
  16. }
  17. //Log::info(Auth::user()->programs);
  18. $title = 'Program Coordinator Overview';
  19. $programs = Auth::user()->programs;
  20. //Log::info($programs);
  21. //$outcomes = Outcome::orderBy('name', 'asc')->get();
  22. $semesters = Session::get('semesters_ids');
  23. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  24. //Log::info($semesters->start);
  25. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  26. ->whereNull('deleted_at')
  27. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  28. ->orderBy('name', 'ASC')->get();
  29. $outcomeCount = count($outcomes);
  30. $programs_array = array();
  31. $programs_contact = array();
  32. // old code
  33. /*foreach ($programs as $program) {
  34. $program_array = array();
  35. $program_array['program'] = $program;
  36. $program_array['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
  37. $program_array['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
  38. $program_array['program_courses'] = $program->courses;
  39. $program_array['grouped_objectives'] = $program->objectives();
  40. $program_array['assessed_courses_count'] = 0;
  41. foreach ($program_array['program_courses'] as $course) {
  42. if ($course->outcomes_achieved != NULL) {
  43. $program_array['course_outcomes_achieved'] = json_decode($course->outcomes_achieved, true);
  44. $program_array['course_outcomes_attempted'] = json_decode($course->outcomes_attempted, true);
  45. for ($i = 1; $i <= count($program_array['outcomes_attempted']); $i++) {
  46. $program_array['outcomes_achieved'][$i] += $program_array['course_outcomes_achieved'][$i];
  47. $program_array['outcomes_attempted'][$i] += $program_array['course_outcomes_attempted'][$i];
  48. }
  49. $program_array['assessed_courses_count'] += 1;
  50. }
  51. }
  52. */
  53. foreach ($programs as $program) {
  54. //Log::info($program);
  55. $program_array = array();
  56. $program_object = new \stdClass();
  57. $program_object->name = $program->name;
  58. $program_object->school = $program->school->name;
  59. $program_object->id = $program->id;
  60. $program_array['program'] = $program_object;
  61. //Log::info($program_array);
  62. $program_array['outcomes_achieved'] = [];
  63. $program_array['outcomes_attempted'] = [];
  64. $program_array['program_outcomes_achieved'] = [];
  65. $program_array['program_outcomes_attempted'] = [];
  66. //Log::info($program_array);
  67. foreach ($outcomes as $outcome) {
  68. $program_array['outcomes_achieved'][$outcome->id] = 0;
  69. $program_array['outcomes_attempted'][$outcome->id] = 0;
  70. $program_array['program_outcomes_achieved'][$outcome->id] = 0;
  71. $program_array['program_outcomes_attempted'][$outcome->id] = 0;
  72. }
  73. $program_array['program_outcomes_achieved'] = $program->program_students_per_outcome['program_info']['outcomes_achieved_combined'];
  74. $program_array['program_outcomes_attempted'] = $program->program_students_per_outcome['program_info']['outcomes_attempted_combined'];
  75. $program_array['program_courses'] = $program->courses;
  76. $program_array['assessed_courses_count'] = 0;
  77. foreach ($program->courses as $course) {
  78. $student_report = $course->student_report_for_outcome;
  79. if ($student_report) {
  80. foreach ($student_report as $outcome_id => $score) {
  81. if (array_key_exists($outcome_id, $program_array['outcomes_attempted'])) $program_array['outcomes_attempted'][$outcome_id] += $student_report[$outcome_id]['calculations']['student_attempted'];
  82. else $program_array['outcomes_attempted'][$outcome_id] = $student_report[$outcome_id]['calculations']['student_attempted'];
  83. if (array_key_exists($outcome_id, $program_array['outcomes_achieved'])) $program_array['outcomes_achieved'][$outcome_id] += $student_report[$outcome_id]['calculations']['student_achieved'];
  84. else $program_array['outcomes_achieved'][$outcome_id] = $student_report[$outcome_id]['calculations']['student_achieved'];
  85. }
  86. /*
  87. $course->with_program_report = 1;
  88. $program_student_report = $course->student_report_for_outcome;
  89. foreach ($program_student_report as $outcome_id => $score) {
  90. if (array_key_exists($outcome_id, $program_array['program_outcomes_attempted'])) $program_array['program_outcomes_attempted'][$outcome_id] += $program_student_report[$outcome_id]['calculations']['student_attempted'];
  91. else $program_array['program_outcomes_attempted'][$outcome_id] = $program_student_report[$outcome_id]['calculations']['student_attempted'];
  92. if (array_key_exists($outcome_id, $program_array['program_outcomes_achieved'])) $program_array['program_outcomes_achieved'][$outcome_id] += $program_student_report[$outcome_id]['calculations']['student_achieved'];
  93. else $program_array['program_outcomes_achieved'][$outcome_id] = $program_student_report[$outcome_id]['calculations']['student_achieved'];
  94. } */
  95. $program_array['assessed_courses_count'] += 1;
  96. }
  97. }
  98. /*foreach ($programs as $program) {
  99. //Log::info($program);
  100. $program_array = array();
  101. $program_object = new \stdClass();
  102. $program_object->name = $program->name;
  103. $program_object->school = $program->school->name;
  104. $program_object->id = $program->id;
  105. $program_array['program'] = $program_object;
  106. //Log::info($program_array);
  107. $program_array['outcomes_achieved'] = [];
  108. $program_array['outcomes_attempted'] = [];
  109. //Log::info($program_array);
  110. $program_array['program_courses'] = $program->courses;
  111. $program_array['assessed_courses_count'] = 0;
  112. foreach ($program_array['program_courses'] as $course) {
  113. //$student_report = $course->student_report_for_outcome;
  114. //Log::info($program_array);
  115. $program_array['course_outcomes_achieved'] = $course->outcomes_ach();
  116. //Log::info("course_outcomes_achieved");
  117. //Log::info($program_array['course_outcomes_achieved']);
  118. //Log::info($program_array);
  119. if ($program_array['course_outcomes_achieved']) {
  120. //(($program_array['course_outcomes_achieved'])) {
  121. $program_array['course_outcomes_achieved'] = $course->outcomes_ach();
  122. $program_array['course_outcomes_attempted'] = $course->outcomes_att();
  123. //Log::info('course_outcomes_achieved');
  124. //Log::info($program_array['course_outcomes_achieved']);
  125. //Log::info($program_array);
  126. foreach ($program_array['course_outcomes_achieved'] as $outcome_id => $score) {
  127. if (array_key_exists($outcome_id, $program_array['outcomes_achieved'])) $program_array['outcomes_achieved'][$outcome_id] += $score;
  128. else $program_array['outcomes_achieved'][$outcome_id] = $score;
  129. //Log::info('program["outcomes_achieved"]');
  130. //Log::info($program_array['outcomes_achieved'][$i]);
  131. //Log::info($program_array);
  132. Log::info("outcomes_achieved");
  133. Log::info($program_array['outcomes_achieved']);
  134. }
  135. foreach ($program_array['course_outcomes_attempted'] as $i => $score) {
  136. if (array_key_exists($i, $program_array['outcomes_attempted'])) $program_array['outcomes_attempted'][$i] += $program_array['course_outcomes_attempted'][$i];
  137. else $program_array['outcomes_attempted'][$i] = $program_array['course_outcomes_attempted'][$i];
  138. //Log::info('program["outcomes_achieved"]');
  139. //Log::info($program_array['outcomes_attempted'][$i]);
  140. //Log::info($program_array);
  141. }
  142. $program_array['assessed_courses_count'] += 1;
  143. }
  144. }*/
  145. /**
  146. * List of grouped courses (grouped sections)
  147. */
  148. //old code
  149. /* $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  150. ->with('semester')
  151. ->with('program')
  152. ->where('program_id', $program->id)
  153. ->whereIn('semester_id', Session::get('semesters_ids'))
  154. ->groupBy(array('code', 'number', 'semester_id'))
  155. ->orderBy('code')
  156. ->orderBy('number')
  157. ->orderBy('semester_id')
  158. ->get(); */
  159. //Log::info($program_array);
  160. $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, semester_id, program_id'))
  161. ->with('semester')
  162. ->with('program')
  163. ->where('program_id', $program->id)
  164. ->whereIn('semester_id', Session::get('semesters_ids'))
  165. ->groupBy(array('code', 'number', 'semester_id'))
  166. ->orderBy('code')
  167. ->orderBy('number')
  168. ->orderBy('semester_id')
  169. ->get();
  170. $program_array['linea_de_graph'] = $program->expected_outcome_target;
  171. $programs_array[] = $program_array;
  172. // Program contact information
  173. $users = User::select('users.*')
  174. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  175. ->where(function ($query) use ($program) {
  176. $query
  177. ->where('school_id', $program->school_id)
  178. ->where('role', 2);
  179. })
  180. ->orWhere(function ($query) use ($program) {
  181. $query
  182. ->where('role', 3)
  183. ->where('program_id', $program->id);
  184. })
  185. ->orWhere(function ($query) use ($program) {
  186. $query
  187. ->where('role', 4)
  188. ->where('program_id', $program->id);
  189. })
  190. ->get();
  191. $programs_contact[] = $users;
  192. }
  193. return View::make('local.managers.pCoords.overview', compact('title', 'programs', 'outcomes', 'programs_array', 'programs_contact'));
  194. }
  195. }