Без опису

AdministratorsController.php 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. class AdministratorsController extends \BaseController
  3. {
  4. public function overview()
  5. {
  6. //Total amount of learning outcomes
  7. $outcomeCount = Outcome::withTrashed()->count();
  8. // Id for excluding UHS from records
  9. $uhs_school_id = School::where('name', 'LIKE', '%UHS%')->first()->id;
  10. $uhs_program_id = Program::where('name', 'LIKE', '%UHS%')->first()->id;
  11. $schools = School::where('id', '!=', $uhs_school_id)->orderBy('name', 'asc')->get();
  12. $title = 'Campus Overview';
  13. $outcomes = Outcome::withTrashed()->select('id', 'name', 'expected_outcome')->orderBy('name', 'asc')->get();
  14. $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  15. $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  16. $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  17. $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  18. /**
  19. * Calculate campus wide outcome performance
  20. */
  21. // Calculate campus wide outcome performance for undergrad and grad
  22. foreach (Course::with('program')
  23. ->where('program_id', '!=', $uhs_program_id)
  24. ->where('code', '!=', 'TEST')
  25. ->whereNotNull('outcomes_achieved')
  26. ->whereIn('semester_id', Session::get('semesters_ids'))->get() as $course)
  27. {
  28. if(!$course->program->is_graduate)
  29. {
  30. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  31. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  32. for($i=1; $i<=count($undergrad_outcomes_attempted); $i++)
  33. {
  34. $undergrad_outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  35. $undergrad_outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  36. }
  37. }
  38. else
  39. {
  40. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  41. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  42. for($i=1; $i<=count($grad_outcomes_attempted); $i++)
  43. {
  44. $grad_outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  45. $grad_outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  46. }
  47. }
  48. }
  49. /**
  50. * Calculate how many programs achieved and attempted each outcome
  51. */
  52. // Number of programs that achieved a particular learning outcome
  53. $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  54. // Number of programs that attempted a particular learning outcome
  55. $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  56. // Names of programs doing assessment
  57. // Fetch programs with participation
  58. $participating_undergrad_programs = DB::table('VIEW_participating_programs')
  59. ->whereIn('semester_id', Session::get('semesters_ids'))
  60. ->where('is_graduate', 0)
  61. ->groupBy('id')
  62. ->orderBy('name', 'asc')
  63. ->get();
  64. $output = array();
  65. // For each outcome
  66. foreach ($outcomes as $outcome)
  67. {
  68. // For each program with courses that do assessment
  69. foreach (Program::with(array('courses' => function($query){
  70. $query->whereNotNull('outcomes_attempted');
  71. $query->where('code', '!=', 'TEST');
  72. $query->whereIn('semester_id', Session::get('semesters_ids'));
  73. }))->where('is_graduate', 0)->orderBy('name', 'asc')->get() as $program)
  74. {
  75. // To acummulate all criteria for one program
  76. $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  77. $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  78. //Flag for counting programs
  79. $flag =false;
  80. // For each course in the program
  81. foreach ($program->courses as $course)
  82. {
  83. // If the outcome in question is being evaluated
  84. $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  85. $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  86. if(array_key_exists($outcome->id, $course_outcomes_attempted2 )
  87. && $course_outcomes_attempted2[$outcome->id]>0)
  88. {
  89. $achieved_outcomes_per_undergrad_program[$outcome->id]+=$course_outcomes_achieved2[$outcome->id];
  90. $attempted_outcomes_per_undergrad_program[$outcome->id]+=$course_outcomes_attempted2[$outcome->id];
  91. // Add one to the programs assessing, if it wasn't added before
  92. if(!$flag)
  93. {
  94. $attemptedUndergradProgramsPerOutcome[$outcome->id]+=1;
  95. $flag= true;
  96. }
  97. }
  98. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  99. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_undergrad_program);
  100. }
  101. //If the accumulated achieved criteria for a specific outcome in a program divided by the accumulated attempted criteria for a specific outcome in a program is greated than the expected outcome
  102. if($attempted_outcomes_per_undergrad_program[$outcome->id]!=0 && (float)$achieved_outcomes_per_undergrad_program[$outcome->id]/$attempted_outcomes_per_undergrad_program[$outcome->id]*100 >= $outcome->expected_outcome)
  103. {
  104. $achievedUndergradProgramsPerOutcome[$outcome->id]+=1;
  105. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedUndergradProgramsPerOutcome);
  106. }
  107. }
  108. }
  109. /**
  110. * Calculate how many programs achieved and attempted each outcome
  111. */
  112. // Number of programs that achieved a particular learning outcome
  113. $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  114. // Number of programs that attempted a particular learning outcome
  115. $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  116. // Names of programs doing assessment
  117. $participating_grad_programs = DB::table('VIEW_participating_programs')
  118. ->whereIn('semester_id', Session::get('semesters_ids'))
  119. ->where('is_graduate', 1)
  120. ->groupBy('id')
  121. ->orderBy('name', 'asc')
  122. ->get();
  123. $output = array();
  124. // For each outcome
  125. foreach ($outcomes as $outcome)
  126. {
  127. // For each program with courses that do assessment
  128. foreach (Program::with(array('courses' => function($query){
  129. $query->whereNotNull('outcomes_attempted');
  130. $query->where('code', '!=', 'TEST');
  131. $query->whereIn('semester_id', Session::get('semesters_ids'));
  132. }))->where('is_graduate', 1)->orderBy('name', 'asc')->get() as $program)
  133. {
  134. // To acummulate all criteria for one program
  135. $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  136. $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  137. //Flag for counting programs
  138. $flag =false;
  139. // For each course in the program
  140. foreach ($program->courses as $course)
  141. {
  142. // If the outcome in question is being evaluated
  143. $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  144. $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  145. if(array_key_exists($outcome->id, $course_outcomes_attempted2 )
  146. && $course_outcomes_attempted2[$outcome->id]>0)
  147. {
  148. $achieved_outcomes_per_grad_program[$outcome->id]+=$course_outcomes_achieved2[$outcome->id];
  149. $attempted_outcomes_per_grad_program[$outcome->id]+=$course_outcomes_attempted2[$outcome->id];
  150. // Add one to the programs assessing, if it wasn't added before
  151. if(!$flag)
  152. {
  153. $attemptedGradProgramsPerOutcome[$outcome->id]+=1;
  154. $flag= true;
  155. }
  156. }
  157. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_program);
  158. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_grad_program);
  159. }
  160. //If the accumulated achieved criteria for a specific outcome in a program divided by the accumulated attempted criteria for a specific outcome in a program is greated than the expected outcome
  161. if($attempted_outcomes_per_grad_program[$outcome->id]!=0 && (float)$achieved_outcomes_per_grad_program[$outcome->id]/$attempted_outcomes_per_grad_program[$outcome->id]*100 >= $outcome->expected_outcome)
  162. {
  163. $achievedGradProgramsPerOutcome[$outcome->id]+=1;
  164. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedGradProgramsPerOutcome);
  165. }
  166. }
  167. }
  168. return View::make('local.managers.admins.overview', compact('title', 'schools', 'outcomes', 'undergrad_outcomes_achieved', 'undergrad_outcomes_attempted', 'grad_outcomes_achieved', 'grad_outcomes_attempted', 'attemptedUndergradProgramsPerOutcome', 'participating_undergrad_programs', 'achievedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'participating_grad_programs', 'achievedGradProgramsPerOutcome'));
  169. }
  170. }