Ei kuvausta

SchoolsController.php 64KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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. $undergrad_stu_outcome_attempted = [];
  35. $grad_stu_outcome_attempted = [];
  36. $undergrad_stu_outcome_achieved = [];
  37. $grad_stu_outcome_achieved = [];
  38. $attemptedUndergradProgramsPerOutcome = [];
  39. $achievedUndergradProgramsPerOutcome = [];
  40. $attemptedGradProgramsPerOutcome = [];
  41. $achievedGradProgramsPerOutcome = [];
  42. foreach ($outcomes_undergrad as $outcome) {
  43. $undergrad_stu_outcome_attempted[$outcome->id] = 0;
  44. $undergrad_stu_outcome_achieved[$outcome->id] = 0;
  45. $attemptedUndergradProgramsPerOutcome[$outcome->id] = [];
  46. $achievedUndergradProgramsPerOutcome[$outcome->id] = [];
  47. }
  48. foreach ($outcomes_grad as $outcome) {
  49. $grad_stu_outcome_attempted[$outcome->id] = 0;
  50. $grad_stu_outcome_achieved[$outcome->id] = 0;
  51. $attemptedGradProgramsPerOutcome[$outcome->id] = [];
  52. $achievedGradProgramsPerOutcome[$outcome->id] = [];
  53. }
  54. /**
  55. * List of grouped courses (grouped sections)
  56. */
  57. $program_ids = $school->programs->lists('id');
  58. $undergrad_programs = DB::table('programs')
  59. ->select('id', 'name', 'school_id', 'is_graduate')
  60. ->where('is_graduate', '=', 0)
  61. ->where('school_id', '=', $id)
  62. ->orderBy('name', 'ASC')
  63. ->get();
  64. $grad_programs = DB::table('programs')
  65. ->select('id', 'name', 'school_id', 'is_graduate')
  66. ->where('is_graduate', '=', 1)
  67. ->where('school_id', '=', $id)
  68. ->orderBy('name', 'ASC')
  69. ->get();
  70. //quiero ver si monto el query tm aqui
  71. $undergrad_programs_list = DB::table('programs')
  72. ->select('id', 'name', 'school_id', 'is_graduate')
  73. ->where('is_graduate', '=', 0)
  74. ->where('school_id', '=', $id)
  75. ->orderBy('name', 'ASC')
  76. ->lists('id');
  77. $grad_programs_list = DB::table('programs')
  78. ->select('id', 'name', 'school_id', 'is_graduate')
  79. ->where('is_graduate', '=', 1)
  80. ->where('school_id', '=', $id)
  81. ->orderBy('name', 'ASC')
  82. ->lists('id');
  83. $undergraduate_student_query = DB::table("courses")
  84. ->join('activities', 'activities.course_id', '=', 'courses.id')
  85. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  86. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  87. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  88. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  89. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  90. ->join('program_criterion_objective_outcome as poco', function ($q) {
  91. $q->on('courses.program_id', '=', 'poco.program_id')
  92. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  93. })
  94. ->join('students', 'students.id', '=', 'assessments.student_id')
  95. ->whereIn('poco.program_id', $undergrad_programs_list)
  96. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  97. ->whereIn('courses.program_id', $undergrad_programs_list)
  98. ->select('students.number as student_id')
  99. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  100. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  101. ->addSelect('outcome_id')
  102. ->groupBy(array('students.id', 'outcome_id'))
  103. ->get();
  104. Log::info($undergraduate_student_query);
  105. $grad_student_query = DB::table("courses")
  106. ->join('activities', 'activities.course_id', '=', 'courses.id')
  107. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  108. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  109. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  110. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  111. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  112. ->join('program_criterion_objective_outcome as poco', function ($q) {
  113. $q->on('courses.program_id', '=', 'poco.program_id')
  114. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  115. })
  116. ->join('students', 'students.id', '=', 'assessments.student_id')
  117. ->whereIn('poco.program_id', $grad_programs_list)
  118. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  119. ->whereIn('courses.program_id', $grad_programs_list)
  120. ->select('students.number as student_id')
  121. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  122. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  123. ->addSelect('outcome_id')
  124. ->groupBy(array('students.id', 'outcome_id'))
  125. ->get();
  126. //school
  127. /*
  128. student x, crit achieved, crit attempted, outcome 1
  129. student x, crit achieved, crit attempted, outcome 2
  130. student x, crit achieved, crit attempted, outcome 3
  131. student x, crit achieved, crit attempted, outcome 4
  132. student y, crit achieved, crit attempted, outcome 1
  133. student y, crit achieved, crit attempted, outcome 2
  134. student y, crit achieved, crit attempted, outcome 3
  135. ....
  136. */
  137. $grad_outcomes_attempted = [];
  138. $grad_outcomes_achieved = [];
  139. $undergrad_outcomes_attempted = [];
  140. $undergrad_outcomes_achieved = [];
  141. foreach ($outcomes_grad as $outcome) {
  142. $grad_outcomes_attempted[$outcome->id] = 0;
  143. $grad_outcomes_achieved[$outcome->id] = 0;
  144. }
  145. foreach ($outcomes_undergrad as $outcome) {
  146. $undergrad_outcomes_attempted[$outcome->id] = 0;
  147. $undergrad_outcomes_achieved[$outcome->id] = 0;
  148. }
  149. foreach ($grad_student_query as $result) {
  150. if ($result->criteria_attempted != 0) {
  151. if (!isset($grad_outcomes_attempted[$result->outcome_id]))
  152. continue;
  153. $grad_outcomes_attempted[$result->outcome_id]++;
  154. $percent = $result->criteria_achieved / $result->criteria_attempted * 100;
  155. if ($percent >= 66.66) {
  156. $grad_outcomes_achieved[$result->outcome_id]++;
  157. }
  158. }
  159. }
  160. foreach ($undergraduate_student_query as $result) {
  161. if ($result->criteria_attempted != 0) {
  162. if (!isset($undergrad_outcomes_attempted[$result->outcome_id]))
  163. continue;
  164. $undergrad_outcomes_attempted[$result->outcome_id]++;
  165. $percent = $result->criteria_achieved / $result->criteria_attempted * 100;
  166. if ($percent >= 66.66) {
  167. $undergrad_outcomes_achieved[$result->outcome_id]++;
  168. }
  169. }
  170. }
  171. $grad_grouped_courses = Course::
  172. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  173. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  174. ->with('semester')
  175. ->with('program')
  176. ->whereIn('courses.program_id', $program_ids)
  177. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  178. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  179. ->where('programs.is_graduate', '=', 1)
  180. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  181. ->orderBy('courses.code')
  182. ->orderBy('courses.number')
  183. ->orderBy('courses.semester_id')
  184. ->get();
  185. $undergrad_grouped_courses = Course::
  186. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  187. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  188. ->with('semester')
  189. ->with('program')
  190. ->whereIn('courses.program_id', $program_ids)
  191. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  192. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  193. ->where('programs.is_graduate', '=', 0)
  194. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  195. ->orderBy('courses.code')
  196. ->orderBy('courses.number')
  197. ->orderBy('courses.semester_id')
  198. ->get();
  199. foreach ($undergrad_grouped_courses as $key => $courses) {
  200. $undergrad_grouped_courses[$key]->outcomes_attempted = NULL;
  201. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  202. foreach ($coursesT as $course) {
  203. if ($course->isAssessed()) {
  204. $undergrad_grouped_courses[$key]->outcomes_attempted = true;
  205. }
  206. }
  207. }
  208. foreach ($grad_grouped_courses as $key => $courses) {
  209. $grad_grouped_courses[$key]->outcomes_attempted = NULL;
  210. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  211. foreach ($coursesT as $course) {
  212. if ($course->isAssessed()) {
  213. $grad_grouped_courses[$key]->outcomes_attempted = true;
  214. }
  215. }
  216. }
  217. // Fetch programs with participation
  218. $participating_programs = $this->participatingPrograms($school);
  219. /**
  220. * Calculate how many sections are doing assessment
  221. */
  222. $undergrad_assessed_sections_count = 0;
  223. $undergrad_school_sections_count = 0;
  224. $grad_assessed_sections_count = 0;
  225. $grad_school_sections_count = 0;
  226. foreach ($school->programs as $program) {
  227. foreach ($program->courses as $course) {
  228. if (!$course->program->is_graduate) {
  229. $undergrad_school_sections_count += 1;
  230. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  231. } else {
  232. $grad_school_sections_count += 1;
  233. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  234. }
  235. }
  236. }
  237. //como resuelvo programsAttempted y eso
  238. //El query es el mismo de students, lo unico que dividido con programas,
  239. //asi que lo que esta haciendo es, prog 1, y coge los dominios y estudiantes que evaluason
  240. $undergrad_prog_attempted = DB::table("courses")
  241. ->join('activities', 'activities.course_id', '=', 'courses.id')
  242. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  243. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  244. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  245. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  246. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  247. ->join('program_criterion_objective_outcome as poco', function ($q) {
  248. $q->on('courses.program_id', '=', 'poco.program_id')
  249. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  250. })
  251. ->join('students', 'students.id', '=', 'assessments.student_id')
  252. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  253. ->whereIn('poco.program_id', $undergrad_programs_list)
  254. ->whereIn('courses.program_id', $undergrad_programs_list)
  255. ->select('students.number as student_id')
  256. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  257. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  258. ->addSelect('outcome_id')
  259. ->addSelect("courses.program_id")
  260. ->groupBy(array('students.id', 'outcome_id', 'program_id'))
  261. ->get();
  262. $grad_prog_attempted = DB::table("courses")
  263. ->join('activities', 'activities.course_id', '=', 'courses.id')
  264. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  265. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  266. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  267. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  268. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  269. ->join('program_criterion_objective_outcome as poco', function ($q) {
  270. $q->on('courses.program_id', '=', 'poco.program_id')
  271. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  272. })
  273. ->join('students', 'students.id', '=', 'assessments.student_id')
  274. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  275. ->whereIn('poco.program_id', $grad_programs_list)
  276. ->whereIn('courses.program_id', $grad_programs_list)
  277. ->select('students.number as student_id')
  278. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  279. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  280. ->addSelect('outcome_id')
  281. ->addSelect("courses.program_id")
  282. ->groupBy(array('students.id', 'outcome_id', 'program_id'))
  283. ->get();
  284. //este arreglo va a tener attempted[outcome->id][program->id]
  285. //so la cardinalidad de attempted[outcome->id] dice cuantos programas intentaron, achieved[outcome->id], va
  286. //a decir cuantos pasaron y attempted[outcome->id][program->id] la suma de estudiantes que intentaron
  287. //
  288. foreach ($undergrad_prog_attempted as $row) {
  289. $program_id = $row->program_id;
  290. $outcome_id = $row->outcome_id;
  291. if (!isset($attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id]))
  292. $attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  293. $attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id]++;
  294. $criteria_attempted_by_stu = $row->criteria_attempted;
  295. $criteria_achieved_by_stu = $row->criteria_achieved;
  296. if ($criteria_attempted_by_stu != 0 && $criteria_achieved_by_stu / $criteria_attempted_by_stu * 100 >= 66.67) {
  297. if (!isset($achievedUndergradProgramsPerOutcome[$outcome_id][$program_id]))
  298. $achievedUndergradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  299. $achievedUndergradProgramsPerOutcome[$outcome_id][$program_id]++;
  300. }
  301. }
  302. foreach ($grad_prog_attempted as $row) {
  303. $program_id = $row->program_id;
  304. $outcome_id = $row->outcome_id;
  305. if (!isset($attemptedGradProgramsPerOutcome[$outcome_id][$program_id]))
  306. $attemptedGradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  307. $attemptedGradProgramsPerOutcome[$outcome_id][$program_id]++;
  308. $criteria_attempted_by_stu = $row->criteria_attempted;
  309. $criteria_achieved_by_stu = $row->criteria_achieved;
  310. if ($criteria_attempted_by_stu != 0 && $criteria_achieved_by_stu / $criteria_attempted_by_stu * 100 >= 66.67) {
  311. if (!isset($achievedGradProgramsPerOutcome[$outcome_id][$program_id]))
  312. $achievedGradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  313. $achievedGradProgramsPerOutcome[$outcome_id][$program_id]++;
  314. }
  315. }
  316. /**
  317. * Calculate how many programs achieved and attempted each outcome in this school
  318. */
  319. // For each outcome
  320. /*
  321. foreach ($outcomes_undergrad as $outcome) {
  322. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  323. // $achieved_outcomes_per_undergrad_program[$outcome->id]=0;
  324. $attemptedUndergradProgramsPerOutcome[$outcome->id] = 0;
  325. $achievedUndergradProgramsPerOutcome[$outcome->id] = 0;
  326. $programs_attempted_in_school[$outcome->id] = $outcome->programs_attempted_in_school($semesters, $school->id);
  327. // var_dump($programs_attempted_in_school);exit();
  328. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  329. // var_dump($program_id->id);exit();
  330. $program = DB::table('programs')->where('id', '=', $program_id->id)->first();
  331. if (!$program->is_graduate) {
  332. $attemptedUndergradProgramsPerOutcome[$outcome->id]++;
  333. $programC = Program::where('id', '=', $program_id->id)->first();
  334. // var_dump($programC);exit();
  335. if ($programC->achieved_outcome($outcome->id, $semesters)) {
  336. $achievedUndergradProgramsPerOutcome[$outcome->id]++;
  337. }
  338. }
  339. }
  340. $undergrad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 0);
  341. $undergrad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 0);
  342. // For each program with courses that do assessment
  343. $programs_with_courses = Program::with(array('courses' => function ($query) {
  344. // $query->whereNotNull('outcomes_attempted');
  345. $query->whereIn('semester_id', Session::get('semesters_ids'));
  346. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  347. }*/
  348. /**
  349. * Calculate how many Graduate programs achieved and attempted each outcome in this school
  350. */
  351. /*
  352. // For each outcome
  353. foreach ($outcomes_grad as $outcome) {
  354. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  355. $achieved_outcomes_per_grad_program[$outcome->id] = 0;
  356. $attemptedGradProgramsPerOutcome[$outcome->id] = 0;
  357. $achievedGradProgramsPerOutcome[$outcome->id] = 0;
  358. $grad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 1);
  359. $grad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 1);
  360. // For each program with courses that do assessment
  361. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  362. // var_dump($program_id->id);exit();
  363. $program = DB::table('programs')
  364. ->where('id', '=', $program_id->id)
  365. ->first();
  366. // $program=Program::where('id', $program_id->id);
  367. // var_dump($program);exit();
  368. if ($program->is_graduate) {
  369. $attemptedGradProgramsPerOutcome[$outcome->id]++;
  370. $programC = Program::where('id', '=', $program_id->id)->first();
  371. // var_dump($programC);exit();
  372. if ($programC->achieved_outcome($outcome->id, $semesters)) {
  373. $achievedGradProgramsPerOutcome[$outcome->id]++;
  374. }
  375. }
  376. }
  377. $programs_with_courses = Program::with(array('courses' => function ($query) {
  378. // $query->whereNotNull('outcomes_attempted');
  379. $query->whereIn('semester_id', Session::get('semesters_ids'));
  380. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  381. }*/
  382. if ($school->id == 13) {
  383. // 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'));
  384. 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'));
  385. } else {
  386. // 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'));
  387. 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'));
  388. }
  389. }
  390. private function cmp($a, $b)
  391. {
  392. return strcmp($a->name, $b->name);
  393. }
  394. public function studentSchoolAssessmentReport($school_id)
  395. {
  396. $id = $school_id;
  397. ini_set('memory_limit', -1);
  398. ini_set('max_execution_time', 300);
  399. $outcomes = Outcome::orderBy('name', 'asc')->get();
  400. $school = School::find($school_id);
  401. $title = $school->name;
  402. $outcomeCount = Outcome::all()->count();
  403. $programs = Program::where('school_id', '=', $school_id)->get();
  404. $programs_ids = array();
  405. // var_dump($programs);exit();
  406. $programs_name = array();
  407. foreach ($programs as $program) {
  408. // var_dump($program);
  409. $programs_ids[] = $program->id;
  410. $programs_name[$program->id] = $program->name;
  411. }
  412. $grouped_courses = Course::
  413. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  414. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  415. ->with('semester')
  416. ->with('program')
  417. ->whereIn('courses.program_id', $programs_ids)
  418. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  419. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  420. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  421. ->orderBy('courses.code')
  422. ->orderBy('courses.number')
  423. ->orderBy('courses.semester_id')
  424. ->get();
  425. $role = Auth::user()->role;
  426. $users = array();
  427. $resultados_todos_obj = DB::table('assessments')
  428. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  429. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  430. ->join('courses', 'courses.id', '=', 'activities.course_id')
  431. ->join('students', 'students.id', '=', 'assessments.student_id')
  432. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  433. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  434. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  435. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  436. ->whereIn('students.program_id', $programs_ids)
  437. ->whereIn('semester_id', Session::get('semesters_ids'))
  438. ->where('semesters.is_visible', '=', 1)
  439. ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  440. ->distinct()
  441. ->get();
  442. foreach ($resultados_todos_obj as $resultado) {
  443. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'])) {
  444. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'] = array();
  445. }
  446. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'][] = $resultado->code;
  447. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'] = array_unique($resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters']);
  448. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted'])) {
  449. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted'] = 0;
  450. }
  451. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted']++;
  452. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved'])) {
  453. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved'] = 0;
  454. }
  455. if ($resultado->score >= $resultado->expected_points) {
  456. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved']++;
  457. }
  458. }
  459. $outcomes_colap = array();
  460. $programs = array();
  461. // $outcomes_colap=array();
  462. $i = 0;
  463. $outcomes_attempted = array();
  464. $outcomes_attempted_colap = array();
  465. $outcomes_achieved_colap = array();
  466. $outcomes_attempted_semesters = array();
  467. foreach ($resultados_todos as $program_id => $resultados_prog) {
  468. $outcomes_attempted_semesters[$program_id] = array();
  469. foreach ($resultados_prog as $out => $datos_out) {
  470. $outcomes_achieved[$program_id][$out] = 0;
  471. $outcomes_attempted[$program_id][$out] = 0;
  472. // var_dump($datos_out);outcomes_attempted_semesters
  473. $outcomes_attempted_semesters[$program_id][$out] = $datos_out['semesters'];
  474. unset($datos_out['semesters']);
  475. // var_dump($outcomes_attempted_semesters[$program_id][$out]);
  476. // var_dump($datos_out);
  477. // exit();
  478. foreach ($datos_out as $res) {
  479. $outcomes_attempted[$program_id][$out]++;
  480. if (3 * $res['achieved'] >= 2 * $res['attempted'])
  481. $outcomes_achieved[$program_id][$out]++;
  482. }
  483. }
  484. $programs[] = Program::find($program_id);
  485. if (Program::find($program_id)->is_graduate) {
  486. $colapso = array(1 => array(), 3 => array(), 2 => array(11), 12 => array(7, 14), 10 => array(), 4 => array(6, 15));
  487. } else {
  488. $colapso = array(10 => array(), 1 => array(), 12 => array(7), 3 => array(9, 8, 14), 2 => array(11), 5 => array(), 4 => array(6, 13), 16 => array());
  489. }
  490. $resultados_todos_colap[$program_id] = array();
  491. foreach ($colapso as $out => $pares) {
  492. $resultados_todos_colap[$program_id][$out]["semesters"] = array();
  493. if (isset($resultados_todos[$program_id][$out]))
  494. $resultados_todos_colap[$program_id][$out] = $resultados_todos[$program_id][$out];
  495. else $resultados_todos_colap[$program_id][$out] = array();
  496. foreach ($pares as $par) {
  497. if (isset($resultados_todos[$program_id][$par])) {
  498. // unset($resultados_todos[$program_id][$par]['semesters']);
  499. foreach ($resultados_todos[$program_id][$par] as $estu => $resus) {
  500. if ($estu != "semesters") {
  501. if (!isset($resultados_todos_colap[$program_id][$out][$estu])) {
  502. $resultados_todos_colap[$program_id][$out][$estu]['attempted'] = 0;
  503. $resultados_todos_colap[$program_id][$out][$estu]['achieved'] = 0;
  504. }
  505. // print $program_id." ".$par." ".$estu."<br>";
  506. // var_dump($resultados_todos[$program_id][$par][$estu]);
  507. $resultados_todos_colap[$program_id][$out][$estu]['attempted'] += $resultados_todos[$program_id][$par][$estu]['attempted'];
  508. $resultados_todos_colap[$program_id][$out][$estu]['achieved'] += $resultados_todos[$program_id][$par][$estu]['achieved'];
  509. } else if (isset($resultados_todos[$program_id][$par]["semesters"])) {
  510. if (isset($resultados_todos_colap[$program_id][$out]["semesters"])) {
  511. $tmp = array_merge($resultados_todos_colap[$program_id][$out]["semesters"], $resultados_todos[$program_id][$par]["semesters"]);
  512. // var_dump(($tmp));
  513. // var_dump(array_unique($tmp));
  514. // exit();
  515. $resultados_todos_colap[$program_id][$out]["semesters"] = array_unique($tmp);
  516. } else
  517. $resultados_todos_colap[$program_id][$out]["semesters"] = array_unique($resultados_todos[$program_id][$par]["semesters"]);
  518. }
  519. }
  520. }
  521. }
  522. }
  523. // var_dump($resultados_todos_colap);
  524. $outcomes_attempted_colap[$program_id] = array();
  525. $outcomes_achieved_colap[$program_id] = array();
  526. $outcomes_attempted_colap_semesters[$program_id] = array();
  527. // print $program_id."<br>";
  528. // var_dump($resultados_todos_colap[$program_id]);
  529. // print "<br>";
  530. foreach ($resultados_todos_colap[$program_id] as $out => $datos_out) {
  531. if (!$i) $outcomes_colap[] = Outcome::find($out);
  532. // $outcomes_attempted_colap_semesters[$program_id][$out]=array();
  533. if (isset($datos_out['semesters'])) {
  534. $outcomes_attempted_colap_semesters[$program_id][$out] = $datos_out['semesters'];
  535. unset($datos_out['semesters']);
  536. }
  537. foreach ($datos_out as $res) {
  538. if (!isset($outcomes_attempted_colap[$program_id][$out])) {
  539. $outcomes_attempted_colap[$program_id][$out] = 0;
  540. $outcomes_achieved_colap[$program_id][$out] = 0;
  541. }
  542. $outcomes_attempted_colap[$program_id][$out]++;
  543. if (3 * $res['achieved'] >= 2 * $res['attempted'])
  544. $outcomes_achieved_colap[$program_id][$out]++;
  545. }
  546. if (empty($datos_out)) {
  547. $outcomes_attempted_colap[$program_id][$out] = 0;
  548. $outcomes_achieved_colap[$program_id][$out] = 0;
  549. }
  550. }
  551. $i++;
  552. }
  553. usort($outcomes_colap, array($this, "cmp"));
  554. // var_dump($outcomes_attempted_colap); print "<br>";
  555. // var_dump($outcomes_achieved_colap); print "<br>";
  556. // exit();
  557. $outcomes_attempted_colap_todo = array();
  558. $outcomes_achieved_colap_todo = array();
  559. foreach ($outcomes_attempted_colap as $program_id => $out_res) {
  560. foreach ($out_res as $out => $res) {
  561. if (!isset($outcomes_attempted_colap_todo[$out])) {
  562. $outcomes_attempted_colap_todo[$out] = 0;
  563. $outcomes_achieved_colap_todo[$out] = 0;
  564. }
  565. $outcomes_attempted_colap_todo[$out] += $outcomes_attempted_colap[$program_id][$out];
  566. $outcomes_achieved_colap_todo[$out] += $outcomes_achieved_colap[$program_id][$out];
  567. }
  568. }
  569. $outcomes_attempted_todo = array();
  570. $outcomes_achieved_todo = array();
  571. foreach ($outcomes_attempted as $program_id => $out_res) {
  572. foreach ($out_res as $out => $res) {
  573. if (!isset($outcomes_attempted_todo[$out])) {
  574. $outcomes_attempted_todo[$out] = 0;
  575. $outcomes_achieved_todo[$out] = 0;
  576. }
  577. $outcomes_attempted_todo[$out] += $outcomes_attempted[$program_id][$out];
  578. $outcomes_achieved_todo[$out] += $outcomes_achieved[$program_id][$out];
  579. }
  580. }
  581. return View::make('local.managers.shared.school_student_result', compact('title', 'outcomes_attempted_colap_semesters', 'outcomes_attempted_semesters', 'outcomes_attempted_colap_todo', 'outcomes_achieved_colap_todo', 'outcomes_attempted_todo', 'outcomes_achieved_todo', 'school', 'programs_name', 'role', 'outcomes', 'outcomes_colap', 'outcomes_attempted', 'outcomes_achieved', 'outcomes_attempted_colap', 'outcomes_achieved_colap', 'programs', 'users', 'program_courses', 'grouped_courses'));
  582. }
  583. public function showQuasiOri($id)
  584. {
  585. ini_set('memory_limit', '256M');
  586. DB::connection()->disableQueryLog();
  587. $school = School::find($id);
  588. $title = $school->name;
  589. $schools = School::all();
  590. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  591. // $outcomeCount = Outcome::all()->count();
  592. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  593. // var_dump($semesters);
  594. // exit();
  595. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  596. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  597. /**
  598. * List of grouped courses (grouped sections)
  599. */
  600. $program_ids = $school->programs->lists('id');
  601. $undergrad_programs = DB::table('programs')
  602. ->select('id', 'name', 'school_id', 'is_graduate')
  603. ->where('is_graduate', '=', 0)
  604. ->where('school_id', '=', $id)
  605. ->orderBy('name', 'ASC')
  606. ->get();
  607. $grad_programs = DB::table('programs')
  608. ->select('id', 'name', 'school_id', 'is_graduate')
  609. ->where('is_graduate', '=', 1)
  610. ->where('school_id', '=', $id)
  611. ->orderBy('name', 'ASC')
  612. ->get();
  613. $grad_grouped_courses = Course::
  614. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  615. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  616. ->with('semester')
  617. ->with('program')
  618. ->whereIn('courses.program_id', $program_ids)
  619. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  620. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  621. ->where('programs.is_graduate', '=', 1)
  622. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  623. ->orderBy('courses.code')
  624. ->orderBy('courses.number')
  625. ->orderBy('courses.semester_id')
  626. ->get();
  627. $undergrad_grouped_courses = Course::
  628. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  629. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  630. ->with('semester')
  631. ->with('program')
  632. ->whereIn('courses.program_id', $program_ids)
  633. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  634. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  635. ->where('programs.is_graduate', '=', 0)
  636. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  637. ->orderBy('courses.code')
  638. ->orderBy('courses.number')
  639. ->orderBy('courses.semester_id')
  640. ->get();
  641. // Fetch programs with participation
  642. $participating_programs = $this->participatingPrograms($school);
  643. /**
  644. * Calculate how many sections are doing assessment
  645. */
  646. // $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  647. // $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  648. $undergrad_assessed_sections_count = 0;
  649. $undergrad_school_sections_count = 0;
  650. // $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  651. // $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  652. $grad_assessed_sections_count = 0;
  653. $grad_school_sections_count = 0;
  654. foreach ($school->programs as $program) {
  655. foreach ($program->courses as $course) {
  656. // Log::info("aqui".$course);
  657. if (!$course->program->is_graduate) {
  658. $undergrad_school_sections_count += 1;
  659. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  660. // Log::info("aqui".$course);
  661. } else {
  662. $grad_school_sections_count += 1;
  663. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  664. // Log::info("aqui".$course);
  665. }
  666. // if (!$course->program->is_graduate) {
  667. // if ($course->outcomes_achieved != NULL) {
  668. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  669. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  670. // for ($i = 1; $i <= count($undergrad_outcomes_attempted); $i++) {
  671. // $undergrad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  672. // $undergrad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  673. // }
  674. // $undergrad_assessed_sections_count += 1;
  675. // }
  676. // $undergrad_school_sections_count += 1;
  677. // } else {
  678. // if ($course->outcomes_achieved != NULL) {
  679. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  680. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  681. // for ($i = 1; $i <= count($grad_outcomes_attempted); $i++) {
  682. // $grad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  683. // $grad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  684. // }
  685. // $grad_assessed_sections_count += 1;
  686. // }
  687. // $grad_school_sections_count += 1;
  688. // }
  689. }
  690. }
  691. /**
  692. * Calculate how many programs achieved and attempted each outcome in this school
  693. */
  694. // Number of programs that achieved a particular learning outcome
  695. // $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  696. // Number of programs that attempted a particular learning outcome
  697. // $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  698. // Fetch programs with participation for the school
  699. // $participating_undergrad_programs = DB::table('programs')
  700. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  701. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  702. // ->addSelect('courses.semester_id')
  703. // ->whereIn('semester_id', Session::get('semesters_ids'))
  704. // ->where('is_graduate', 0)
  705. // ->where('school_id', $school->id)
  706. // ->groupBy('id')
  707. // ->get();
  708. $output = array();
  709. // For each outcome
  710. foreach ($outcomes_undergrad as $outcome) {
  711. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  712. $achieved_outcomes_per_undergrad_program[$outcome->id] = 0;
  713. $attemptedUndergradProgramsPerOutcome[$outcome->id] = 0;
  714. $achievedUndergradProgramsPerOutcome[$outcome->id] = 0;
  715. $programs_attempted_in_school[$outcome->id] = $outcome->programs_attempted_in_school($semesters, $school->id);
  716. // var_dump($programs_attempted_in_school);exit();
  717. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  718. // var_dump($program_id->id);exit();
  719. $program = DB::table('programs')
  720. ->where('id', '=', $program_id->id)
  721. ->first();
  722. // $program=Program::where('id', $program_id->id);
  723. // var_dump($program);exit();
  724. if (!$program->is_graduate) {
  725. $attemptedUndergradProgramsPerOutcome[$outcome->id]++;
  726. }
  727. }
  728. $undergrad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 0);
  729. $undergrad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 0);
  730. // For each program with courses that do assessment
  731. $programs_with_courses = Program::with(array('courses' => function ($query) {
  732. // $query->whereNotNull('outcomes_attempted');
  733. $query->whereIn('semester_id', Session::get('semesters_ids'));
  734. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  735. foreach ($programs_with_courses as $program) {
  736. if (in_array($program->id, $participating_programs)) {
  737. // To acummulate all criteria for one program
  738. // $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  739. // $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  740. //Flag for counting programs
  741. $flag = false;
  742. // For each course in the program
  743. // foreach ($program->courses as $course) {
  744. // if($course->isAssessed()){
  745. // // If the outcome in question is being evaluated
  746. // $course_outcomes_attempted2 = $course->outcomes_att();
  747. // // $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  748. // // $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  749. // $course_outcomes_achieved2 = $course->outcomes_ach();
  750. // if (
  751. // array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  752. // && $course_outcomes_attempted2[$outcome->id] > 0
  753. // ) {
  754. // $achieved_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  755. // // $attempted_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  756. //
  757. // // Add one to the programs assessing, if it wasn't added before
  758. // if (!$flag) {
  759. // $attemptedUndergradProgramsPerOutcome[$outcome->id] += 1;
  760. // $flag = true;
  761. // }
  762. // }
  763. //
  764. // // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  765. // // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  766. // }
  767. // }
  768. //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
  769. // 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) {
  770. // $achievedUndergradProgramsPerOutcome[$outcome->id] += 1;
  771. // // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  772. // }
  773. }
  774. }
  775. }
  776. /**
  777. * Calculate how many programs achieved and attempted each outcome in this school
  778. */
  779. // Number of programs that achieved a particular learning outcome
  780. // $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  781. // Number of programs that attempted a particular learning outcome
  782. // $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  783. //
  784. // Fetch programs with participation for the school
  785. // $participating_grad_programs = DB::table('programs')
  786. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  787. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  788. // ->addSelect('courses.semester_id')
  789. // ->whereIn('semester_id', Session::get('semesters_ids'))
  790. // ->where('is_graduate', 1)
  791. // ->where('school_id', $school->id)
  792. // ->groupBy('id')
  793. // ->get();
  794. $output = array();
  795. // For each outcome
  796. foreach ($outcomes_grad as $outcome) {
  797. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  798. $achieved_outcomes_per_grad_program[$outcome->id] = 0;
  799. $attemptedGradProgramsPerOutcome[$outcome->id] = 0;
  800. $achievedGradProgramsPerOutcome[$outcome->id] = 0;
  801. $grad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 1);
  802. $grad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 1);
  803. // For each program with courses that do assessment
  804. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  805. // var_dump($program_id->id);exit();
  806. $program = DB::table('programs')
  807. ->where('id', '=', $program_id->id)
  808. ->first();
  809. // $program=Program::where('id', $program_id->id);
  810. // var_dump($program);exit();
  811. if ($program->is_graduate) {
  812. $attemptedGradProgramsPerOutcome[$outcome->id]++;
  813. }
  814. }
  815. $programs_with_courses = Program::with(array('courses' => function ($query) {
  816. // $query->whereNotNull('outcomes_attempted');
  817. $query->whereIn('semester_id', Session::get('semesters_ids'));
  818. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  819. foreach ($programs_with_courses as $program) {
  820. if (in_array($program->id, $participating_programs)) {
  821. // To acummulate all criteria for one program
  822. // $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  823. // $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  824. //Flag for counting programs
  825. $flag = false;
  826. // For each course in the program
  827. foreach ($program->courses as $course) {
  828. if ($course->isAssessed()) {
  829. // If the outcome in question is being evaluated
  830. // $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  831. $course_outcomes_attempted2 = ($course->outcomes_att());
  832. $course_outcomes_achieved2 = ($course->outcomes_ach());
  833. // $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  834. if (
  835. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  836. && $course_outcomes_attempted2[$outcome->id] > 0
  837. ) {
  838. $achieved_outcomes_per_grad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  839. $attempted_outcomes_per_grad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  840. // Add one to the programs assessing, if it wasn't added before
  841. if (!$flag) {
  842. $attemptedGradProgramsPerOutcome[$outcome->id] += 1;
  843. $flag = true;
  844. }
  845. }
  846. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_program);
  847. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  848. }
  849. }
  850. //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
  851. 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) {
  852. $achievedGradProgramsPerOutcome[$outcome->id] += 1;
  853. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  854. }
  855. }
  856. }
  857. }
  858. if ($school->id == 13) {
  859. // 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'));
  860. 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'));
  861. } else {
  862. // 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'));
  863. 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'));
  864. }
  865. }
  866. public function print_school($id)
  867. {
  868. ini_set('memory_limit', '256M');
  869. DB::connection()->disableQueryLog();
  870. $school = School::find($id);
  871. $title = $school->name . ' Assessment Report - ' . date('m/d/Y');
  872. $outcomes = Outcome::orderBy('name', 'asc')->get();
  873. $outcomeCount = Outcome::all()->count();
  874. /**
  875. * List of courses (grouped sections)
  876. */
  877. $program_ids = $school->programs->lists('id');
  878. $grouped_courses = Course::
  879. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  880. select(DB::raw('name, code, number, semester_id, program_id'))
  881. ->with('semester')
  882. ->with('program')
  883. ->whereIn('program_id', $program_ids)
  884. ->whereIn('semester_id', Session::get('semesters_ids'))
  885. ->groupBy(array('code', 'number', 'semester_id'))
  886. ->orderBy('code')
  887. ->orderBy('number')
  888. ->orderBy('semester_id')
  889. ->get();
  890. // Fetch programs with participation
  891. $participating_programs = $this->participatingPrograms($school);
  892. /**
  893. * Calculate how many sections are doing assessment
  894. */
  895. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  896. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  897. $assessed_sections_count = 0;
  898. $school_sections_count = 0;
  899. foreach ($school->programs as $program) {
  900. foreach ($program->courses as $course) {
  901. if ($course->outcomes_achieved != NULL) {
  902. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  903. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  904. for ($i = 1; $i <= count($outcomes_attempted); $i++) {
  905. $outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  906. $outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  907. }
  908. $assessed_sections_count += 1;
  909. }
  910. $school_sections_count += 1;
  911. }
  912. }
  913. /**
  914. * Calculate how many programs achieved and attempted each outcome in this school
  915. */
  916. // Number of programs that achieved a particular learning outcome
  917. $achievedProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  918. // Number of programs that attempted a particular learning outcome
  919. $attemptedProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  920. $output = array();
  921. // For each outcome
  922. foreach ($outcomes as $outcome) {
  923. // For each program with courses that do assessment
  924. foreach (Program::with(array('courses' => function ($query) {
  925. // $query->whereNotNull('outcomes_attempted');
  926. $query->whereIn('semester_id', Session::get('semesters_ids'));
  927. }))->where('school_id', $school->id)->orderBy('name', 'asc')->get() as $program) {
  928. // To acummulate all criteria for one program
  929. $achieved_outcomes_per_program = array_fill(1, $outcomeCount, 0);
  930. $attempted_outcomes_per_program = array_fill(1, $outcomeCount, 0);
  931. //Flag for counting programs
  932. $flag = false;
  933. // For each course in the program
  934. foreach ($program->courses as $course) {
  935. // If the outcome in question is being evaluated
  936. $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  937. $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  938. if (
  939. array_key_exists($outcome->id, $course_outcomes_attempted2)
  940. && $course_outcomes_attempted2[$outcome->id] > 0
  941. ) {
  942. $achieved_outcomes_per_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  943. $attempted_outcomes_per_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  944. // Add one to the programs assessing, if it wasn't added before
  945. if (!$flag) {
  946. $attemptedProgramsPerOutcome[$outcome->id] += 1;
  947. $flag = true;
  948. }
  949. }
  950. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_program);
  951. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  952. }
  953. //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
  954. 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) {
  955. $achievedProgramsPerOutcome[$outcome->id] += 1;
  956. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  957. }
  958. }
  959. }
  960. 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'));
  961. }
  962. }