Ingen beskrivning

ProgramsController.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. class ProgramsController extends \BaseController
  3. {
  4. /**
  5. * Shows a particular program
  6. */
  7. public function show($id)
  8. {
  9. $program = Program::find($id);
  10. $title= $program->school->name.': '.$program->name;
  11. $program_courses = $program->courses;
  12. $outcomes = Outcome::orderBy('name', 'asc')->get();
  13. $schools = School::all();
  14. $outcomeCount = Outcome::all()->count();
  15. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  16. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  17. $assessed_courses_count=0;
  18. foreach ($program_courses as $course)
  19. {
  20. if($course->outcomes_achieved!=NULL)
  21. {
  22. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  23. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  24. for($i=1; $i<=count($outcomes_attempted); $i++)
  25. {
  26. $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  27. $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  28. }
  29. $assessed_courses_count+=1;
  30. }
  31. }
  32. /**
  33. * List of grouped courses (grouped sections)
  34. */
  35. $grouped_courses = Course::
  36. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  37. ->with('semester')
  38. ->with('program')
  39. ->where('program_id', $program->id)
  40. ->whereIn('semester_id', Session::get('semesters_ids'))
  41. ->groupBy(array('code', 'number', 'semester_id'))
  42. ->orderBy('code')
  43. ->orderBy('number')
  44. ->orderBy('semester_id')
  45. ->get();
  46. // Program contact information
  47. $users = User::
  48. select('users.*')
  49. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  50. ->where(function($query) use($program)
  51. {
  52. $query
  53. ->where('school_id', $program->school_id)
  54. ->where('role', 2);
  55. })
  56. ->orWhere(function($query) use($program)
  57. {
  58. $query
  59. ->where('role', 3)
  60. ->where('program_id', $program->id);
  61. })
  62. ->orWhere(function($query) use($program)
  63. {
  64. $query
  65. ->where('role', 4)
  66. ->where('program_id', $program->id);
  67. })
  68. ->get();
  69. return View::make('local.managers.shared.program', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses', 'program', 'users'));
  70. }
  71. /**
  72. * Info to print a program
  73. */
  74. public function print_program($id)
  75. {
  76. $program = Program::find($id);
  77. $title= $program->name.' Assessment Report - '.date('m/d/Y');
  78. $program_courses = $program->courses;
  79. $outcomes = Outcome::orderBy('name', 'asc')->get();
  80. $schools = School::all();
  81. $outcomeCount = Outcome::all()->count();
  82. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  83. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  84. $assessed_courses_count=0;
  85. foreach ($program_courses as $course)
  86. {
  87. if($course->outcomes_achieved!=NULL)
  88. {
  89. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  90. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  91. for($i=1; $i<=count($outcomes_attempted); $i++)
  92. {
  93. $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  94. $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  95. }
  96. $assessed_courses_count+=1;
  97. }
  98. }
  99. /**
  100. * List of grouped courses (grouped sections)
  101. */
  102. $grouped_courses = Course::
  103. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  104. ->with('semester')
  105. ->with('program')
  106. ->where('program_id', $program->id)
  107. ->whereIn('semester_id', Session::get('semesters_ids'))
  108. ->groupBy(array('code', 'number', 'semester_id'))
  109. ->orderBy('code')
  110. ->orderBy('number')
  111. ->orderBy('semester_id')
  112. ->get();
  113. return View::make('local.managers.shared.print_program', compact('title', 'program', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses'));
  114. }
  115. /**
  116. * A list of all programs
  117. */
  118. public function index()
  119. {
  120. $title = "Programs by School";
  121. $programs = Program::orderBy('name')->get();
  122. $schools = School::all();
  123. return View::make('local.managers.shared.programs', compact('programs', 'schools', 'title'));
  124. }
  125. /**
  126. * Fetch a program
  127. */
  128. public function fetch()
  129. {
  130. Log::info('id:'.Input::get('id'));
  131. return School::find(Input::get('id'))->programs;
  132. }
  133. }