暫無描述

ProfessorsController.php 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. class ProfessorsController extends \BaseController
  3. {
  4. private $grouped_courses;
  5. public function __construct()
  6. {
  7. $this->courses = Auth::user()->courses;
  8. }
  9. public function overview()
  10. {
  11. $title = 'My Courses';
  12. $grouped_courses = Course::where('user_id', Auth::user()->id)->whereIn('semester_id', Session::get('semesters_ids'))->groupBy(array('code', 'number', 'semester_id'))->get();
  13. $semesters = Session::get('semesters_ids');
  14. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  15. Log::info($semesters->start);
  16. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  17. ->whereNull('deleted_at')
  18. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  19. ->orderBy('name', 'ASC')->get();
  20. $outcomeCount = count($outcomes);
  21. $grouped_outcomes_achieved_results = array();
  22. $grouped_outcomes_attempted_results = array();
  23. $grouped_sections = array();
  24. foreach ($grouped_courses as $index => $grouped_course) {
  25. // Blank outcomes for one course
  26. //$outcomes_achieved = array_fill(1, $outcomeCount, 0);
  27. //$outcomes_attempted = array_fill(1, $outcomeCount, 0);
  28. $outcomes_achieved = [];
  29. $outcomes_attempted = [];
  30. // Find sections belonging to user with identifier of one course
  31. $sections = Course::where('user_id', Auth::user()->id)
  32. ->where('code', $grouped_course->code)
  33. ->whereIn('semester_id', Session::get('semesters_ids'))
  34. ->where('number', $grouped_course->number)
  35. ->where('semester_id', $grouped_course->semester_id)
  36. ->get();
  37. // For each of the professor's course sections, add the attempted and achieved criteria per outcome
  38. foreach ($sections as $section) {
  39. $section_outcomes_achieved = $section->outcomes_ach();
  40. $section_outcomes_attempted = $section->outcomes_att();
  41. //if ($section->outcomes_achieved != NULL) {
  42. if (!empty($section_outcomes_achieved)) {
  43. //$section_outcomes_achieved = json_decode($section->outcomes_achieved, true);
  44. //$section_outcomes_attempted = json_decode($section->outcomes_attempted, true);
  45. foreach ($section_outcomes_attempted as $outcome_id => $score) {
  46. if (array_key_exists($outcome_id, $outcomes_achieved) && array_key_exists($outcome_id, $section_outcomes_achieved)) {
  47. $outcomes_achieved[$outcome_id] += $section_outcomes_achieved[$outcome_id];
  48. } elseif (array_key_exists($outcome_id, $outcomes_achieved)) {
  49. $outcomes_achieved[$outcome_id] += 0;
  50. } elseif (array_key_exists($outcome_id, $section_outcomes_achieved)) {
  51. $outcomes_achieved[$outcome_id] = $section_outcomes_achieved[$outcome_id];
  52. } else {
  53. $outcomes_achieved[$outcome_id] = 0;
  54. }
  55. if (array_key_exists($outcome_id, $outcomes_attempted)) {
  56. $outcomes_attempted[$outcome_id] += $section_outcomes_attempted[$outcome_id];
  57. } else {
  58. $outcomes_attempted[$outcome_id] = $section_outcomes_attempted[$outcome_id];
  59. }
  60. //$outcomes_achieved[$outcome_id] += $section_outcomes_achieved[$outcome_id];
  61. //$outcomes_attempted[$outcome_id] += $section_outcomes_attempted[$outcome_id];
  62. }
  63. }
  64. }
  65. $grouped_outcomes_achieved_results[] = $outcomes_achieved;
  66. $grouped_outcomes_attempted_results[] = $outcomes_attempted;
  67. $grouped_sections[] = $sections;
  68. }
  69. return View::make('local.professors.overview', compact('title', 'grouped_courses', 'outcomes', 'grouped_outcomes_attempted_results', 'grouped_outcomes_achieved_results', 'grouped_sections'));
  70. }
  71. public function program()
  72. {
  73. $program = Auth::user()->programs[0];
  74. $title = 'Your Program: ' . $program->name;
  75. $program_courses = Course::where('program_id', '=', $program->id)->whereIn('semester_id', Session::get('semesters_ids'))->get();
  76. $semesters = Session::get('semesters_ids');
  77. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  78. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  79. ->whereNull('deleted_at')
  80. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  81. ->orderBy('name', 'ASC')->get();
  82. $outcomeCount = count($outcomes);
  83. $outcomes_achieved = [];
  84. $outcomes_attempted = [];
  85. Log::info($program_courses);
  86. foreach ($program_courses as $course) {
  87. if ($course->outcomes_ach()) {
  88. $course_outcomes_achieved = $course->outcomes_ach();
  89. $course_outcomes_attempted = $course->outcomes_att();
  90. foreach ($course_outcomes_achieved as $outcome => $score) {
  91. if (array_key_exists($outcome, $outcomes_achieved))
  92. $outcomes_achieved[$outcome] += $score;
  93. else $outcomes_achieved[$outcome] = $score;
  94. }
  95. foreach ($course_outcomes_attempted as $outcome => $score) {
  96. if (array_key_exists($outcome, $outcomes_attempted))
  97. $outcomes_attempted[$outcome] += $score;
  98. else $outcomes_attempted[$outcome] = $score;
  99. }
  100. }
  101. }
  102. // Program contact information
  103. $scoords = User::where('school_id', $program->school_id)
  104. ->where('role', 2)
  105. ->get();
  106. $pcoords = User::select('users.*')
  107. ->join('program_user', 'users.id', '=', 'program_user.user_id')
  108. ->where('role', 3)
  109. ->where('program_id', $program->id)
  110. ->get();
  111. return View::make('local.professors.program', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'scoords', 'pcoords'));
  112. }
  113. public function generalStudiesOverview()
  114. {
  115. $title = 'General Component Assessment Overview';
  116. try {
  117. $programs = Program::generalComponentPrograms();
  118. } catch (Exception $e) {
  119. dd('Unable to find general component programs');
  120. }
  121. $outcomes = Outcome::orderBy('name', 'asc')->get();
  122. $schools = School::all();
  123. $program_packs = array();
  124. if (!$programs->isEmpty()) {
  125. foreach ($programs as $program) {
  126. $program_packs[] = $program->assessmentOverview();
  127. }
  128. }
  129. return View::make('local.managers.shared.general_studies_overview', compact('title', 'outcomes', 'schools', 'program_packs'));
  130. }
  131. }