No Description

SchoolsController.php 37KB

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