Без опису

SchoolCoordinatorsController.php 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. {
  82. $undergrad_grouped_courses[$key]->outcomes_attempted=NULL;
  83. $coursesT=Course::where('courses.code',$courses->code)->where('courses.number',$courses->number)->where('courses.semester_id',$courses->semester_id)->get();
  84. foreach($coursesT as $course)
  85. {
  86. if($course->isAssessed())
  87. {
  88. $undergrad_grouped_courses[$key]->outcomes_attempted=true;
  89. }
  90. }
  91. }
  92. foreach($grad_grouped_courses as $key=>$courses)
  93. {
  94. $grad_grouped_courses[$key]->outcomes_attempted=NULL;
  95. $coursesT=Course::where('courses.code',$courses->code)->where('courses.number',$courses->number)->where('courses.semester_id',$courses->semester_id)->get();
  96. foreach($coursesT as $course)
  97. {
  98. if($course->isAssessed())
  99. {
  100. $grad_grouped_courses[$key]->outcomes_attempted=true;
  101. }
  102. }
  103. }
  104. // Fetch programs with participation
  105. $participating_programs = $this->participatingPrograms($school);
  106. /**
  107. * Calculate how many sections are doing assessment
  108. */
  109. $undergrad_assessed_sections_count = 0;
  110. $undergrad_school_sections_count = 0;
  111. $grad_assessed_sections_count = 0;
  112. $grad_school_sections_count = 0;
  113. foreach ($school->programs as $program) {
  114. foreach ($program->courses as $course) {
  115. if (!$course->program->is_graduate){
  116. $undergrad_school_sections_count += 1;
  117. if($course->isAssessed())$undergrad_assessed_sections_count += 1;
  118. }
  119. else {
  120. $grad_school_sections_count += 1;
  121. if($course->isAssessed())$grad_assessed_sections_count += 1;
  122. }
  123. }
  124. }
  125. /**
  126. * Calculate how many programs achieved and attempted each outcome in this school
  127. */
  128. // For each outcome
  129. foreach ($outcomes_undergrad as $outcome) {
  130. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  131. // $achieved_outcomes_per_undergrad_program[$outcome->id]=0;
  132. $attemptedUndergradProgramsPerOutcome[$outcome->id]=0;
  133. $achievedUndergradProgramsPerOutcome[$outcome->id]=0;
  134. $programs_attempted_in_school[$outcome->id]=$outcome->programs_attempted_in_school($semesters, $school->id);
  135. // var_dump($programs_attempted_in_school);exit();
  136. foreach($programs_attempted_in_school[$outcome->id] as $program_id)
  137. {
  138. // var_dump($program_id->id);exit();
  139. $program = DB::table('programs')->where('id', '=', $program_id->id)->first();
  140. if(!$program->is_graduate)
  141. {
  142. $attemptedUndergradProgramsPerOutcome[$outcome->id]++;
  143. $programC=Program::where('id', '=', $program_id->id)->first();
  144. // var_dump($programC);exit();
  145. if($programC->achieved_outcome($outcome->id,$semesters))
  146. {
  147. $achievedUndergradProgramsPerOutcome[$outcome->id]++;
  148. }
  149. }
  150. }
  151. $undergrad_outcomes_attempted[$outcome->id]=$outcome->attempted_by_school($semesters, $school->id,0);
  152. $undergrad_outcomes_achieved[$outcome->id]=$outcome->achieved_by_school($semesters, $school->id,0);
  153. // For each program with courses that do assessment
  154. $programs_with_courses = Program::with(array('courses' => function ($query) {
  155. // $query->whereNotNull('outcomes_attempted');
  156. $query->whereIn('semester_id', Session::get('semesters_ids'));
  157. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  158. }
  159. /**
  160. * Calculate how many programs achieved and attempted each outcome in this school
  161. */
  162. // For each outcome
  163. foreach ($outcomes_grad as $outcome) {
  164. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  165. $achieved_outcomes_per_grad_program[$outcome->id]=0;
  166. $attemptedGradProgramsPerOutcome[$outcome->id]=0;
  167. $achievedGradProgramsPerOutcome[$outcome->id]=0;
  168. $grad_outcomes_attempted[$outcome->id]=$outcome->attempted_by_school($semesters, $school->id,1);
  169. $grad_outcomes_achieved[$outcome->id]=$outcome->achieved_by_school($semesters, $school->id,1);
  170. // For each program with courses that do assessment
  171. foreach($programs_attempted_in_school[$outcome->id] as $program_id)
  172. {
  173. // var_dump($program_id->id);exit();
  174. $program = DB::table('programs')
  175. ->where('id', '=', $program_id->id)
  176. ->first();
  177. // $program=Program::where('id', $program_id->id);
  178. // var_dump($program);exit();
  179. if($program->is_graduate)
  180. {
  181. $attemptedGradProgramsPerOutcome[$outcome->id]++;
  182. $programC=Program::where('id', '=', $program_id->id)->first();
  183. // var_dump($programC);exit();
  184. if($programC->achieved_outcome($outcome->id,$semesters))
  185. {
  186. $achievedGradProgramsPerOutcome[$outcome->id]++;
  187. }
  188. }
  189. }
  190. $programs_with_courses = Program::with(array('courses' => function ($query) {
  191. // $query->whereNotNull('outcomes_attempted');
  192. $query->whereIn('semester_id', Session::get('semesters_ids'));
  193. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  194. }
  195. if ($school->id == 13) {
  196. // 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'));
  197. 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'));
  198. } else {
  199. // 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'));
  200. 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'));
  201. }
  202. }
  203. public function overviewOri()
  204. {
  205. DB::disableQueryLog();
  206. Log::debug('user' . Auth::user()->id);
  207. //TODO Find a better way to prevent non-scoords from reaching the page
  208. switch (Auth::user()->role) {
  209. case 1:
  210. return Redirect::to('administrator');
  211. break;
  212. case 3:
  213. return Redirect::to('program-coordinator');
  214. break;
  215. }
  216. $schools = School::orderBy('name', 'asc')->get();
  217. $school = Auth::user()->school;
  218. $title = $school->name . ' ' . 'Overview';
  219. $id = $school->id;
  220. $outcomes = Outcome::orderBy('name', 'asc')->get();
  221. $outcomeCount = Outcome::all()->count();
  222. /**
  223. * List of grouped courses (grouped sections)
  224. */
  225. $program_ids = $school->programs->lists('id');
  226. $undergrad_programs = DB::table('programs')
  227. ->select('id', 'name', 'school_id', 'is_graduate')
  228. ->where('is_graduate', '=', 0)
  229. ->where('school_id', '=', $id)
  230. ->orderBy('name', 'ASC')
  231. ->get();
  232. $grad_programs = DB::table('programs')
  233. ->select('id', 'name', 'school_id', 'is_graduate')
  234. ->where('is_graduate', '=', 1)
  235. ->where('school_id', '=', $id)
  236. ->orderBy('name', 'ASC')
  237. ->get();
  238. /*$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'))
  239. ->with('semester')
  240. ->with('program')
  241. ->whereIn('courses.program_id', $program_ids)
  242. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  243. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  244. ->where('programs.is_graduate', '=', 1)
  245. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  246. ->orderBy('courses.code')
  247. ->orderBy('courses.number')
  248. ->orderBy('courses.semester_id')
  249. ->get();*/
  250. $grad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  251. ->with('semester')
  252. ->with('program')
  253. ->whereIn('courses.program_id', $program_ids)
  254. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  255. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  256. ->where('programs.is_graduate', '=', 1)
  257. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  258. ->orderBy('courses.code')
  259. ->orderBy('courses.number')
  260. ->orderBy('courses.semester_id')
  261. ->get();
  262. /*$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'))
  263. ->with('semester')
  264. ->with('program')
  265. ->whereIn('courses.program_id', $program_ids)
  266. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  267. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  268. ->where('programs.is_graduate', '=', 0)
  269. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  270. ->orderBy('courses.code')
  271. ->orderBy('courses.number')
  272. ->orderBy('courses.semester_id')
  273. ->get();*/
  274. $undergrad_grouped_courses = Course::select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  275. ->with('semester')
  276. ->with('program')
  277. ->whereIn('courses.program_id', $program_ids)
  278. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  279. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  280. ->where('programs.is_graduate', '=', 0)
  281. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  282. ->orderBy('courses.code')
  283. ->orderBy('courses.number')
  284. ->orderBy('courses.semester_id')
  285. ->get();
  286. // Fetch programs with participation
  287. $participating_programs = $this->participatingPrograms($school);
  288. /**
  289. * Calculate how many sections are doing assessment
  290. */
  291. $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  292. $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  293. $undergrad_assessed_sections_count = 0;
  294. $undergrad_school_sections_count = 0;
  295. $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  296. $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  297. $grad_assessed_sections_count = 0;
  298. $grad_school_sections_count = 0;
  299. /*
  300. foreach ($school->programs as $program) {
  301. foreach ($program->courses as $course) {
  302. if (!$course->program->is_graduate) {
  303. if ($course->outcomes_achieved != NULL) {
  304. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  305. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  306. for ($i = 1; $i <= count($undergrad_outcomes_attempted); $i++) {
  307. $undergrad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  308. $undergrad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  309. }
  310. $undergrad_assessed_sections_count += 1;
  311. }
  312. $undergrad_school_sections_count += 1;
  313. } else {
  314. if ($course->outcomes_achieved != NULL) {
  315. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  316. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  317. for ($i = 1; $i <= count($grad_outcomes_attempted); $i++) {
  318. $grad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  319. $grad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  320. }
  321. $grad_assessed_sections_count += 1;
  322. }
  323. $grad_school_sections_count += 1;
  324. }
  325. }
  326. }
  327. */
  328. foreach ($school->programs as $program) {
  329. foreach ($program->courses as $course) {
  330. if (!$course->program->is_graduate){
  331. $undergrad_school_sections_count += 1;
  332. if($course->isAssessed())$undergrad_assessed_sections_count += 1;
  333. // Log::info("aqui".$course);
  334. }
  335. else {
  336. $grad_school_sections_count += 1;
  337. if($course->isAssessed())$grad_assessed_sections_count += 1;
  338. // Log::info("aqui".$course);
  339. }
  340. //
  341. // if (!$course->program->is_graduate) {
  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. // $undergrad_outcomes_attempted[$i] += $score;
  348. // }
  349. // foreach ($course_outcomes_achieved as $i => $score) {
  350. // $undergrad_outcomes_achieved[$i] += $score;
  351. // }
  352. // $undergrad_assessed_sections_count += 1;
  353. // }
  354. // $undergrad_school_sections_count += 1;
  355. // } else {
  356. // if ($course_outcomes_achieved = $course->outcomes_ach()) {
  357. // //$course_outcomes_achieved = $course->outcomes_ach();
  358. // $course_outcomes_attempted = $course->outcomes_att();
  359. // foreach ($course_outcomes_attempted as $i => $score) {
  360. //
  361. // $grad_outcomes_attempted[$i] += $score;
  362. // }
  363. // foreach ($course_outcomes_achieved as $i => $score) {
  364. // $grad_outcomes_achieved[$i] += $score;
  365. // }
  366. // $grad_assessed_sections_count += 1;
  367. // }
  368. // $grad_school_sections_count += 1;
  369. // }
  370. }
  371. }
  372. /**
  373. * Calculate how many programs achieved and attempted each outcome in this school
  374. */
  375. // Number of programs that achieved a particular learning outcome
  376. $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  377. // Number of programs that attempted a particular learning outcome
  378. $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  379. // Fetch programs with participation for the school
  380. // $participating_undergrad_programs = DB::table('programs')
  381. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  382. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  383. // ->addSelect('courses.semester_id')
  384. // ->whereIn('semester_id', Session::get('semesters_ids'))
  385. // ->where('is_graduate', 0)
  386. // ->where('school_id', $school->id)
  387. // ->groupBy('id')
  388. // ->get();
  389. $output = array();
  390. // For each outcome
  391. foreach ($outcomes as $outcome) {
  392. // For each program with courses that do assessment
  393. $programs_with_courses = Program::with(array('courses' => function ($query) {
  394. // $query->whereNotNull('outcomes_attempted');
  395. $query->whereIn('semester_id', Session::get('semesters_ids'));
  396. $query->join('activities', 'activities.course_id', '=', 'courses.id')
  397. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  398. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  399. ->where('activities.draft', 0)
  400. ->where('activities.diagnostic', 0)
  401. ->select('courses.*')->distinct();
  402. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  403. foreach ($programs_with_courses as $program) {
  404. if(in_array($program->id,$participating_programs)){
  405. // To acummulate all criteria for one program
  406. $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  407. $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  408. //Flag for counting programs
  409. $flag = false;
  410. // For each course in the program
  411. foreach ($program->courses as $course) {
  412. // If the outcome in question is being evaluated
  413. $course_outcomes_attempted2 = $course->outcomes_att(); //json_decode($course->outcomes_attempted, true);
  414. $course_outcomes_achieved2 = $course->outcomes_ach(); //json_decode($course->outcomes_achieved, true);
  415. if (
  416. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  417. && $course_outcomes_attempted2[$outcome->id] > 0
  418. ) {
  419. $achieved_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  420. $attempted_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  421. // Add one to the programs assessing, if it wasn't added before
  422. if (!$flag) {
  423. $attemptedUndergradProgramsPerOutcome[$outcome->id] += 1;
  424. $flag = true;
  425. }
  426. }
  427. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  428. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  429. }
  430. //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
  431. 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) {
  432. $achievedUndergradProgramsPerOutcome[$outcome->id] += 1;
  433. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  434. }
  435. }
  436. }
  437. }
  438. /**
  439. * Calculate how many programs achieved and attempted each outcome in this school
  440. */
  441. // Number of programs that achieved a particular learning outcome
  442. $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  443. // Number of programs that attempted a particular learning outcome
  444. $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  445. // Fetch programs with participation for the school
  446. // $participating_grad_programs = DB::table('programs')
  447. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  448. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  449. // ->addSelect('courses.semester_id')
  450. // ->whereIn('semester_id', Session::get('semesters_ids'))
  451. // ->where('is_graduate', 1)
  452. // ->where('school_id', $school->id)
  453. // ->groupBy('id')
  454. // ->get();
  455. $output = array();
  456. // For each outcome
  457. foreach ($outcomes as $outcome) {
  458. // For each program with courses that do assessment
  459. $programs_with_courses = Program::with(array('courses' => function ($query) {
  460. //$query->whereNotNull('outcomes_attempted');
  461. $query->whereIn('semester_id', Session::get('semesters_ids'));
  462. $query->join('activities', 'activities.course_id', '=', 'courses.id')
  463. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  464. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  465. ->where('activities.draft', 0)
  466. ->where('activities.diagnostic', 0)
  467. ->select('courses.*')->distinct();
  468. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  469. foreach ($programs_with_courses as $program) {
  470. if(in_array($program->id,$participating_programs)){
  471. // To acummulate all criteria for one program
  472. $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  473. $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  474. //Flag for counting programs
  475. $flag = false;
  476. // For each course in the program
  477. foreach ($program->courses as $course) {
  478. // If the outcome in question is being evaluated
  479. $course_outcomes_attempted2 = $course->outcomes_att(); // json_decode($course->outcomes_attempted, true);
  480. $course_outcomes_achieved2 = $course->outcomes_ach(); //json_decode($course->outcomes_achieved, true);
  481. if (
  482. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  483. && $course_outcomes_attempted2[$outcome->id] > 0
  484. ) {
  485. $achieved_outcomes_per_grad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  486. $attempted_outcomes_per_grad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  487. // Add one to the programs assessing, if it wasn't added before
  488. if (!$flag) {
  489. $attemptedGradProgramsPerOutcome[$outcome->id] += 1;
  490. $flag = true;
  491. }
  492. }
  493. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_program);
  494. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  495. }
  496. //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
  497. 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) {
  498. $achievedGradProgramsPerOutcome[$outcome->id] += 1;
  499. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  500. }
  501. }
  502. }
  503. }
  504. // 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'));
  505. 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'));
  506. }
  507. }