No Description

ProfessorsController.php 8.2KB

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