Sin descripción

SchoolCoordinatorsController.php 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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()
  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.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'));
  188. }
  189. }
  190. public function overviewOri()
  191. {
  192. DB::disableQueryLog();
  193. Log::debug('user' . Auth::user()->id);
  194. //TODO Find a better way to prevent non-scoords from reaching the page
  195. switch (Auth::user()->role) {
  196. case 1:
  197. return Redirect::to('administrator');
  198. break;
  199. case 3:
  200. return Redirect::to('program-coordinator');
  201. break;
  202. }
  203. $schools = School::orderBy('name', 'asc')->get();
  204. $school = Auth::user()->school;
  205. $title = $school->name . ' ' . 'Overview';
  206. $id = $school->id;
  207. $outcomes = Outcome::orderBy('name', 'asc')->get();
  208. $outcomeCount = Outcome::all()->count();
  209. /**
  210. * List of grouped courses (grouped sections)
  211. */
  212. $program_ids = $school->programs->lists('id');
  213. $undergrad_programs = DB::table('programs')
  214. ->select('id', 'name', 'school_id', 'is_graduate')
  215. ->where('is_graduate', '=', 0)
  216. ->where('school_id', '=', $id)
  217. ->orderBy('name', 'ASC')
  218. ->get();
  219. $grad_programs = DB::table('programs')
  220. ->select('id', 'name', 'school_id', 'is_graduate')
  221. ->where('is_graduate', '=', 1)
  222. ->where('school_id', '=', $id)
  223. ->orderBy('name', 'ASC')
  224. ->get();
  225. /*$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'))
  226. ->with('semester')
  227. ->with('program')
  228. ->whereIn('courses.program_id', $program_ids)
  229. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  230. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  231. ->where('programs.is_graduate', '=', 1)
  232. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  233. ->orderBy('courses.code')
  234. ->orderBy('courses.number')
  235. ->orderBy('courses.semester_id')
  236. ->get();*/
  237. $grad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  238. ->with('semester')
  239. ->with('program')
  240. ->whereIn('courses.program_id', $program_ids)
  241. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  242. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  243. ->where('programs.is_graduate', '=', 1)
  244. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  245. ->orderBy('courses.code')
  246. ->orderBy('courses.number')
  247. ->orderBy('courses.semester_id')
  248. ->get();
  249. /*$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'))
  250. ->with('semester')
  251. ->with('program')
  252. ->whereIn('courses.program_id', $program_ids)
  253. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  254. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  255. ->where('programs.is_graduate', '=', 0)
  256. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  257. ->orderBy('courses.code')
  258. ->orderBy('courses.number')
  259. ->orderBy('courses.semester_id')
  260. ->get();*/
  261. $undergrad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  262. ->with('semester')
  263. ->with('program')
  264. ->whereIn('courses.program_id', $program_ids)
  265. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  266. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  267. ->where('programs.is_graduate', '=', 0)
  268. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  269. ->orderBy('courses.code')
  270. ->orderBy('courses.number')
  271. ->orderBy('courses.semester_id')
  272. ->get();
  273. // Fetch programs with participation
  274. $participating_programs = $this->participatingPrograms($school);
  275. /**
  276. * Calculate how many sections are doing assessment
  277. */
  278. $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  279. $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  280. $undergrad_assessed_sections_count = 0;
  281. $undergrad_school_sections_count = 0;
  282. $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  283. $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  284. $grad_assessed_sections_count = 0;
  285. $grad_school_sections_count = 0;
  286. /*
  287. foreach ($school->programs as $program) {
  288. foreach ($program->courses as $course) {
  289. if (!$course->program->is_graduate) {
  290. if ($course->outcomes_achieved != NULL) {
  291. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  292. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  293. for ($i = 1; $i <= count($undergrad_outcomes_attempted); $i++) {
  294. $undergrad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  295. $undergrad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  296. }
  297. $undergrad_assessed_sections_count += 1;
  298. }
  299. $undergrad_school_sections_count += 1;
  300. } else {
  301. if ($course->outcomes_achieved != NULL) {
  302. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  303. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  304. for ($i = 1; $i <= count($grad_outcomes_attempted); $i++) {
  305. $grad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  306. $grad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  307. }
  308. $grad_assessed_sections_count += 1;
  309. }
  310. $grad_school_sections_count += 1;
  311. }
  312. }
  313. }
  314. */
  315. foreach ($school->programs as $program) {
  316. foreach ($program->courses as $course) {
  317. if (!$course->program->is_graduate) {
  318. $undergrad_school_sections_count += 1;
  319. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  320. // Log::info("aqui".$course);
  321. } else {
  322. $grad_school_sections_count += 1;
  323. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  324. // Log::info("aqui".$course);
  325. }
  326. //
  327. // if (!$course->program->is_graduate) {
  328. // if ($course_outcomes_achieved = $course->outcomes_ach()) {
  329. // //$course_outcomes_achieved = $course->outcomes_ach();
  330. // $course_outcomes_attempted = $course->outcomes_att();
  331. // foreach ($course_outcomes_attempted as $i => $score) {
  332. //
  333. // $undergrad_outcomes_attempted[$i] += $score;
  334. // }
  335. // foreach ($course_outcomes_achieved as $i => $score) {
  336. // $undergrad_outcomes_achieved[$i] += $score;
  337. // }
  338. // $undergrad_assessed_sections_count += 1;
  339. // }
  340. // $undergrad_school_sections_count += 1;
  341. // } else {
  342. // if ($course_outcomes_achieved = $course->outcomes_ach()) {
  343. // //$course_outcomes_achieved = $course->outcomes_ach();
  344. // $course_outcomes_attempted = $course->outcomes_att();
  345. // foreach ($course_outcomes_attempted as $i => $score) {
  346. //
  347. // $grad_outcomes_attempted[$i] += $score;
  348. // }
  349. // foreach ($course_outcomes_achieved as $i => $score) {
  350. // $grad_outcomes_achieved[$i] += $score;
  351. // }
  352. // $grad_assessed_sections_count += 1;
  353. // }
  354. // $grad_school_sections_count += 1;
  355. // }
  356. }
  357. }
  358. /**
  359. * Calculate how many programs achieved and attempted each outcome in this school
  360. */
  361. // Number of programs that achieved a particular learning outcome
  362. $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  363. // Number of programs that attempted a particular learning outcome
  364. $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  365. // Fetch programs with participation for the school
  366. // $participating_undergrad_programs = DB::table('programs')
  367. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  368. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  369. // ->addSelect('courses.semester_id')
  370. // ->whereIn('semester_id', Session::get('semesters_ids'))
  371. // ->where('is_graduate', 0)
  372. // ->where('school_id', $school->id)
  373. // ->groupBy('id')
  374. // ->get();
  375. $output = array();
  376. // For each outcome
  377. foreach ($outcomes as $outcome) {
  378. // For each program with courses that do assessment
  379. $programs_with_courses = Program::with(array('courses' => function ($query) {
  380. // $query->whereNotNull('outcomes_attempted');
  381. $query->whereIn('semester_id', Session::get('semesters_ids'));
  382. $query->join('activities', 'activities.course_id', '=', 'courses.id')
  383. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  384. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  385. ->where('activities.draft', 0)
  386. ->where('activities.diagnostic', 0)
  387. ->select('courses.*')->distinct();
  388. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  389. foreach ($programs_with_courses as $program) {
  390. if (in_array($program->id, $participating_programs)) {
  391. // To acummulate all criteria for one program
  392. $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  393. $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  394. //Flag for counting programs
  395. $flag = false;
  396. // For each course in the program
  397. foreach ($program->courses as $course) {
  398. // If the outcome in question is being evaluated
  399. $course_outcomes_attempted2 = $course->outcomes_att(); //json_decode($course->outcomes_attempted, true);
  400. $course_outcomes_achieved2 = $course->outcomes_ach(); //json_decode($course->outcomes_achieved, true);
  401. if (
  402. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  403. && $course_outcomes_attempted2[$outcome->id] > 0
  404. ) {
  405. $achieved_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  406. $attempted_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  407. // Add one to the programs assessing, if it wasn't added before
  408. if (!$flag) {
  409. $attemptedUndergradProgramsPerOutcome[$outcome->id] += 1;
  410. $flag = true;
  411. }
  412. }
  413. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  414. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  415. }
  416. //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
  417. 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) {
  418. $achievedUndergradProgramsPerOutcome[$outcome->id] += 1;
  419. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  420. }
  421. }
  422. }
  423. }
  424. /**
  425. * Calculate how many programs achieved and attempted each outcome in this school
  426. */
  427. // Number of programs that achieved a particular learning outcome
  428. $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  429. // Number of programs that attempted a particular learning outcome
  430. $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  431. // Fetch programs with participation for the school
  432. // $participating_grad_programs = DB::table('programs')
  433. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  434. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  435. // ->addSelect('courses.semester_id')
  436. // ->whereIn('semester_id', Session::get('semesters_ids'))
  437. // ->where('is_graduate', 1)
  438. // ->where('school_id', $school->id)
  439. // ->groupBy('id')
  440. // ->get();
  441. $output = array();
  442. // For each outcome
  443. foreach ($outcomes as $outcome) {
  444. // For each program with courses that do assessment
  445. $programs_with_courses = Program::with(array('courses' => function ($query) {
  446. //$query->whereNotNull('outcomes_attempted');
  447. $query->whereIn('semester_id', Session::get('semesters_ids'));
  448. $query->join('activities', 'activities.course_id', '=', 'courses.id')
  449. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  450. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  451. ->where('activities.draft', 0)
  452. ->where('activities.diagnostic', 0)
  453. ->select('courses.*')->distinct();
  454. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  455. foreach ($programs_with_courses as $program) {
  456. if (in_array($program->id, $participating_programs)) {
  457. // To acummulate all criteria for one program
  458. $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  459. $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  460. //Flag for counting programs
  461. $flag = false;
  462. // For each course in the program
  463. foreach ($program->courses as $course) {
  464. // If the outcome in question is being evaluated
  465. $course_outcomes_attempted2 = $course->outcomes_att(); // json_decode($course->outcomes_attempted, true);
  466. $course_outcomes_achieved2 = $course->outcomes_ach(); //json_decode($course->outcomes_achieved, true);
  467. if (
  468. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  469. && $course_outcomes_attempted2[$outcome->id] > 0
  470. ) {
  471. $achieved_outcomes_per_grad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  472. $attempted_outcomes_per_grad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  473. // Add one to the programs assessing, if it wasn't added before
  474. if (!$flag) {
  475. $attemptedGradProgramsPerOutcome[$outcome->id] += 1;
  476. $flag = true;
  477. }
  478. }
  479. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_program);
  480. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  481. }
  482. //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
  483. 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) {
  484. $achievedGradProgramsPerOutcome[$outcome->id] += 1;
  485. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  486. }
  487. }
  488. }
  489. }
  490. // 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'));
  491. 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'));
  492. }
  493. }