Nenhuma descrição

ProfessorsController.php 7.5KB

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