Keine Beschreibung

SchoolsController.php 39KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. class SchoolsController 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 show($id)
  25. {
  26. ini_set('memory_limit', '256M');
  27. DB::connection()->disableQueryLog();
  28. $school = School::find($id);
  29. $title = $school->name;
  30. $schools = School::all();
  31. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  32. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  33. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  34. /**
  35. * List of grouped courses (grouped sections)
  36. */
  37. $program_ids = $school->programs->lists('id');
  38. $undergrad_programs = DB::table('programs')
  39. ->select('id', 'name', 'school_id', 'is_graduate')
  40. ->where('is_graduate', '=', 0)
  41. ->where('school_id', '=', $id)
  42. ->orderBy('name', 'ASC')
  43. ->get();
  44. $grad_programs = DB::table('programs')
  45. ->select('id', 'name', 'school_id', 'is_graduate')
  46. ->where('is_graduate', '=', 1)
  47. ->where('school_id', '=', $id)
  48. ->orderBy('name', 'ASC')
  49. ->get();
  50. $grad_grouped_courses = Course::
  51. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  52. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  53. ->with('semester')
  54. ->with('program')
  55. ->whereIn('courses.program_id', $program_ids)
  56. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  57. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  58. ->where('programs.is_graduate', '=', 1)
  59. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  60. ->orderBy('courses.code')
  61. ->orderBy('courses.number')
  62. ->orderBy('courses.semester_id')
  63. ->get();
  64. $undergrad_grouped_courses = Course::
  65. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  66. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  67. ->with('semester')
  68. ->with('program')
  69. ->whereIn('courses.program_id', $program_ids)
  70. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  71. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  72. ->where('programs.is_graduate', '=', 0)
  73. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  74. ->orderBy('courses.code')
  75. ->orderBy('courses.number')
  76. ->orderBy('courses.semester_id')
  77. ->get();
  78. foreach ($undergrad_grouped_courses as $key => $courses) {
  79. $undergrad_grouped_courses[$key]->outcomes_attempted = NULL;
  80. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  81. foreach ($coursesT as $course) {
  82. if ($course->isAssessed()) {
  83. $undergrad_grouped_courses[$key]->outcomes_attempted = true;
  84. }
  85. }
  86. }
  87. foreach ($grad_grouped_courses as $key => $courses) {
  88. $grad_grouped_courses[$key]->outcomes_attempted = NULL;
  89. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  90. foreach ($coursesT as $course) {
  91. if ($course->isAssessed()) {
  92. $grad_grouped_courses[$key]->outcomes_attempted = true;
  93. }
  94. }
  95. }
  96. // Fetch programs with participation
  97. $participating_programs = $this->participatingPrograms($school);
  98. /**
  99. * Calculate how many sections are doing assessment
  100. */
  101. $undergrad_assessed_sections_count = 0;
  102. $undergrad_school_sections_count = 0;
  103. $grad_assessed_sections_count = 0;
  104. $grad_school_sections_count = 0;
  105. foreach ($school->programs as $program) {
  106. foreach ($program->courses as $course) {
  107. if (!$course->program->is_graduate) {
  108. $undergrad_school_sections_count += 1;
  109. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  110. } else {
  111. $grad_school_sections_count += 1;
  112. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  113. }
  114. }
  115. }
  116. /**
  117. * Calculate how many programs achieved and attempted each outcome in this school
  118. */
  119. // For each outcome
  120. foreach ($outcomes_undergrad as $outcome) {
  121. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  122. // $achieved_outcomes_per_undergrad_program[$outcome->id]=0;
  123. $attemptedUndergradProgramsPerOutcome[$outcome->id] = 0;
  124. $achievedUndergradProgramsPerOutcome[$outcome->id] = 0;
  125. $programs_attempted_in_school[$outcome->id] = $outcome->programs_attempted_in_school($semesters, $school->id);
  126. // var_dump($programs_attempted_in_school);exit();
  127. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  128. // var_dump($program_id->id);exit();
  129. $program = DB::table('programs')->where('id', '=', $program_id->id)->first();
  130. if (!$program->is_graduate) {
  131. $attemptedUndergradProgramsPerOutcome[$outcome->id]++;
  132. $programC = Program::where('id', '=', $program_id->id)->first();
  133. // var_dump($programC);exit();
  134. if ($programC->achieved_outcome($outcome->id, $semesters)) {
  135. $achievedUndergradProgramsPerOutcome[$outcome->id]++;
  136. }
  137. }
  138. }
  139. $undergrad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 0);
  140. $undergrad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 0);
  141. // For each program with courses that do assessment
  142. $programs_with_courses = Program::with(array('courses' => function ($query) {
  143. // $query->whereNotNull('outcomes_attempted');
  144. $query->whereIn('semester_id', Session::get('semesters_ids'));
  145. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  146. }
  147. /**
  148. * Calculate how many Graduate programs achieved and attempted each outcome in this school
  149. */
  150. // For each outcome
  151. foreach ($outcomes_grad as $outcome) {
  152. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  153. $achieved_outcomes_per_grad_program[$outcome->id] = 0;
  154. $attemptedGradProgramsPerOutcome[$outcome->id] = 0;
  155. $achievedGradProgramsPerOutcome[$outcome->id] = 0;
  156. $grad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 1);
  157. $grad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 1);
  158. // For each program with courses that do assessment
  159. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  160. // var_dump($program_id->id);exit();
  161. $program = DB::table('programs')
  162. ->where('id', '=', $program_id->id)
  163. ->first();
  164. // $program=Program::where('id', $program_id->id);
  165. // var_dump($program);exit();
  166. if ($program->is_graduate) {
  167. $attemptedGradProgramsPerOutcome[$outcome->id]++;
  168. $programC = Program::where('id', '=', $program_id->id)->first();
  169. // var_dump($programC);exit();
  170. if ($programC->achieved_outcome($outcome->id, $semesters)) {
  171. $achievedGradProgramsPerOutcome[$outcome->id]++;
  172. }
  173. }
  174. }
  175. $programs_with_courses = Program::with(array('courses' => function ($query) {
  176. // $query->whereNotNull('outcomes_attempted');
  177. $query->whereIn('semester_id', Session::get('semesters_ids'));
  178. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  179. }
  180. if ($school->id == 13) {
  181. // 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'));
  182. 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'));
  183. } else {
  184. // 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'));
  185. 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'));
  186. }
  187. }
  188. public function showQuasiOri($id)
  189. {
  190. ini_set('memory_limit', '256M');
  191. DB::connection()->disableQueryLog();
  192. $school = School::find($id);
  193. $title = $school->name;
  194. $schools = School::all();
  195. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  196. // $outcomeCount = Outcome::all()->count();
  197. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  198. // var_dump($semesters);
  199. // exit();
  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. // Fetch programs with participation
  247. $participating_programs = $this->participatingPrograms($school);
  248. /**
  249. * Calculate how many sections are doing assessment
  250. */
  251. // $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  252. // $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  253. $undergrad_assessed_sections_count = 0;
  254. $undergrad_school_sections_count = 0;
  255. // $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  256. // $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  257. $grad_assessed_sections_count = 0;
  258. $grad_school_sections_count = 0;
  259. foreach ($school->programs as $program) {
  260. foreach ($program->courses as $course) {
  261. // Log::info("aqui".$course);
  262. if (!$course->program->is_graduate) {
  263. $undergrad_school_sections_count += 1;
  264. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  265. // Log::info("aqui".$course);
  266. } else {
  267. $grad_school_sections_count += 1;
  268. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  269. // Log::info("aqui".$course);
  270. }
  271. // if (!$course->program->is_graduate) {
  272. // if ($course->outcomes_achieved != NULL) {
  273. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  274. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  275. // for ($i = 1; $i <= count($undergrad_outcomes_attempted); $i++) {
  276. // $undergrad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  277. // $undergrad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  278. // }
  279. // $undergrad_assessed_sections_count += 1;
  280. // }
  281. // $undergrad_school_sections_count += 1;
  282. // } else {
  283. // if ($course->outcomes_achieved != NULL) {
  284. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  285. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  286. // for ($i = 1; $i <= count($grad_outcomes_attempted); $i++) {
  287. // $grad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  288. // $grad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  289. // }
  290. // $grad_assessed_sections_count += 1;
  291. // }
  292. // $grad_school_sections_count += 1;
  293. // }
  294. }
  295. }
  296. /**
  297. * Calculate how many programs achieved and attempted each outcome in this school
  298. */
  299. // Number of programs that achieved a particular learning outcome
  300. // $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  301. // Number of programs that attempted a particular learning outcome
  302. // $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  303. // Fetch programs with participation for the school
  304. // $participating_undergrad_programs = DB::table('programs')
  305. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  306. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  307. // ->addSelect('courses.semester_id')
  308. // ->whereIn('semester_id', Session::get('semesters_ids'))
  309. // ->where('is_graduate', 0)
  310. // ->where('school_id', $school->id)
  311. // ->groupBy('id')
  312. // ->get();
  313. $output = array();
  314. // For each outcome
  315. foreach ($outcomes_undergrad as $outcome) {
  316. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  317. $achieved_outcomes_per_undergrad_program[$outcome->id] = 0;
  318. $attemptedUndergradProgramsPerOutcome[$outcome->id] = 0;
  319. $achievedUndergradProgramsPerOutcome[$outcome->id] = 0;
  320. $programs_attempted_in_school[$outcome->id] = $outcome->programs_attempted_in_school($semesters, $school->id);
  321. // var_dump($programs_attempted_in_school);exit();
  322. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  323. // var_dump($program_id->id);exit();
  324. $program = DB::table('programs')
  325. ->where('id', '=', $program_id->id)
  326. ->first();
  327. // $program=Program::where('id', $program_id->id);
  328. // var_dump($program);exit();
  329. if (!$program->is_graduate) {
  330. $attemptedUndergradProgramsPerOutcome[$outcome->id]++;
  331. }
  332. }
  333. $undergrad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 0);
  334. $undergrad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 0);
  335. // For each program with courses that do assessment
  336. $programs_with_courses = Program::with(array('courses' => function ($query) {
  337. // $query->whereNotNull('outcomes_attempted');
  338. $query->whereIn('semester_id', Session::get('semesters_ids'));
  339. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  340. foreach ($programs_with_courses as $program) {
  341. if (in_array($program->id, $participating_programs)) {
  342. // To acummulate all criteria for one program
  343. // $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  344. // $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  345. //Flag for counting programs
  346. $flag = false;
  347. // For each course in the program
  348. // foreach ($program->courses as $course) {
  349. // if($course->isAssessed()){
  350. // // If the outcome in question is being evaluated
  351. // $course_outcomes_attempted2 = $course->outcomes_att();
  352. // // $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  353. // // $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  354. // $course_outcomes_achieved2 = $course->outcomes_ach();
  355. // if (
  356. // array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  357. // && $course_outcomes_attempted2[$outcome->id] > 0
  358. // ) {
  359. // $achieved_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  360. // // $attempted_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  361. //
  362. // // Add one to the programs assessing, if it wasn't added before
  363. // if (!$flag) {
  364. // $attemptedUndergradProgramsPerOutcome[$outcome->id] += 1;
  365. // $flag = true;
  366. // }
  367. // }
  368. //
  369. // // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  370. // // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  371. // }
  372. // }
  373. //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
  374. // 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) {
  375. // $achievedUndergradProgramsPerOutcome[$outcome->id] += 1;
  376. // // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  377. // }
  378. }
  379. }
  380. }
  381. /**
  382. * Calculate how many programs achieved and attempted each outcome in this school
  383. */
  384. // Number of programs that achieved a particular learning outcome
  385. // $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  386. // Number of programs that attempted a particular learning outcome
  387. // $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  388. //
  389. // Fetch programs with participation for the school
  390. // $participating_grad_programs = DB::table('programs')
  391. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  392. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  393. // ->addSelect('courses.semester_id')
  394. // ->whereIn('semester_id', Session::get('semesters_ids'))
  395. // ->where('is_graduate', 1)
  396. // ->where('school_id', $school->id)
  397. // ->groupBy('id')
  398. // ->get();
  399. $output = array();
  400. // For each outcome
  401. foreach ($outcomes_grad as $outcome) {
  402. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  403. $achieved_outcomes_per_grad_program[$outcome->id] = 0;
  404. $attemptedGradProgramsPerOutcome[$outcome->id] = 0;
  405. $achievedGradProgramsPerOutcome[$outcome->id] = 0;
  406. $grad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 1);
  407. $grad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 1);
  408. // For each program with courses that do assessment
  409. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  410. // var_dump($program_id->id);exit();
  411. $program = DB::table('programs')
  412. ->where('id', '=', $program_id->id)
  413. ->first();
  414. // $program=Program::where('id', $program_id->id);
  415. // var_dump($program);exit();
  416. if ($program->is_graduate) {
  417. $attemptedGradProgramsPerOutcome[$outcome->id]++;
  418. }
  419. }
  420. $programs_with_courses = Program::with(array('courses' => function ($query) {
  421. // $query->whereNotNull('outcomes_attempted');
  422. $query->whereIn('semester_id', Session::get('semesters_ids'));
  423. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  424. foreach ($programs_with_courses as $program) {
  425. if (in_array($program->id, $participating_programs)) {
  426. // To acummulate all criteria for one program
  427. // $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  428. // $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  429. //Flag for counting programs
  430. $flag = false;
  431. // For each course in the program
  432. foreach ($program->courses as $course) {
  433. if ($course->isAssessed()) {
  434. // If the outcome in question is being evaluated
  435. // $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  436. $course_outcomes_attempted2 = ($course->outcomes_att());
  437. $course_outcomes_achieved2 = ($course->outcomes_ach());
  438. // $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  439. if (
  440. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  441. && $course_outcomes_attempted2[$outcome->id] > 0
  442. ) {
  443. $achieved_outcomes_per_grad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  444. $attempted_outcomes_per_grad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  445. // Add one to the programs assessing, if it wasn't added before
  446. if (!$flag) {
  447. $attemptedGradProgramsPerOutcome[$outcome->id] += 1;
  448. $flag = true;
  449. }
  450. }
  451. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_program);
  452. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  453. }
  454. }
  455. //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
  456. 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) {
  457. $achievedGradProgramsPerOutcome[$outcome->id] += 1;
  458. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  459. }
  460. }
  461. }
  462. }
  463. if ($school->id == 13) {
  464. // 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'));
  465. 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'));
  466. } else {
  467. // 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'));
  468. 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'));
  469. }
  470. }
  471. public function print_school($id)
  472. {
  473. ini_set('memory_limit', '256M');
  474. DB::connection()->disableQueryLog();
  475. $school = School::find($id);
  476. $title = $school->name . ' Assessment Report - ' . date('m/d/Y');
  477. $outcomes = Outcome::orderBy('name', 'asc')->get();
  478. $outcomeCount = Outcome::all()->count();
  479. /**
  480. * List of courses (grouped sections)
  481. */
  482. $program_ids = $school->programs->lists('id');
  483. $grouped_courses = Course::
  484. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  485. select(DB::raw('name, code, number, semester_id, program_id'))
  486. ->with('semester')
  487. ->with('program')
  488. ->whereIn('program_id', $program_ids)
  489. ->whereIn('semester_id', Session::get('semesters_ids'))
  490. ->groupBy(array('code', 'number', 'semester_id'))
  491. ->orderBy('code')
  492. ->orderBy('number')
  493. ->orderBy('semester_id')
  494. ->get();
  495. // Fetch programs with participation
  496. $participating_programs = $this->participatingPrograms($school);
  497. /**
  498. * Calculate how many sections are doing assessment
  499. */
  500. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  501. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  502. $assessed_sections_count = 0;
  503. $school_sections_count = 0;
  504. foreach ($school->programs as $program) {
  505. foreach ($program->courses as $course) {
  506. if ($course->outcomes_achieved != NULL) {
  507. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  508. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  509. for ($i = 1; $i <= count($outcomes_attempted); $i++) {
  510. $outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  511. $outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  512. }
  513. $assessed_sections_count += 1;
  514. }
  515. $school_sections_count += 1;
  516. }
  517. }
  518. /**
  519. * Calculate how many programs achieved and attempted each outcome in this school
  520. */
  521. // Number of programs that achieved a particular learning outcome
  522. $achievedProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  523. // Number of programs that attempted a particular learning outcome
  524. $attemptedProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  525. $output = array();
  526. // For each outcome
  527. foreach ($outcomes as $outcome) {
  528. // For each program with courses that do assessment
  529. foreach (Program::with(array('courses' => function ($query) {
  530. // $query->whereNotNull('outcomes_attempted');
  531. $query->whereIn('semester_id', Session::get('semesters_ids'));
  532. }))->where('school_id', $school->id)->orderBy('name', 'asc')->get() as $program) {
  533. // To acummulate all criteria for one program
  534. $achieved_outcomes_per_program = array_fill(1, $outcomeCount, 0);
  535. $attempted_outcomes_per_program = array_fill(1, $outcomeCount, 0);
  536. //Flag for counting programs
  537. $flag = false;
  538. // For each course in the program
  539. foreach ($program->courses as $course) {
  540. // If the outcome in question is being evaluated
  541. $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  542. $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  543. if (
  544. array_key_exists($outcome->id, $course_outcomes_attempted2)
  545. && $course_outcomes_attempted2[$outcome->id] > 0
  546. ) {
  547. $achieved_outcomes_per_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  548. $attempted_outcomes_per_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  549. // Add one to the programs assessing, if it wasn't added before
  550. if (!$flag) {
  551. $attemptedProgramsPerOutcome[$outcome->id] += 1;
  552. $flag = true;
  553. }
  554. }
  555. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_program);
  556. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  557. }
  558. //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
  559. if ($attempted_outcomes_per_program[$outcome->id] != 0 && (float)$achieved_outcomes_per_program[$outcome->id] / $attempted_outcomes_per_program[$outcome->id] * 100 >= $outcome->expected_outcome) {
  560. $achievedProgramsPerOutcome[$outcome->id] += 1;
  561. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  562. }
  563. }
  564. }
  565. return View::make('local.managers.shared.print_school', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'school', 'assessed_sections_count', 'school_sections_count', 'achievedProgramsPerOutcome', 'attemptedProgramsPerOutcome', 'grouped_courses', 'participating_programs'));
  566. }
  567. }