Ei kuvausta

ProgramCoordinatorsController.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. class ProgramCoordinatorsController extends \BaseController {
  3. public function overview()
  4. {
  5. //TODO Find a better way to prevent non-scoords from reaching the page
  6. switch(Auth::user()->role)
  7. {
  8. case 1:
  9. return Redirect::to('administrator');
  10. break;
  11. case 2:
  12. return Redirect::to('school-coordinator');
  13. break;
  14. }
  15. $title = 'Program Coordinator Overview';
  16. $programs = Auth::user()->programs;
  17. $outcomes = Outcome::orderBy('name', 'asc')->get();
  18. $outcomeCount = Outcome::all()->count();
  19. $programs_array = array();
  20. $programs_contact = array();
  21. foreach ($programs as $program)
  22. {
  23. $program_array = array();
  24. $program_array['program'] = $program;
  25. $program_array['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
  26. $program_array['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
  27. $program_array['program_courses'] = $program->courses;
  28. $program_array['grouped_objectives'] = $program->objectives();
  29. $program_array['assessed_courses_count']=0;
  30. foreach ($program_array['program_courses'] as $course)
  31. {
  32. if($course->outcomes_achieved!=NULL)
  33. {
  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. {
  38. $program_array['outcomes_achieved'][$i]+=$program_array['course_outcomes_achieved'][$i];
  39. $program_array['outcomes_attempted'][$i]+=$program_array['course_outcomes_attempted'][$i];
  40. }
  41. $program_array['assessed_courses_count']+=1;
  42. }
  43. }
  44. /**
  45. * List of grouped courses (grouped sections)
  46. */
  47. $program_array['grouped_courses'] = Course::
  48. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  49. ->with('semester')
  50. ->with('program')
  51. ->where('program_id', $program->id)
  52. ->whereIn('semester_id', Session::get('semesters_ids'))
  53. ->groupBy(array('code', 'number', 'semester_id'))
  54. ->orderBy('code')
  55. ->orderBy('number')
  56. ->orderBy('semester_id')
  57. ->get();
  58. $programs_array[] = $program_array;
  59. // Program contact information
  60. $users = User::
  61. select('users.*')
  62. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  63. ->where(function($query) use($program)
  64. {
  65. $query
  66. ->where('school_id', $program->school_id)
  67. ->where('role', 2);
  68. })
  69. ->orWhere(function($query) use($program)
  70. {
  71. $query
  72. ->where('role', 3)
  73. ->where('program_id', $program->id);
  74. })
  75. ->orWhere(function($query) use($program)
  76. {
  77. $query
  78. ->where('role', 4)
  79. ->where('program_id', $program->id);
  80. })
  81. ->get();
  82. $programs_contact[] = $users;
  83. }
  84. return View::make('local.managers.pCoords.overview', compact('title', 'programs', 'outcomes', 'programs_array', 'programs_contact'));
  85. }
  86. }