Nenhuma descrição

ProgramCoordinatorsController.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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-coordinator');
  15. break;
  16. }
  17. Log::info(Auth::user()->programs);
  18. $title = 'Program Coordinator Overview';
  19. $programs = Auth::user()->programs;
  20. //$outcomes = Outcome::orderBy('name', 'asc')->get();
  21. $semesters = Session::get('semesters_ids');
  22. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  23. Log::info($semesters->start);
  24. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  25. ->whereNull('deleted_at')
  26. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  27. ->orderBy('name', 'ASC')->get();
  28. $outcomeCount = count($outcomes);
  29. $programs_array = array();
  30. $programs_contact = array();
  31. // old code
  32. /*foreach ($programs as $program) {
  33. $program_array = array();
  34. $program_array['program'] = $program;
  35. $program_array['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
  36. $program_array['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
  37. $program_array['program_courses'] = $program->courses;
  38. $program_array['grouped_objectives'] = $program->objectives();
  39. $program_array['assessed_courses_count'] = 0;
  40. foreach ($program_array['program_courses'] as $course) {
  41. if ($course->outcomes_achieved != NULL) {
  42. $program_array['course_outcomes_achieved'] = json_decode($course->outcomes_achieved, true);
  43. $program_array['course_outcomes_attempted'] = json_decode($course->outcomes_attempted, true);
  44. for ($i = 1; $i <= count($program_array['outcomes_attempted']); $i++) {
  45. $program_array['outcomes_achieved'][$i] += $program_array['course_outcomes_achieved'][$i];
  46. $program_array['outcomes_attempted'][$i] += $program_array['course_outcomes_attempted'][$i];
  47. }
  48. $program_array['assessed_courses_count'] += 1;
  49. }
  50. }
  51. */
  52. foreach ($programs as $program) {
  53. $program_array = array();
  54. $program_array['program'] = $program;
  55. $program_array['outcomes_achieved'] = [];
  56. $program_array['outcomes_attempted'] = [];
  57. $program_array['program_courses'] = $program->courses;
  58. $program_array['grouped_objectives'] = $program->objectives();
  59. $program_array['assessed_courses_count'] = 0;
  60. foreach ($program_array['program_courses'] as $course) {
  61. if (!($program_array['course_outcomes_achieved'] = $course->outcomes_ach())) {
  62. // $program_array['course_outcomes_achieved'] = $course->outcomes_ach();
  63. $program_array['course_outcomes_attempted'] = $course->outcomes_att();
  64. Log::info($program_array['course_outcomes_achieved']);
  65. foreach ($program_array['course_outcomes_achieved'] as $i => $score) {
  66. if (array_key_exists($i, $program_array['outcomes_achieved'])) $program_array['outcomes_achieved'][$i] += $program_array['course_outcomes_achieved'][$i];
  67. else $program_array['outcomes_achieved'][$i] = $program_array['course_outcomes_achieved'][$i];
  68. }
  69. foreach ($program_array['course_outcomes_attempted'] as $i => $score) {
  70. if (array_key_exists($i, $program_array['outcomes_attempted'])) $program_array['outcomes_attempted'][$i] += $program_array['course_outcomes_attempted'][$i];
  71. else $program_array['outcomes_attempted'][$i] = $program_array['course_outcomes_attempted'][$i];
  72. }
  73. $program_array['assessed_courses_count'] += 1;
  74. }
  75. }
  76. /**
  77. * List of grouped courses (grouped sections)
  78. */
  79. //old code
  80. /* $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  81. ->with('semester')
  82. ->with('program')
  83. ->where('program_id', $program->id)
  84. ->whereIn('semester_id', Session::get('semesters_ids'))
  85. ->groupBy(array('code', 'number', 'semester_id'))
  86. ->orderBy('code')
  87. ->orderBy('number')
  88. ->orderBy('semester_id')
  89. ->get(); */
  90. $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, semester_id, program_id'))
  91. ->with('semester')
  92. ->with('program')
  93. ->where('program_id', $program->id)
  94. ->whereIn('semester_id', Session::get('semesters_ids'))
  95. ->groupBy(array('code', 'number', 'semester_id'))
  96. ->orderBy('code')
  97. ->orderBy('number')
  98. ->orderBy('semester_id')
  99. ->get();
  100. $programs_array[] = $program_array;
  101. // Program contact information
  102. $users = User::select('users.*')
  103. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  104. ->where(function ($query) use ($program) {
  105. $query
  106. ->where('school_id', $program->school_id)
  107. ->where('role', 2);
  108. })
  109. ->orWhere(function ($query) use ($program) {
  110. $query
  111. ->where('role', 3)
  112. ->where('program_id', $program->id);
  113. })
  114. ->orWhere(function ($query) use ($program) {
  115. $query
  116. ->where('role', 4)
  117. ->where('program_id', $program->id);
  118. })
  119. ->get();
  120. $programs_contact[] = $users;
  121. }
  122. return View::make('local.managers.pCoords.overview', compact('title', 'programs', 'outcomes', 'programs_array', 'programs_contact'));
  123. }
  124. }