Geen omschrijving

ProgramCoordinatorsController.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. $outcomeCount = Outcome::all()->count();
  22. $programs_array = array();
  23. $programs_contact = array();
  24. foreach ($programs as $program) {
  25. $program_array = array();
  26. $program_array['program'] = $program;
  27. $program_array['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
  28. $program_array['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
  29. $program_array['program_courses'] = $program->courses;
  30. $program_array['grouped_objectives'] = $program->objectives();
  31. $program_array['assessed_courses_count'] = 0;
  32. foreach ($program_array['program_courses'] as $course) {
  33. if ($course->outcomes_achieved != NULL) {
  34. $program_array['course_outcomes_achieved'] = json_decode($course->outcomes_achieved, true);
  35. $program_array['course_outcomes_attempted'] = json_decode($course->outcomes_attempted, true);
  36. for ($i = 1; $i <= count($program_array['outcomes_attempted']); $i++) {
  37. $program_array['outcomes_achieved'][$i] += $program_array['course_outcomes_achieved'][$i];
  38. $program_array['outcomes_attempted'][$i] += $program_array['course_outcomes_attempted'][$i];
  39. }
  40. $program_array['assessed_courses_count'] += 1;
  41. }
  42. }
  43. /**
  44. * List of grouped courses (grouped sections)
  45. */
  46. $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  47. ->with('semester')
  48. ->with('program')
  49. ->where('program_id', $program->id)
  50. ->whereIn('semester_id', Session::get('semesters_ids'))
  51. ->groupBy(array('code', 'number', 'semester_id'))
  52. ->orderBy('code')
  53. ->orderBy('number')
  54. ->orderBy('semester_id')
  55. ->get();
  56. $programs_array[] = $program_array;
  57. // Program contact information
  58. $users = User::select('users.*')
  59. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  60. ->where(function ($query) use ($program) {
  61. $query
  62. ->where('school_id', $program->school_id)
  63. ->where('role', 2);
  64. })
  65. ->orWhere(function ($query) use ($program) {
  66. $query
  67. ->where('role', 3)
  68. ->where('program_id', $program->id);
  69. })
  70. ->orWhere(function ($query) use ($program) {
  71. $query
  72. ->where('role', 4)
  73. ->where('program_id', $program->id);
  74. })
  75. ->get();
  76. $programs_contact[] = $users;
  77. }
  78. return View::make('local.managers.pCoords.overview', compact('title', 'programs', 'outcomes', 'programs_array', 'programs_contact'));
  79. }
  80. }