No Description

SchoolCoordinatorsController.php 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. <?php
  2. class SchoolCoordinatorsController extends \BaseController
  3. {
  4. private function participatingPrograms($school)
  5. {
  6. return DB::table('programs')
  7. ->join('courses', 'courses.program_id', '=', 'programs.id')
  8. ->join('activities', 'activities.course_id', '=', 'courses.id')
  9. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  10. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  11. ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  12. ->addSelect('courses.semester_id')
  13. ->where('school_id', $school->id)
  14. ->whereIn('semester_id', Session::get('semesters_ids'))
  15. ->lists('id');
  16. // return DB::table('programs')
  17. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  18. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  19. // ->addSelect('courses.semester_id')
  20. // ->where('school_id', $school->id)
  21. // ->whereIn('semester_id', Session::get('semesters_ids'))
  22. // ->lists('id');
  23. }
  24. public function overview_test()
  25. {
  26. ini_set('memory_limit', '256M');
  27. DB::connection()->disableQueryLog();
  28. // $school = School::find($id);
  29. $school = Auth::user()->school;
  30. $id = $school->id;
  31. $title = $school->name;
  32. $schools = School::all();
  33. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  34. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  35. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  36. /**
  37. * List of grouped courses (grouped sections)
  38. */
  39. $program_ids = $school->programs->lists('id');
  40. $undergrad_programs = DB::table('programs')
  41. ->select('id', 'name', 'school_id', 'is_graduate')
  42. ->where('is_graduate', '=', 0)
  43. ->where('school_id', '=', $id)
  44. ->orderBy('name', 'ASC')
  45. ->get();
  46. $grad_programs = DB::table('programs')
  47. ->select('id', 'name', 'school_id', 'is_graduate')
  48. ->where('is_graduate', '=', 1)
  49. ->where('school_id', '=', $id)
  50. ->orderBy('name', 'ASC')
  51. ->get();
  52. $grad_grouped_courses = Course::
  53. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  54. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  55. ->with('semester')
  56. ->with('program')
  57. ->whereIn('courses.program_id', $program_ids)
  58. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  59. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  60. ->where('programs.is_graduate', '=', 1)
  61. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  62. ->orderBy('courses.code')
  63. ->orderBy('courses.number')
  64. ->orderBy('courses.semester_id')
  65. ->get();
  66. $undergrad_grouped_courses = Course::
  67. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  68. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  69. ->with('semester')
  70. ->with('program')
  71. ->whereIn('courses.program_id', $program_ids)
  72. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  73. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  74. ->where('programs.is_graduate', '=', 0)
  75. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  76. ->orderBy('courses.code')
  77. ->orderBy('courses.number')
  78. ->orderBy('courses.semester_id')
  79. ->get();
  80. foreach ($undergrad_grouped_courses as $key => $courses) {
  81. $undergrad_grouped_courses[$key]->outcomes_attempted = NULL;
  82. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  83. foreach ($coursesT as $course) {
  84. if ($course->isAssessed()) {
  85. $undergrad_grouped_courses[$key]->outcomes_attempted = true;
  86. }
  87. }
  88. }
  89. foreach ($grad_grouped_courses as $key => $courses) {
  90. $grad_grouped_courses[$key]->outcomes_attempted = NULL;
  91. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  92. foreach ($coursesT as $course) {
  93. if ($course->isAssessed()) {
  94. $grad_grouped_courses[$key]->outcomes_attempted = true;
  95. }
  96. }
  97. }
  98. // Fetch programs with participation
  99. $participating_programs = $this->participatingPrograms($school);
  100. /**
  101. * Calculate how many sections are doing assessment
  102. */
  103. $undergrad_assessed_sections_count = 0;
  104. $undergrad_school_sections_count = 0;
  105. $grad_assessed_sections_count = 0;
  106. $grad_school_sections_count = 0;
  107. foreach ($school->programs as $program) {
  108. foreach ($program->courses as $course) {
  109. if (!$course->program->is_graduate) {
  110. $undergrad_school_sections_count += 1;
  111. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  112. } else {
  113. $grad_school_sections_count += 1;
  114. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  115. }
  116. }
  117. }
  118. /**
  119. * Calculate how many programs achieved and attempted each outcome in this school
  120. */
  121. // For each outcome
  122. foreach ($outcomes_undergrad as $outcome) {
  123. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  124. // $achieved_outcomes_per_undergrad_program[$outcome->id]=0;
  125. $attemptedUndergradProgramsPerOutcome[$outcome->id] = 0;
  126. $achievedUndergradProgramsPerOutcome[$outcome->id] = 0;
  127. $programs_attempted_in_school[$outcome->id] = $outcome->programs_attempted_in_school($semesters, $school->id);
  128. // var_dump($programs_attempted_in_school);exit();
  129. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  130. // var_dump($program_id->id);exit();
  131. $program = DB::table('programs')->where('id', '=', $program_id->id)->first();
  132. if (!$program->is_graduate) {
  133. $attemptedUndergradProgramsPerOutcome[$outcome->id]++;
  134. $programC = Program::where('id', '=', $program_id->id)->first();
  135. // var_dump($programC);exit();
  136. if ($programC->achieved_outcome($outcome->id, $semesters)) {
  137. $achievedUndergradProgramsPerOutcome[$outcome->id]++;
  138. }
  139. }
  140. }
  141. $undergrad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 0);
  142. $undergrad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 0);
  143. // For each program with courses that do assessment
  144. $programs_with_courses = Program::with(array('courses' => function ($query) {
  145. // $query->whereNotNull('outcomes_attempted');
  146. $query->whereIn('semester_id', Session::get('semesters_ids'));
  147. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  148. }
  149. /**
  150. * Calculate how many programs achieved and attempted each outcome in this school
  151. */
  152. // For each outcome
  153. foreach ($outcomes_grad as $outcome) {
  154. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  155. $achieved_outcomes_per_grad_program[$outcome->id] = 0;
  156. $attemptedGradProgramsPerOutcome[$outcome->id] = 0;
  157. $achievedGradProgramsPerOutcome[$outcome->id] = 0;
  158. $grad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 1);
  159. $grad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 1);
  160. // For each program with courses that do assessment
  161. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  162. // var_dump($program_id->id);exit();
  163. $program = DB::table('programs')
  164. ->where('id', '=', $program_id->id)
  165. ->first();
  166. // $program=Program::where('id', $program_id->id);
  167. // var_dump($program);exit();
  168. if ($program->is_graduate) {
  169. $attemptedGradProgramsPerOutcome[$outcome->id]++;
  170. $programC = Program::where('id', '=', $program_id->id)->first();
  171. // var_dump($programC);exit();
  172. if ($programC->achieved_outcome($outcome->id, $semesters)) {
  173. $achievedGradProgramsPerOutcome[$outcome->id]++;
  174. }
  175. }
  176. }
  177. $programs_with_courses = Program::with(array('courses' => function ($query) {
  178. // $query->whereNotNull('outcomes_attempted');
  179. $query->whereIn('semester_id', Session::get('semesters_ids'));
  180. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  181. }
  182. if ($school->id == 13) {
  183. // return View::make('local.managers.shared.school-uhs', compact('title', 'outcomes', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs', 'participating_undergrad_programs', 'participating_grad_programs'));
  184. return View::make('local.managers.shared.school-uhs', compact('title', 'outcomes_grad', 'outcomes_undergrad', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs'));
  185. } else {
  186. // return View::make('local.managers.shared.school', compact('title', 'outcomes', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs', 'participating_undergrad_programs', 'participating_grad_programs'));
  187. return View::make('local.managers.shared.schoolTest', compact('title', 'outcomes_grad', 'outcomes_undergrad', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs'));
  188. }
  189. }
  190. public function overview()
  191. {
  192. ini_set('memory_limit', '256M');
  193. DB::connection()->disableQueryLog();
  194. // $school = School::find($id);
  195. $school = Auth::user()->school;
  196. $id = $school->id;
  197. $title = $school->name;
  198. $schools = School::all();
  199. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  200. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  201. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  202. /**
  203. * List of grouped courses (grouped sections)
  204. */
  205. $program_ids = $school->programs->lists('id');
  206. $undergrad_programs = DB::table('programs')
  207. ->select('id', 'name', 'school_id', 'is_graduate')
  208. ->where('is_graduate', '=', 0)
  209. ->where('school_id', '=', $id)
  210. ->orderBy('name', 'ASC')
  211. ->get();
  212. $grad_programs = DB::table('programs')
  213. ->select('id', 'name', 'school_id', 'is_graduate')
  214. ->where('is_graduate', '=', 1)
  215. ->where('school_id', '=', $id)
  216. ->orderBy('name', 'ASC')
  217. ->get();
  218. $grad_grouped_courses = Course::
  219. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  220. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  221. ->with('semester')
  222. ->with('program')
  223. ->whereIn('courses.program_id', $program_ids)
  224. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  225. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  226. ->where('programs.is_graduate', '=', 1)
  227. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  228. ->orderBy('courses.code')
  229. ->orderBy('courses.number')
  230. ->orderBy('courses.semester_id')
  231. ->get();
  232. $undergrad_grouped_courses = Course::
  233. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  234. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  235. ->with('semester')
  236. ->with('program')
  237. ->whereIn('courses.program_id', $program_ids)
  238. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  239. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  240. ->where('programs.is_graduate', '=', 0)
  241. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  242. ->orderBy('courses.code')
  243. ->orderBy('courses.number')
  244. ->orderBy('courses.semester_id')
  245. ->get();
  246. foreach ($undergrad_grouped_courses as $key => $courses) {
  247. $undergrad_grouped_courses[$key]->outcomes_attempted = NULL;
  248. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  249. foreach ($coursesT as $course) {
  250. if ($course->isAssessed()) {
  251. $undergrad_grouped_courses[$key]->outcomes_attempted = true;
  252. }
  253. }
  254. }
  255. foreach ($grad_grouped_courses as $key => $courses) {
  256. $grad_grouped_courses[$key]->outcomes_attempted = NULL;
  257. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  258. foreach ($coursesT as $course) {
  259. if ($course->isAssessed()) {
  260. $grad_grouped_courses[$key]->outcomes_attempted = true;
  261. }
  262. }
  263. }
  264. // Fetch programs with participation
  265. $participating_programs = $this->participatingPrograms($school);
  266. /**
  267. * Calculate how many sections are doing assessment
  268. */
  269. $undergrad_assessed_sections_count = 0;
  270. $undergrad_school_sections_count = 0;
  271. $grad_assessed_sections_count = 0;
  272. $grad_school_sections_count = 0;
  273. foreach ($school->programs as $program) {
  274. foreach ($program->courses as $course) {
  275. if (!$course->program->is_graduate) {
  276. $undergrad_school_sections_count += 1;
  277. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  278. } else {
  279. $grad_school_sections_count += 1;
  280. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  281. }
  282. }
  283. }
  284. /**
  285. * Calculate how many programs achieved and attempted each outcome in this school
  286. */
  287. // For each outcome
  288. foreach ($outcomes_undergrad as $outcome) {
  289. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  290. // $achieved_outcomes_per_undergrad_program[$outcome->id]=0;
  291. $attemptedUndergradProgramsPerOutcome[$outcome->id] = 0;
  292. $achievedUndergradProgramsPerOutcome[$outcome->id] = 0;
  293. $programs_attempted_in_school[$outcome->id] = $outcome->programs_attempted_in_school($semesters, $school->id);
  294. // var_dump($programs_attempted_in_school);exit();
  295. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  296. // var_dump($program_id->id);exit();
  297. $program = DB::table('programs')->where('id', '=', $program_id->id)->first();
  298. if (!$program->is_graduate) {
  299. $attemptedUndergradProgramsPerOutcome[$outcome->id]++;
  300. $programC = Program::where('id', '=', $program_id->id)->first();
  301. // var_dump($programC);exit();
  302. if ($programC->achieved_outcome($outcome->id, $semesters)) {
  303. $achievedUndergradProgramsPerOutcome[$outcome->id]++;
  304. }
  305. }
  306. }
  307. $undergrad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 0);
  308. $undergrad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 0);
  309. // For each program with courses that do assessment
  310. $programs_with_courses = Program::with(array('courses' => function ($query) {
  311. // $query->whereNotNull('outcomes_attempted');
  312. $query->whereIn('semester_id', Session::get('semesters_ids'));
  313. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  314. }
  315. /**
  316. * Calculate how many programs achieved and attempted each outcome in this school
  317. */
  318. // For each outcome
  319. foreach ($outcomes_grad as $outcome) {
  320. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  321. $achieved_outcomes_per_grad_program[$outcome->id] = 0;
  322. $attemptedGradProgramsPerOutcome[$outcome->id] = 0;
  323. $achievedGradProgramsPerOutcome[$outcome->id] = 0;
  324. $grad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 1);
  325. $grad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 1);
  326. // For each program with courses that do assessment
  327. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  328. // var_dump($program_id->id);exit();
  329. $program = DB::table('programs')
  330. ->where('id', '=', $program_id->id)
  331. ->first();
  332. // $program=Program::where('id', $program_id->id);
  333. // var_dump($program);exit();
  334. if ($program->is_graduate) {
  335. $attemptedGradProgramsPerOutcome[$outcome->id]++;
  336. $programC = Program::where('id', '=', $program_id->id)->first();
  337. // var_dump($programC);exit();
  338. if ($programC->achieved_outcome($outcome->id, $semesters)) {
  339. $achievedGradProgramsPerOutcome[$outcome->id]++;
  340. }
  341. }
  342. }
  343. $programs_with_courses = Program::with(array('courses' => function ($query) {
  344. // $query->whereNotNull('outcomes_attempted');
  345. $query->whereIn('semester_id', Session::get('semesters_ids'));
  346. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  347. }
  348. if ($school->id == 13) {
  349. // return View::make('local.managers.shared.school-uhs', compact('title', 'outcomes', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs', 'participating_undergrad_programs', 'participating_grad_programs'));
  350. return View::make('local.managers.shared.school-uhs', compact('title', 'outcomes_grad', 'outcomes_undergrad', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs'));
  351. } else {
  352. // return View::make('local.managers.shared.school', compact('title', 'outcomes', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs', 'participating_undergrad_programs', 'participating_grad_programs'));
  353. return View::make('local.managers.shared.school', compact('title', 'outcomes_grad', 'outcomes_undergrad', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs'));
  354. }
  355. }
  356. public function overviewOri()
  357. {
  358. DB::disableQueryLog();
  359. Log::debug('user' . Auth::user()->id);
  360. //TODO Find a better way to prevent non-scoords from reaching the page
  361. switch (Auth::user()->role) {
  362. case 1:
  363. return Redirect::to('administrator');
  364. break;
  365. case 3:
  366. return Redirect::to('program-coordinator');
  367. break;
  368. }
  369. $schools = School::orderBy('name', 'asc')->get();
  370. $school = Auth::user()->school;
  371. $title = $school->name . ' ' . 'Overview';
  372. $id = $school->id;
  373. $outcomes = Outcome::orderBy('name', 'asc')->get();
  374. $outcomeCount = Outcome::all()->count();
  375. /**
  376. * List of grouped courses (grouped sections)
  377. */
  378. $program_ids = $school->programs->lists('id');
  379. $undergrad_programs = DB::table('programs')
  380. ->select('id', 'name', 'school_id', 'is_graduate')
  381. ->where('is_graduate', '=', 0)
  382. ->where('school_id', '=', $id)
  383. ->orderBy('name', 'ASC')
  384. ->get();
  385. $grad_programs = DB::table('programs')
  386. ->select('id', 'name', 'school_id', 'is_graduate')
  387. ->where('is_graduate', '=', 1)
  388. ->where('school_id', '=', $id)
  389. ->orderBy('name', 'ASC')
  390. ->get();
  391. /*$grad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  392. ->with('semester')
  393. ->with('program')
  394. ->whereIn('courses.program_id', $program_ids)
  395. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  396. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  397. ->where('programs.is_graduate', '=', 1)
  398. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  399. ->orderBy('courses.code')
  400. ->orderBy('courses.number')
  401. ->orderBy('courses.semester_id')
  402. ->get();*/
  403. $grad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  404. ->with('semester')
  405. ->with('program')
  406. ->whereIn('courses.program_id', $program_ids)
  407. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  408. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  409. ->where('programs.is_graduate', '=', 1)
  410. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  411. ->orderBy('courses.code')
  412. ->orderBy('courses.number')
  413. ->orderBy('courses.semester_id')
  414. ->get();
  415. /*$undergrad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  416. ->with('semester')
  417. ->with('program')
  418. ->whereIn('courses.program_id', $program_ids)
  419. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  420. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  421. ->where('programs.is_graduate', '=', 0)
  422. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  423. ->orderBy('courses.code')
  424. ->orderBy('courses.number')
  425. ->orderBy('courses.semester_id')
  426. ->get();*/
  427. $undergrad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  428. ->with('semester')
  429. ->with('program')
  430. ->whereIn('courses.program_id', $program_ids)
  431. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  432. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  433. ->where('programs.is_graduate', '=', 0)
  434. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  435. ->orderBy('courses.code')
  436. ->orderBy('courses.number')
  437. ->orderBy('courses.semester_id')
  438. ->get();
  439. // Fetch programs with participation
  440. $participating_programs = $this->participatingPrograms($school);
  441. /**
  442. * Calculate how many sections are doing assessment
  443. */
  444. $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  445. $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  446. $undergrad_assessed_sections_count = 0;
  447. $undergrad_school_sections_count = 0;
  448. $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  449. $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  450. $grad_assessed_sections_count = 0;
  451. $grad_school_sections_count = 0;
  452. /*
  453. foreach ($school->programs as $program) {
  454. foreach ($program->courses as $course) {
  455. if (!$course->program->is_graduate) {
  456. if ($course->outcomes_achieved != NULL) {
  457. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  458. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  459. for ($i = 1; $i <= count($undergrad_outcomes_attempted); $i++) {
  460. $undergrad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  461. $undergrad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  462. }
  463. $undergrad_assessed_sections_count += 1;
  464. }
  465. $undergrad_school_sections_count += 1;
  466. } else {
  467. if ($course->outcomes_achieved != NULL) {
  468. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  469. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  470. for ($i = 1; $i <= count($grad_outcomes_attempted); $i++) {
  471. $grad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  472. $grad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  473. }
  474. $grad_assessed_sections_count += 1;
  475. }
  476. $grad_school_sections_count += 1;
  477. }
  478. }
  479. }
  480. */
  481. foreach ($school->programs as $program) {
  482. foreach ($program->courses as $course) {
  483. if (!$course->program->is_graduate) {
  484. $undergrad_school_sections_count += 1;
  485. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  486. // Log::info("aqui".$course);
  487. } else {
  488. $grad_school_sections_count += 1;
  489. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  490. // Log::info("aqui".$course);
  491. }
  492. //
  493. // if (!$course->program->is_graduate) {
  494. // if ($course_outcomes_achieved = $course->outcomes_ach()) {
  495. // //$course_outcomes_achieved = $course->outcomes_ach();
  496. // $course_outcomes_attempted = $course->outcomes_att();
  497. // foreach ($course_outcomes_attempted as $i => $score) {
  498. //
  499. // $undergrad_outcomes_attempted[$i] += $score;
  500. // }
  501. // foreach ($course_outcomes_achieved as $i => $score) {
  502. // $undergrad_outcomes_achieved[$i] += $score;
  503. // }
  504. // $undergrad_assessed_sections_count += 1;
  505. // }
  506. // $undergrad_school_sections_count += 1;
  507. // } else {
  508. // if ($course_outcomes_achieved = $course->outcomes_ach()) {
  509. // //$course_outcomes_achieved = $course->outcomes_ach();
  510. // $course_outcomes_attempted = $course->outcomes_att();
  511. // foreach ($course_outcomes_attempted as $i => $score) {
  512. //
  513. // $grad_outcomes_attempted[$i] += $score;
  514. // }
  515. // foreach ($course_outcomes_achieved as $i => $score) {
  516. // $grad_outcomes_achieved[$i] += $score;
  517. // }
  518. // $grad_assessed_sections_count += 1;
  519. // }
  520. // $grad_school_sections_count += 1;
  521. // }
  522. }
  523. }
  524. /**
  525. * Calculate how many programs achieved and attempted each outcome in this school
  526. */
  527. // Number of programs that achieved a particular learning outcome
  528. $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  529. // Number of programs that attempted a particular learning outcome
  530. $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  531. // Fetch programs with participation for the school
  532. // $participating_undergrad_programs = DB::table('programs')
  533. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  534. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  535. // ->addSelect('courses.semester_id')
  536. // ->whereIn('semester_id', Session::get('semesters_ids'))
  537. // ->where('is_graduate', 0)
  538. // ->where('school_id', $school->id)
  539. // ->groupBy('id')
  540. // ->get();
  541. $output = array();
  542. // For each outcome
  543. foreach ($outcomes as $outcome) {
  544. // For each program with courses that do assessment
  545. $programs_with_courses = Program::with(array('courses' => function ($query) {
  546. // $query->whereNotNull('outcomes_attempted');
  547. $query->whereIn('semester_id', Session::get('semesters_ids'));
  548. $query->join('activities', 'activities.course_id', '=', 'courses.id')
  549. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  550. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  551. ->where('activities.draft', 0)
  552. ->where('activities.diagnostic', 0)
  553. ->select('courses.*')->distinct();
  554. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  555. foreach ($programs_with_courses as $program) {
  556. if (in_array($program->id, $participating_programs)) {
  557. // To acummulate all criteria for one program
  558. $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  559. $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  560. //Flag for counting programs
  561. $flag = false;
  562. // For each course in the program
  563. foreach ($program->courses as $course) {
  564. // If the outcome in question is being evaluated
  565. $course_outcomes_attempted2 = $course->outcomes_att(); //json_decode($course->outcomes_attempted, true);
  566. $course_outcomes_achieved2 = $course->outcomes_ach(); //json_decode($course->outcomes_achieved, true);
  567. if (
  568. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  569. && $course_outcomes_attempted2[$outcome->id] > 0
  570. ) {
  571. $achieved_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  572. $attempted_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  573. // Add one to the programs assessing, if it wasn't added before
  574. if (!$flag) {
  575. $attemptedUndergradProgramsPerOutcome[$outcome->id] += 1;
  576. $flag = true;
  577. }
  578. }
  579. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  580. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  581. }
  582. //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
  583. 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) {
  584. $achievedUndergradProgramsPerOutcome[$outcome->id] += 1;
  585. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  586. }
  587. }
  588. }
  589. }
  590. /**
  591. * Calculate how many programs achieved and attempted each outcome in this school
  592. */
  593. // Number of programs that achieved a particular learning outcome
  594. $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  595. // Number of programs that attempted a particular learning outcome
  596. $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  597. // Fetch programs with participation for the school
  598. // $participating_grad_programs = DB::table('programs')
  599. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  600. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  601. // ->addSelect('courses.semester_id')
  602. // ->whereIn('semester_id', Session::get('semesters_ids'))
  603. // ->where('is_graduate', 1)
  604. // ->where('school_id', $school->id)
  605. // ->groupBy('id')
  606. // ->get();
  607. $output = array();
  608. // For each outcome
  609. foreach ($outcomes as $outcome) {
  610. // For each program with courses that do assessment
  611. $programs_with_courses = Program::with(array('courses' => function ($query) {
  612. //$query->whereNotNull('outcomes_attempted');
  613. $query->whereIn('semester_id', Session::get('semesters_ids'));
  614. $query->join('activities', 'activities.course_id', '=', 'courses.id')
  615. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  616. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  617. ->where('activities.draft', 0)
  618. ->where('activities.diagnostic', 0)
  619. ->select('courses.*')->distinct();
  620. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  621. foreach ($programs_with_courses as $program) {
  622. if (in_array($program->id, $participating_programs)) {
  623. // To acummulate all criteria for one program
  624. $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  625. $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  626. //Flag for counting programs
  627. $flag = false;
  628. // For each course in the program
  629. foreach ($program->courses as $course) {
  630. // If the outcome in question is being evaluated
  631. $course_outcomes_attempted2 = $course->outcomes_att(); // json_decode($course->outcomes_attempted, true);
  632. $course_outcomes_achieved2 = $course->outcomes_ach(); //json_decode($course->outcomes_achieved, true);
  633. if (
  634. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  635. && $course_outcomes_attempted2[$outcome->id] > 0
  636. ) {
  637. $achieved_outcomes_per_grad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  638. $attempted_outcomes_per_grad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  639. // Add one to the programs assessing, if it wasn't added before
  640. if (!$flag) {
  641. $attemptedGradProgramsPerOutcome[$outcome->id] += 1;
  642. $flag = true;
  643. }
  644. }
  645. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_program);
  646. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  647. }
  648. //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
  649. 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) {
  650. $achievedGradProgramsPerOutcome[$outcome->id] += 1;
  651. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  652. }
  653. }
  654. }
  655. }
  656. // return View::make('local.managers.shared.school', compact('title', 'outcomes', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs', 'participating_undergrad_programs', 'participating_grad_programs'));
  657. return View::make('local.managers.shared.school', compact('title', 'outcomes', 'undergrad_programs', 'grad_programs', 'undergrad_outcomes_attempted', 'grad_outcomes_attempted', 'undergrad_outcomes_achieved', 'grad_outcomes_achieved', 'schools', 'school', 'undergrad_assessed_sections_count', 'grad_assessed_sections_count', 'undergrad_school_sections_count', 'grad_school_sections_count', 'achievedUndergradProgramsPerOutcome', 'achievedGradProgramsPerOutcome', 'attemptedUndergradProgramsPerOutcome', 'attemptedGradProgramsPerOutcome', 'grad_grouped_courses', 'undergrad_grouped_courses', 'participating_programs'));
  658. }
  659. }