暫無描述

SchoolsController.php 96KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763
  1. <?php
  2. use PhpOffice\PhpWord\Element\Object;
  3. class SchoolsController extends \BaseController
  4. {
  5. private function participatingPrograms($school)
  6. {
  7. return DB::table('programs')
  8. ->join('courses', 'courses.program_id', '=', 'programs.id')
  9. ->join('activities', 'activities.course_id', '=', 'courses.id')
  10. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  11. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  12. ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  13. ->addSelect('courses.semester_id')
  14. ->where('school_id', $school->id)
  15. ->whereIn('semester_id', Session::get('semesters_ids'))
  16. ->lists('id');
  17. // return DB::table('programs')
  18. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  19. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  20. // ->addSelect('courses.semester_id')
  21. // ->where('school_id', $school->id)
  22. // ->whereIn('semester_id', Session::get('semesters_ids'))
  23. // ->lists('id');
  24. }
  25. public function show($id)
  26. {
  27. ini_set('memory_limit', '256M');
  28. DB::connection()->disableQueryLog();
  29. $school = School::find($id);
  30. $title = $school->name;
  31. $schools = School::all();
  32. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  33. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  34. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  35. //$school->school_courses_per_outcome;
  36. //$undergrad_stu_outcome_attempted = [];
  37. //$grad_stu_outcome_attempted = [];
  38. //$undergrad_stu_outcome_achieved = [];
  39. //$grad_stu_outcome_achieved = [];
  40. $attemptedUndergradProgramsPerOutcome = [];
  41. $achievedUndergradProgramsPerOutcome = [];
  42. $attemptedGradProgramsPerOutcome = [];
  43. $achievedGradProgramsPerOutcome = [];
  44. foreach ($outcomes_undergrad as $outcome) {
  45. //$undergrad_stu_outcome_attempted[$outcome->id] = 0;
  46. //$undergrad_stu_outcome_achieved[$outcome->id] = 0;
  47. $attemptedUndergradProgramsPerOutcome[$outcome->id] = [];
  48. $achievedUndergradProgramsPerOutcome[$outcome->id] = [];
  49. }
  50. foreach ($outcomes_grad as $outcome) {
  51. //$grad_stu_outcome_attempted[$outcome->id] = 0;
  52. //$grad_stu_outcome_achieved[$outcome->id] = 0;
  53. $attemptedGradProgramsPerOutcome[$outcome->id] = [];
  54. $achievedGradProgramsPerOutcome[$outcome->id] = [];
  55. }
  56. /**
  57. * List of grouped courses (grouped sections)
  58. */
  59. $program_ids = $school->programs->lists('id');
  60. $undergrad_programs = DB::table('programs')
  61. ->select('id', 'name', 'school_id', 'is_graduate')
  62. ->where('is_graduate', '=', 0)
  63. ->where('school_id', '=', $id)
  64. ->orderBy('name', 'ASC')
  65. ->get();
  66. $grad_programs = DB::table('programs')
  67. ->select('id', 'name', 'school_id', 'is_graduate')
  68. ->where('is_graduate', '=', 1)
  69. ->where('school_id', '=', $id)
  70. ->orderBy('name', 'ASC')
  71. ->get();
  72. //quiero ver si monto el query tm aqui
  73. $undergrad_programs_list = DB::table('programs')
  74. ->select('id', 'name', 'school_id', 'is_graduate')
  75. ->where('is_graduate', '=', 0)
  76. ->where('school_id', '=', $id)
  77. ->orderBy('name', 'ASC')
  78. ->lists('id');
  79. $grad_programs_list = DB::table('programs')
  80. ->select('id', 'name', 'school_id', 'is_graduate')
  81. ->where('is_graduate', '=', 1)
  82. ->where('school_id', '=', $id)
  83. ->orderBy('name', 'ASC')
  84. ->lists('id');
  85. /*
  86. $undergraduate_student_query = DB::table("courses")
  87. ->join('activities', 'activities.course_id', '=', 'courses.id')
  88. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  89. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  90. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  91. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  92. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  93. ->join('program_criterion_objective_outcome as poco', function ($q) {
  94. $q->on('courses.program_id', '=', 'poco.program_id')
  95. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  96. })
  97. ->join('students', 'students.id', '=', 'assessments.student_id')
  98. ->whereIn('poco.program_id', $undergrad_programs_list)
  99. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  100. ->whereIn('courses.program_id', $undergrad_programs_list)
  101. ->select('students.number as student_id')
  102. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  103. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  104. ->addSelect('outcome_id')
  105. ->groupBy(array('students.id', 'outcome_id'))
  106. ->get();
  107. //Log::info($undergraduate_student_query);
  108. $grad_student_query = DB::table("courses")
  109. ->join('activities', 'activities.course_id', '=', 'courses.id')
  110. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  111. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  112. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  113. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  114. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  115. ->join('program_criterion_objective_outcome as poco', function ($q) {
  116. $q->on('courses.program_id', '=', 'poco.program_id')
  117. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  118. })
  119. ->join('students', 'students.id', '=', 'assessments.student_id')
  120. ->whereIn('poco.program_id', $grad_programs_list)
  121. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  122. ->whereIn('courses.program_id', $grad_programs_list)
  123. ->select('students.number as student_id')
  124. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  125. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  126. ->addSelect('outcome_id')
  127. ->groupBy(array('students.id', 'outcome_id'))
  128. ->get();
  129. */
  130. //school
  131. $school_info = $school->school_courses_per_outcome;
  132. $grad_outcomes_attempted = $school_info['graduate_info']['outcomes_attempted_combined'];
  133. $grad_outcomes_achieved = $school_info['graduate_info']['outcomes_achieved_combined'];
  134. $undergrad_outcomes_attempted = $school_info['undergraduate_info']['outcomes_attempted_combined'];
  135. $undergrad_outcomes_achieved = $school_info['undergraduate_info']['outcomes_achieved_combined'];
  136. $grad_grouped_courses = Course::
  137. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  138. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id, 1 as grouped'))
  139. ->with('semester')
  140. ->with('program')
  141. ->whereIn('courses.program_id', $program_ids)
  142. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  143. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  144. ->where('programs.is_graduate', '=', 1)
  145. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  146. ->orderBy('courses.code')
  147. ->orderBy('courses.number')
  148. ->orderBy('courses.semester_id')
  149. ->get();
  150. $undergrad_grouped_courses = Course::
  151. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  152. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id, 1 as grouped'))
  153. ->with('semester')
  154. ->with('program')
  155. ->whereIn('courses.program_id', $program_ids)
  156. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  157. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  158. ->where('programs.is_graduate', '=', 0)
  159. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  160. ->orderBy('courses.code')
  161. ->orderBy('courses.number')
  162. ->orderBy('courses.semester_id')
  163. ->get();
  164. foreach ($undergrad_grouped_courses as $key => $courses) {
  165. $undergrad_grouped_courses[$key]->outcomes_attempted = NULL;
  166. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  167. foreach ($coursesT as $course) {
  168. if ($course->isAssessed()) {
  169. $undergrad_grouped_courses[$key]->outcomes_attempted = true;
  170. }
  171. }
  172. }
  173. foreach ($grad_grouped_courses as $key => $courses) {
  174. $grad_grouped_courses[$key]->outcomes_attempted = NULL;
  175. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  176. foreach ($coursesT as $course) {
  177. if ($course->isAssessed()) {
  178. $grad_grouped_courses[$key]->outcomes_attempted = true;
  179. }
  180. }
  181. }
  182. // Fetch programs with participation
  183. $participating_programs = $this->participatingPrograms($school);
  184. /**
  185. * Calculate how many sections are doing assessment
  186. */
  187. $undergrad_assessed_sections_count = 0;
  188. $undergrad_school_sections_count = 0;
  189. $grad_assessed_sections_count = 0;
  190. $grad_school_sections_count = 0;
  191. foreach ($school->programs as $program) {
  192. foreach ($program->courses as $course) {
  193. if (!$course->program->is_graduate) {
  194. $undergrad_school_sections_count += 1;
  195. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  196. } else {
  197. $grad_school_sections_count += 1;
  198. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  199. }
  200. }
  201. }
  202. //Aqui estan los resultados divididos en outcomes y programs
  203. $attemptedUndergradProgramsPerOutcome = $school_info['undergraduate_info']['programs_attempted_combined'];
  204. $achievedUndergradProgramsPerOutcome = $school_info['undergraduate_info']['programs_achieved_combined'];
  205. $attemptedGradProgramsPerOutcome = $school_info['graduate_info']['programs_attempted_combined'];
  206. $achievedGradProgramsPerOutcome = $school_info['graduate_info']['programs_achieved_combined'];
  207. //como resuelvo programsAttempted y eso
  208. //El query es el mismo de students, lo unico que dividido con programas,
  209. //asi que lo que esta haciendo es, prog 1, y coge los dominios y estudiantes que evaluason
  210. /*
  211. $undergrad_prog_attempted = DB::table("courses")
  212. ->join('activities', 'activities.course_id', '=', 'courses.id')
  213. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  214. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  215. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  216. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  217. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  218. ->join('program_criterion_objective_outcome as poco', function ($q) {
  219. $q->on('courses.program_id', '=', 'poco.program_id')
  220. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  221. })
  222. ->join('students', 'students.id', '=', 'assessments.student_id')
  223. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  224. ->whereIn('poco.program_id', $undergrad_programs_list)
  225. ->whereIn('courses.program_id', $undergrad_programs_list)
  226. ->select('students.number as student_id')
  227. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  228. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  229. ->addSelect('outcome_id')
  230. ->addSelect("courses.program_id")
  231. ->groupBy(array('students.id', 'outcome_id', 'program_id'))
  232. ->get();
  233. $grad_prog_attempted = DB::table("courses")
  234. ->join('activities', 'activities.course_id', '=', 'courses.id')
  235. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  236. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  237. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  238. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  239. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  240. ->join('program_criterion_objective_outcome as poco', function ($q) {
  241. $q->on('courses.program_id', '=', 'poco.program_id')
  242. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  243. })
  244. ->join('students', 'students.id', '=', 'assessments.student_id')
  245. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  246. ->whereIn('poco.program_id', $grad_programs_list)
  247. ->whereIn('courses.program_id', $grad_programs_list)
  248. ->select('students.number as student_id')
  249. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  250. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  251. ->addSelect('outcome_id')
  252. ->addSelect("courses.program_id")
  253. ->groupBy(array('students.id', 'outcome_id', 'program_id'))
  254. ->get();
  255. //este arreglo va a tener attempted[outcome->id][program->id]
  256. //so la cardinalidad de attempted[outcome->id] dice cuantos programas intentaron, achieved[outcome->id], va
  257. //a decir cuantos pasaron y attempted[outcome->id][program->id] la suma de estudiantes que intentaron
  258. //
  259. foreach ($undergrad_prog_attempted as $row) {
  260. $program_id = $row->program_id;
  261. $outcome_id = $row->outcome_id;
  262. if (!isset($attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id]))
  263. $attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  264. $attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id]++;
  265. $criteria_attempted_by_stu = $row->criteria_attempted;
  266. $criteria_achieved_by_stu = $row->criteria_achieved;
  267. if ($criteria_attempted_by_stu != 0 && $criteria_achieved_by_stu / $criteria_attempted_by_stu * 100 >= 66.66) {
  268. if (!isset($achievedUndergradProgramsPerOutcome[$outcome_id][$program_id]))
  269. $achievedUndergradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  270. $achievedUndergradProgramsPerOutcome[$outcome_id][$program_id]++;
  271. }
  272. }
  273. foreach ($grad_prog_attempted as $row) {
  274. $program_id = $row->program_id;
  275. $outcome_id = $row->outcome_id;
  276. if (!isset($attemptedGradProgramsPerOutcome[$outcome_id][$program_id]))
  277. $attemptedGradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  278. $attemptedGradProgramsPerOutcome[$outcome_id][$program_id]++;
  279. $criteria_attempted_by_stu = $row->criteria_attempted;
  280. $criteria_achieved_by_stu = $row->criteria_achieved;
  281. if ($criteria_attempted_by_stu != 0 && $criteria_achieved_by_stu / $criteria_attempted_by_stu * 100 >= 66.66) {
  282. if (!isset($achievedGradProgramsPerOutcome[$outcome_id][$program_id]))
  283. $achievedGradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  284. $achievedGradProgramsPerOutcome[$outcome_id][$program_id]++;
  285. }
  286. }
  287. /**
  288. * Calculate how many programs achieved and attempted each outcome in this school
  289. */
  290. // For each outcome
  291. /*
  292. foreach ($outcomes_undergrad as $outcome) {
  293. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  294. // $achieved_outcomes_per_undergrad_program[$outcome->id]=0;
  295. $attemptedUndergradProgramsPerOutcome[$outcome->id] = 0;
  296. $achievedUndergradProgramsPerOutcome[$outcome->id] = 0;
  297. $programs_attempted_in_school[$outcome->id] = $outcome->programs_attempted_in_school($semesters, $school->id);
  298. // var_dump($programs_attempted_in_school);exit();
  299. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  300. // var_dump($program_id->id);exit();
  301. $program = DB::table('programs')->where('id', '=', $program_id->id)->first();
  302. if (!$program->is_graduate) {
  303. $attemptedUndergradProgramsPerOutcome[$outcome->id]++;
  304. $programC = Program::where('id', '=', $program_id->id)->first();
  305. // var_dump($programC);exit();
  306. if ($programC->achieved_outcome($outcome->id, $semesters)) {
  307. $achievedUndergradProgramsPerOutcome[$outcome->id]++;
  308. }
  309. }
  310. }
  311. $undergrad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 0);
  312. $undergrad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 0);
  313. // For each program with courses that do assessment
  314. $programs_with_courses = Program::with(array('courses' => function ($query) {
  315. // $query->whereNotNull('outcomes_attempted');
  316. $query->whereIn('semester_id', Session::get('semesters_ids'));
  317. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  318. }*/
  319. /**
  320. * Calculate how many Graduate programs achieved and attempted each outcome in this school
  321. */
  322. /*
  323. // For each outcome
  324. foreach ($outcomes_grad as $outcome) {
  325. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  326. $achieved_outcomes_per_grad_program[$outcome->id] = 0;
  327. $attemptedGradProgramsPerOutcome[$outcome->id] = 0;
  328. $achievedGradProgramsPerOutcome[$outcome->id] = 0;
  329. $grad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 1);
  330. $grad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 1);
  331. // For each program with courses that do assessment
  332. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  333. // var_dump($program_id->id);exit();
  334. $program = DB::table('programs')
  335. ->where('id', '=', $program_id->id)
  336. ->first();
  337. // $program=Program::where('id', $program_id->id);
  338. // var_dump($program);exit();
  339. if ($program->is_graduate) {
  340. $attemptedGradProgramsPerOutcome[$outcome->id]++;
  341. $programC = Program::where('id', '=', $program_id->id)->first();
  342. // var_dump($programC);exit();
  343. if ($programC->achieved_outcome($outcome->id, $semesters)) {
  344. $achievedGradProgramsPerOutcome[$outcome->id]++;
  345. }
  346. }
  347. }
  348. $programs_with_courses = Program::with(array('courses' => function ($query) {
  349. // $query->whereNotNull('outcomes_attempted');
  350. $query->whereIn('semester_id', Session::get('semesters_ids'));
  351. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  352. }*/
  353. //La linea negra de proposed.
  354. //
  355. //
  356. $linea_undergrad = DB::table('target_outcomes_program')
  357. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  358. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  359. ->whereIn('program_id', $undergrad_programs_list)
  360. ->whereIn("semester_id", Session::get('semesters_ids'))
  361. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  362. ->addSelect(DB::raw("count(target_outcomes_program.semester_id) as count_semester_id"))
  363. ->groupBy("expected_target")
  364. ->orderBy("expected_target", "DESC")
  365. ->first();
  366. if (!isset($linea_undergrad)) {
  367. $default_undergrad = 70;
  368. } elseif ($linea_undergrad->count_semester_id > 1) {
  369. $default_undergrad = null;
  370. $linea_undergrad = DB::table('target_outcomes_program')
  371. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  372. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  373. ->whereIn('program_id', $undergrad_programs_list)
  374. ->where('expected_target', $linea_undergrad->expected_target)
  375. ->whereIn("semester_id", Session::get('semesters_ids'))
  376. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  377. //->addSelect("count(semester_id) as count_semester_id")
  378. //->groupBy("expected_target")
  379. ->orderBy("semester_id", "DESC")
  380. ->first();
  381. }
  382. $linea_grad = DB::table('target_outcomes_program')
  383. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  384. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  385. ->whereIn('program_id', $grad_programs_list)
  386. ->whereIn("semester_id", Session::get('semesters_ids'))
  387. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  388. ->addSelect(DB::raw("count(target_outcomes_program.semester_id) as count_semester_id"))
  389. ->groupBy("expected_target")
  390. ->orderBy("expected_target", "DESC")
  391. ->first();
  392. //Log::info($linea_grad);
  393. if (!isset($linea_grad)) {
  394. $default_grad = 70;
  395. } elseif ($linea_grad->count_semester_id > 1) {
  396. $default_grad = null;
  397. $linea_grad = DB::table('target_outcomes_program')
  398. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  399. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  400. ->whereIn('program_id', $grad_programs_list)
  401. ->where('expected_target', $linea_grad->expected_target)
  402. ->whereIn("semester_id", Session::get('semesters_ids'))
  403. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  404. ->orderBy("semester_id", "DESC")
  405. ->first();
  406. }
  407. $expected_target_for_undergradprograms = !isset($linea_undergrad) ? $default_undergrad : $linea_undergrad->expected_target;
  408. $expected_target_for_gradprograms = !isset($linea_grad) ? $default_grad : $linea_grad->expected_target;
  409. //Log::info($default_grad);
  410. $undergrad_programs = $school->undergraduate_programs->get();
  411. $grad_programs = $school->graduate_programs->get();
  412. if ($school->id == 13) {
  413. // 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'));
  414. return View::make('local.managers.shared.school-uhs', compact('title', 'expected_target_for_undergradprograms', 'expected_target_for_gradprograms', 'undergrad_programs', 'grad_programs', 'default_undergrad', 'default_grad', 'linea_undergrad', 'linea_grad', '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'));
  415. } else {
  416. // 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'));
  417. return View::make('local.managers.shared.school', compact('title', 'expected_target_for_undergradprograms', 'expected_target_for_gradprograms', 'undergrad_programs', 'grad_programs', 'default_undergrad', 'default_grad', 'linea_undergrad', 'linea_grad', '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'));
  418. }
  419. }
  420. private function cmp($a, $b)
  421. {
  422. return strcmp($a->name, $b->name);
  423. }
  424. public function print_school_students_report($school_id)
  425. {
  426. $id = $school_id;
  427. ini_set('memory_limit', -1);
  428. ini_set('max_execution_time', 300);
  429. $outcomes = Outcome::orderBy('name', 'asc')->get();
  430. $school = School::find($school_id);
  431. $title = $school->name . ' Assessment Report - ' . date('m/d/Y');
  432. $outcomeCount = Outcome::all()->count();
  433. $programs = Program::where('school_id', '=', $school_id)->get();
  434. $programs_ids = array();
  435. // var_dump($programs);exit();
  436. $programs_name = array();
  437. foreach ($programs as $program) {
  438. // var_dump($program);
  439. $programs_ids[] = $program->id;
  440. $programs_name[$program->id] = $program->name;
  441. }
  442. $grouped_courses = Course::
  443. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  444. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id, 1 as grouped'))
  445. ->with('semester')
  446. ->with('program')
  447. ->whereIn('courses.program_id', $programs_ids)
  448. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  449. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  450. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  451. ->orderBy('courses.code')
  452. ->orderBy('courses.number')
  453. ->orderBy('courses.semester_id')
  454. ->get();
  455. $role = Auth::user()->role;
  456. $users = array();
  457. $outcomes_colap = Outcome::whereNull("new_outcome_id")->get();
  458. $info = $school->school_students_per_outcome;
  459. $outcomes_undergraduate_achieved_colap_todo = $info['undergraduate_info']['outcomes_achieved_combined'];
  460. $outcomes_undergraduate_attempted_colap_todo = $info['undergraduate_info']['outcomes_attempted_combined'];
  461. $outcomes_graduate_achieved_colap_todo = $info['graduate_info']['outcomes_achieved_combined'];
  462. $outcomes_graduate_attempted_colap_todo = $info['graduate_info']['outcomes_attempted_combined'];
  463. $outcomes_undergrad_program_attempted_colap = $info['undergraduate_info']['programs_attempted_combined'];
  464. $outcomes_undergrad_program_achieved_colap = $info['undergraduate_info']['programs_achieved_combined'];
  465. $outcomes_grad_program_attempted_colap = $info['graduate_info']['programs_attempted_combined'];
  466. $outcomes_grad_program_achieved_colap = $info['graduate_info']['programs_achieved_combined'];
  467. $undergraduate_programs = $school->undergraduate_programs->get();
  468. $graduate_programs = $school->graduate_programs->get();
  469. return View::make('local.managers.shared.print_school_students_report', compact(
  470. 'title', #'outcomes_attempted_colap_semesters', 'outcomes_attempted_semesters',
  471. 'outcomes_undergraduate_attempted_colap_todo',
  472. 'outcomes_undergraduate_achieved_colap_todo',
  473. 'outcomes_graduate_attempted_colap_todo',
  474. 'outcomes_graduate_achieved_colap_todo',
  475. 'outcomes_undergrad_program_attempted_colap',
  476. 'outcomes_undergrad_program_achieved_colap',
  477. 'outcomes_grad_program_attempted_colap',
  478. 'outcomes_grad_program_achieved_colap',
  479. 'undergraduate_programs',
  480. 'graduate_programs',
  481. 'school',
  482. 'programs_name',
  483. 'role',
  484. 'outcomes',
  485. 'outcomes_colap',
  486. 'outcomes_attempted',
  487. 'outcomes_achieved',
  488. 'outcomes_attempted_colap',
  489. 'outcomes_achieved_colap',
  490. 'programs',
  491. 'users',
  492. 'program_courses',
  493. 'grouped_courses'
  494. ));
  495. }
  496. public function studentSchoolAssessmentReport($school_id)
  497. {
  498. $id = $school_id;
  499. ini_set('memory_limit', -1);
  500. ini_set('max_execution_time', 300);
  501. $outcomes = Outcome::orderBy('name', 'asc')->get();
  502. $school = School::find($school_id);
  503. $title = $school->name;
  504. $outcomeCount = Outcome::all()->count();
  505. $programs = Program::where('school_id', '=', $school_id)->get();
  506. $programs_ids = array();
  507. // var_dump($programs);exit();
  508. $programs_name = array();
  509. foreach ($programs as $program) {
  510. // var_dump($program);
  511. $programs_ids[] = $program->id;
  512. $programs_name[$program->id] = $program->name;
  513. }
  514. $grouped_courses = Course::
  515. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  516. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id, 1 as grouped'))
  517. ->with('semester')
  518. ->with('program')
  519. ->whereIn('courses.program_id', $programs_ids)
  520. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  521. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  522. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  523. ->orderBy('courses.code')
  524. ->orderBy('courses.number')
  525. ->orderBy('courses.semester_id')
  526. ->get();
  527. $role = Auth::user()->role;
  528. $users = array();
  529. $outcomes_colap = Outcome::whereNull("new_outcome_id")->get();
  530. /*
  531. $resultados_todos_obj = DB::table('assessments')
  532. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  533. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  534. ->join('courses', 'courses.id', '=', 'activities.course_id')
  535. ->join('students', 'students.id', '=', 'assessments.student_id')
  536. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  537. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  538. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  539. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  540. ->whereIn('students.program_id', $programs_ids)
  541. ->whereIn('semester_id', Session::get('semesters_ids'))
  542. ->where('semesters.is_visible', '=', 1)
  543. ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  544. ->distinct()
  545. ->get();
  546. foreach ($resultados_todos_obj as $resultado) {
  547. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'])) {
  548. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'] = array();
  549. }
  550. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'][] = $resultado->code;
  551. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'] = array_unique($resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters']);
  552. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted'])) {
  553. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted'] = 0;
  554. }
  555. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted']++;
  556. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved'])) {
  557. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved'] = 0;
  558. }
  559. if ($resultado->score >= $resultado->expected_points) {
  560. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved']++;
  561. }
  562. }
  563. $outcomes_colap = array();
  564. $programs = array();
  565. // $outcomes_colap=array();
  566. $i = 0;
  567. $outcomes_attempted = array();
  568. $outcomes_attempted_colap = array();
  569. $outcomes_achieved_colap = array();
  570. $outcomes_attempted_semesters = array();
  571. foreach ($resultados_todos as $program_id => $resultados_prog) {
  572. $outcomes_attempted_semesters[$program_id] = array();
  573. foreach ($resultados_prog as $out => $datos_out) {
  574. $outcomes_achieved[$program_id][$out] = 0;
  575. $outcomes_attempted[$program_id][$out] = 0;
  576. // var_dump($datos_out);outcomes_attempted_semesters
  577. $outcomes_attempted_semesters[$program_id][$out] = $datos_out['semesters'];
  578. unset($datos_out['semesters']);
  579. // var_dump($outcomes_attempted_semesters[$program_id][$out]);
  580. // var_dump($datos_out);
  581. // exit();
  582. foreach ($datos_out as $res) {
  583. $outcomes_attempted[$program_id][$out]++;
  584. if (3 * $res['achieved'] >= 2 * $res['attempted'])
  585. $outcomes_achieved[$program_id][$out]++;
  586. }
  587. }
  588. $programs[] = Program::find($program_id);
  589. if (Program::find($program_id)->is_graduate) {
  590. $colapso = array(1 => array(), 3 => array(), 2 => array(11), 12 => array(7, 14), 10 => array(), 4 => array(6, 15));
  591. } else {
  592. $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());
  593. }
  594. $resultados_todos_colap[$program_id] = array();
  595. foreach ($colapso as $out => $pares) {
  596. $resultados_todos_colap[$program_id][$out]["semesters"] = array();
  597. if (isset($resultados_todos[$program_id][$out]))
  598. $resultados_todos_colap[$program_id][$out] = $resultados_todos[$program_id][$out];
  599. else $resultados_todos_colap[$program_id][$out] = array();
  600. foreach ($pares as $par) {
  601. if (isset($resultados_todos[$program_id][$par])) {
  602. // unset($resultados_todos[$program_id][$par]['semesters']);
  603. foreach ($resultados_todos[$program_id][$par] as $estu => $resus) {
  604. if ($estu != "semesters") {
  605. if (!isset($resultados_todos_colap[$program_id][$out][$estu])) {
  606. $resultados_todos_colap[$program_id][$out][$estu]['attempted'] = 0;
  607. $resultados_todos_colap[$program_id][$out][$estu]['achieved'] = 0;
  608. }
  609. // print $program_id." ".$par." ".$estu."<br>";
  610. // var_dump($resultados_todos[$program_id][$par][$estu]);
  611. $resultados_todos_colap[$program_id][$out][$estu]['attempted'] += $resultados_todos[$program_id][$par][$estu]['attempted'];
  612. $resultados_todos_colap[$program_id][$out][$estu]['achieved'] += $resultados_todos[$program_id][$par][$estu]['achieved'];
  613. } else if (isset($resultados_todos[$program_id][$par]["semesters"])) {
  614. if (isset($resultados_todos_colap[$program_id][$out]["semesters"])) {
  615. $tmp = array_merge($resultados_todos_colap[$program_id][$out]["semesters"], $resultados_todos[$program_id][$par]["semesters"]);
  616. // var_dump(($tmp));
  617. // var_dump(array_unique($tmp));
  618. // exit();
  619. $resultados_todos_colap[$program_id][$out]["semesters"] = array_unique($tmp);
  620. } else
  621. $resultados_todos_colap[$program_id][$out]["semesters"] = array_unique($resultados_todos[$program_id][$par]["semesters"]);
  622. }
  623. }
  624. }
  625. }
  626. }
  627. // var_dump($resultados_todos_colap);
  628. /*
  629. $outcomes_attempted_colap[$program_id] = array();
  630. $outcomes_achieved_colap[$program_id] = array();
  631. $outcomes_attempted_colap_semesters[$program_id] = array();
  632. // print $program_id."<br>";
  633. // var_dump($resultados_todos_colap[$program_id]);
  634. // print "<br>";
  635. foreach ($resultados_todos_colap[$program_id] as $out => $datos_out) {
  636. if (!$i) $outcomes_colap[] = Outcome::find($out);
  637. // $outcomes_attempted_colap_semesters[$program_id][$out]=array();
  638. if (isset($datos_out['semesters'])) {
  639. $outcomes_attempted_colap_semesters[$program_id][$out] = $datos_out['semesters'];
  640. unset($datos_out['semesters']);
  641. }
  642. foreach ($datos_out as $res) {
  643. if (!isset($outcomes_attempted_colap[$program_id][$out])) {
  644. $outcomes_attempted_colap[$program_id][$out] = 0;
  645. $outcomes_achieved_colap[$program_id][$out] = 0;
  646. }
  647. $outcomes_attempted_colap[$program_id][$out]++;
  648. if (3 * $res['achieved'] >= 2 * $res['attempted'])
  649. $outcomes_achieved_colap[$program_id][$out]++;
  650. }
  651. if (empty($datos_out)) {
  652. $outcomes_attempted_colap[$program_id][$out] = 0;
  653. $outcomes_achieved_colap[$program_id][$out] = 0;
  654. }
  655. }
  656. $i++;
  657. }
  658. /*
  659. usort($outcomes_colap, array($this, "cmp"));
  660. // var_dump($outcomes_attempted_colap); print "<br>";
  661. // var_dump($outcomes_achieved_colap); print "<br>";
  662. // exit();
  663. $outcomes_attempted_colap_todo = array();
  664. $outcomes_achieved_colap_todo = array();
  665. foreach ($outcomes_attempted_colap as $program_id => $out_res) {
  666. foreach ($out_res as $out => $res) {
  667. if (!isset($outcomes_attempted_colap_todo[$out])) {
  668. $outcomes_attempted_colap_todo[$out] = 0;
  669. $outcomes_achieved_colap_todo[$out] = 0;
  670. }
  671. $outcomes_attempted_colap_todo[$out] += $outcomes_attempted_colap[$program_id][$out];
  672. $outcomes_achieved_colap_todo[$out] += $outcomes_achieved_colap[$program_id][$out];
  673. }
  674. }
  675. /*
  676. $outcomes_attempted_todo = array();
  677. $outcomes_achieved_todo = array();
  678. foreach ($outcomes_attempted as $program_id => $out_res) {
  679. foreach ($out_res as $out => $res) {
  680. if (!isset($outcomes_attempted_todo[$out])) {
  681. $outcomes_attempted_todo[$out] = 0;
  682. $outcomes_achieved_todo[$out] = 0;
  683. }
  684. $outcomes_attempted_todo[$out] += $outcomes_attempted[$program_id][$out];
  685. $outcomes_achieved_todo[$out] += $outcomes_achieved[$program_id][$out];
  686. }
  687. }*/
  688. $info = $school->school_students_per_outcome;
  689. Log::info("BRR");
  690. Log::info($info);
  691. $outcomes_undergraduate_achieved_colap_todo = $info['undergraduate_info']['outcomes_achieved_combined'];
  692. $outcomes_undergraduate_attempted_colap_todo = $info['undergraduate_info']['outcomes_attempted_combined'];
  693. $outcomes_undergraduate_achieved_todo = $info['undergraduate_info']['outcomes_achieved_uncombined'];
  694. $outcomes_undergraduate_attempted_todo = $info['undergraduate_info']['outcomes_attempted_uncombined'];
  695. $outcomes_graduate_achieved_colap_todo = $info['graduate_info']['outcomes_achieved_combined'];
  696. $outcomes_graduate_attempted_colap_todo = $info['graduate_info']['outcomes_attempted_combined'];
  697. $outcomes_graduate_achieved_todo = $info['graduate_info']['outcomes_achieved_uncombined'];
  698. $outcomes_graduate_attempted_todo = $info['graduate_info']['outcomes_attempted_uncombined'];
  699. $outcomes_undergrad_program_attempted_colap = $info['undergraduate_info']['programs_attempted_combined'];
  700. $outcomes_undergrad_program_achieved_colap = $info['undergraduate_info']['programs_achieved_combined'];
  701. $outcomes_grad_program_attempted_colap = $info['graduate_info']['programs_attempted_combined'];
  702. $outcomes_grad_program_achieved_colap = $info['graduate_info']['programs_achieved_combined'];
  703. Log::info("mera");
  704. Log::info($outcomes_grad_program_attempted_colap);
  705. $outcomes_undergrad_program_attempted_todo = $info['undergraduate_info']['programs_attempted_uncombined'];
  706. $outcomes_undergrad_program_achieved_todo = $info['undergraduate_info']['programs_achieved_uncombined'];
  707. $outcomes_grad_program_attempted_todo = $info['graduate_info']['programs_attempted_uncombined'];
  708. $outcomes_grad_program_achieved_todo = $info['graduate_info']['programs_achieved_uncombined'];
  709. $undergraduate_programs = $school->undergraduate_programs->get();
  710. $graduate_programs = $school->graduate_programs->get();
  711. return View::make('local.managers.shared.school_student_result', compact(
  712. 'title', #'outcomes_attempted_colap_semesters', 'outcomes_attempted_semesters',
  713. 'outcomes_undergraduate_attempted_colap_todo',
  714. 'outcomes_undergraduate_achieved_colap_todo',
  715. 'outcomes_undergraduate_attempted_todo',
  716. 'outcomes_undergraduate_achieved_todo',
  717. 'outcomes_graduate_attempted_colap_todo',
  718. 'outcomes_graduate_achieved_colap_todo',
  719. 'outcomes_graduate_attempted_todo',
  720. 'outcomes_graduate_achieved_todo',
  721. 'outcomes_undergrad_program_attempted_colap',
  722. 'outcomes_undergrad_program_achieved_colap',
  723. 'outcomes_grad_program_attempted_colap',
  724. 'outcomes_grad_program_achieved_colap',
  725. 'outcomes_undergrad_program_attempted_todo',
  726. 'outcomes_undergrad_program_achieved_todo',
  727. 'outcomes_grad_program_attempted_todo',
  728. 'outcomes_grad_program_achieved_todo',
  729. 'undergraduate_programs',
  730. 'graduate_programs',
  731. 'school',
  732. 'programs_name',
  733. 'role',
  734. 'outcomes',
  735. 'outcomes_colap',
  736. 'outcomes_attempted',
  737. 'outcomes_achieved',
  738. 'outcomes_attempted_colap',
  739. 'outcomes_achieved_colap',
  740. 'programs',
  741. 'users',
  742. 'program_courses',
  743. 'grouped_courses'
  744. ));
  745. }
  746. public function showQuasiOri($id)
  747. {
  748. ini_set('memory_limit', '256M');
  749. DB::connection()->disableQueryLog();
  750. $school = School::find($id);
  751. $title = $school->name;
  752. $schools = School::all();
  753. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  754. // $outcomeCount = Outcome::all()->count();
  755. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  756. // var_dump($semesters);
  757. // exit();
  758. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  759. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  760. /**
  761. * List of grouped courses (grouped sections)
  762. */
  763. $program_ids = $school->programs->lists('id');
  764. $undergrad_programs = DB::table('programs')
  765. ->select('id', 'name', 'school_id', 'is_graduate')
  766. ->where('is_graduate', '=', 0)
  767. ->where('school_id', '=', $id)
  768. ->orderBy('name', 'ASC')
  769. ->get();
  770. $grad_programs = DB::table('programs')
  771. ->select('id', 'name', 'school_id', 'is_graduate')
  772. ->where('is_graduate', '=', 1)
  773. ->where('school_id', '=', $id)
  774. ->orderBy('name', 'ASC')
  775. ->get();
  776. $grad_grouped_courses = Course::
  777. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  778. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  779. ->with('semester')
  780. ->with('program')
  781. ->whereIn('courses.program_id', $program_ids)
  782. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  783. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  784. ->where('programs.is_graduate', '=', 1)
  785. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  786. ->orderBy('courses.code')
  787. ->orderBy('courses.number')
  788. ->orderBy('courses.semester_id')
  789. ->get();
  790. $undergrad_grouped_courses = Course::
  791. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  792. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  793. ->with('semester')
  794. ->with('program')
  795. ->whereIn('courses.program_id', $program_ids)
  796. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  797. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  798. ->where('programs.is_graduate', '=', 0)
  799. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  800. ->orderBy('courses.code')
  801. ->orderBy('courses.number')
  802. ->orderBy('courses.semester_id')
  803. ->get();
  804. // Fetch programs with participation
  805. $participating_programs = $this->participatingPrograms($school);
  806. /**
  807. * Calculate how many sections are doing assessment
  808. */
  809. // $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  810. // $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  811. $undergrad_assessed_sections_count = 0;
  812. $undergrad_school_sections_count = 0;
  813. // $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  814. // $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  815. $grad_assessed_sections_count = 0;
  816. $grad_school_sections_count = 0;
  817. foreach ($school->programs as $program) {
  818. foreach ($program->courses as $course) {
  819. // Log::info("aqui".$course);
  820. if (!$course->program->is_graduate) {
  821. $undergrad_school_sections_count += 1;
  822. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  823. // Log::info("aqui".$course);
  824. } else {
  825. $grad_school_sections_count += 1;
  826. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  827. // Log::info("aqui".$course);
  828. }
  829. // if (!$course->program->is_graduate) {
  830. // if ($course->outcomes_achieved != NULL) {
  831. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  832. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  833. // for ($i = 1; $i <= count($undergrad_outcomes_attempted); $i++) {
  834. // $undergrad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  835. // $undergrad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  836. // }
  837. // $undergrad_assessed_sections_count += 1;
  838. // }
  839. // $undergrad_school_sections_count += 1;
  840. // } else {
  841. // if ($course->outcomes_achieved != NULL) {
  842. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  843. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  844. // for ($i = 1; $i <= count($grad_outcomes_attempted); $i++) {
  845. // $grad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  846. // $grad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  847. // }
  848. // $grad_assessed_sections_count += 1;
  849. // }
  850. // $grad_school_sections_count += 1;
  851. // }
  852. }
  853. }
  854. /**
  855. * Calculate how many programs achieved and attempted each outcome in this school
  856. */
  857. // Number of programs that achieved a particular learning outcome
  858. // $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  859. // Number of programs that attempted a particular learning outcome
  860. // $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  861. // Fetch programs with participation for the school
  862. // $participating_undergrad_programs = DB::table('programs')
  863. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  864. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  865. // ->addSelect('courses.semester_id')
  866. // ->whereIn('semester_id', Session::get('semesters_ids'))
  867. // ->where('is_graduate', 0)
  868. // ->where('school_id', $school->id)
  869. // ->groupBy('id')
  870. // ->get();
  871. $output = array();
  872. // For each outcome
  873. foreach ($outcomes_undergrad as $outcome) {
  874. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  875. $achieved_outcomes_per_undergrad_program[$outcome->id] = 0;
  876. $attemptedUndergradProgramsPerOutcome[$outcome->id] = 0;
  877. $achievedUndergradProgramsPerOutcome[$outcome->id] = 0;
  878. $programs_attempted_in_school[$outcome->id] = $outcome->programs_attempted_in_school($semesters, $school->id);
  879. // var_dump($programs_attempted_in_school);exit();
  880. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  881. // var_dump($program_id->id);exit();
  882. $program = DB::table('programs')
  883. ->where('id', '=', $program_id->id)
  884. ->first();
  885. // $program=Program::where('id', $program_id->id);
  886. // var_dump($program);exit();
  887. if (!$program->is_graduate) {
  888. $attemptedUndergradProgramsPerOutcome[$outcome->id]++;
  889. }
  890. }
  891. $undergrad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 0);
  892. $undergrad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 0);
  893. // For each program with courses that do assessment
  894. $programs_with_courses = Program::with(array('courses' => function ($query) {
  895. // $query->whereNotNull('outcomes_attempted');
  896. $query->whereIn('semester_id', Session::get('semesters_ids'));
  897. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  898. foreach ($programs_with_courses as $program) {
  899. if (in_array($program->id, $participating_programs)) {
  900. // To acummulate all criteria for one program
  901. // $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  902. // $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  903. //Flag for counting programs
  904. $flag = false;
  905. // For each course in the program
  906. // foreach ($program->courses as $course) {
  907. // if($course->isAssessed()){
  908. // // If the outcome in question is being evaluated
  909. // $course_outcomes_attempted2 = $course->outcomes_att();
  910. // // $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  911. // // $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  912. // $course_outcomes_achieved2 = $course->outcomes_ach();
  913. // if (
  914. // array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  915. // && $course_outcomes_attempted2[$outcome->id] > 0
  916. // ) {
  917. // $achieved_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  918. // // $attempted_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  919. //
  920. // // Add one to the programs assessing, if it wasn't added before
  921. // if (!$flag) {
  922. // $attemptedUndergradProgramsPerOutcome[$outcome->id] += 1;
  923. // $flag = true;
  924. // }
  925. // }
  926. //
  927. // // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  928. // // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  929. // }
  930. // }
  931. //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
  932. // 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) {
  933. // $achievedUndergradProgramsPerOutcome[$outcome->id] += 1;
  934. // // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  935. // }
  936. }
  937. }
  938. }
  939. /**
  940. * Calculate how many programs achieved and attempted each outcome in this school
  941. */
  942. // Number of programs that achieved a particular learning outcome
  943. // $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  944. // Number of programs that attempted a particular learning outcome
  945. // $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  946. //
  947. // Fetch programs with participation for the school
  948. // $participating_grad_programs = DB::table('programs')
  949. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  950. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  951. // ->addSelect('courses.semester_id')
  952. // ->whereIn('semester_id', Session::get('semesters_ids'))
  953. // ->where('is_graduate', 1)
  954. // ->where('school_id', $school->id)
  955. // ->groupBy('id')
  956. // ->get();
  957. $output = array();
  958. // For each outcome
  959. foreach ($outcomes_grad as $outcome) {
  960. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  961. $achieved_outcomes_per_grad_program[$outcome->id] = 0;
  962. $attemptedGradProgramsPerOutcome[$outcome->id] = 0;
  963. $achievedGradProgramsPerOutcome[$outcome->id] = 0;
  964. $grad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 1);
  965. $grad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 1);
  966. // For each program with courses that do assessment
  967. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  968. // var_dump($program_id->id);exit();
  969. $program = DB::table('programs')
  970. ->where('id', '=', $program_id->id)
  971. ->first();
  972. // $program=Program::where('id', $program_id->id);
  973. // var_dump($program);exit();
  974. if ($program->is_graduate) {
  975. $attemptedGradProgramsPerOutcome[$outcome->id]++;
  976. }
  977. }
  978. $programs_with_courses = Program::with(array('courses' => function ($query) {
  979. // $query->whereNotNull('outcomes_attempted');
  980. $query->whereIn('semester_id', Session::get('semesters_ids'));
  981. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  982. foreach ($programs_with_courses as $program) {
  983. if (in_array($program->id, $participating_programs)) {
  984. // To acummulate all criteria for one program
  985. // $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  986. // $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  987. //Flag for counting programs
  988. $flag = false;
  989. // For each course in the program
  990. foreach ($program->courses as $course) {
  991. if ($course->isAssessed()) {
  992. // If the outcome in question is being evaluated
  993. // $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  994. $course_outcomes_attempted2 = ($course->outcomes_att());
  995. $course_outcomes_achieved2 = ($course->outcomes_ach());
  996. // $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  997. if (
  998. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  999. && $course_outcomes_attempted2[$outcome->id] > 0
  1000. ) {
  1001. $achieved_outcomes_per_grad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  1002. $attempted_outcomes_per_grad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  1003. // Add one to the programs assessing, if it wasn't added before
  1004. if (!$flag) {
  1005. $attemptedGradProgramsPerOutcome[$outcome->id] += 1;
  1006. $flag = true;
  1007. }
  1008. }
  1009. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_program);
  1010. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  1011. }
  1012. }
  1013. //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
  1014. 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) {
  1015. $achievedGradProgramsPerOutcome[$outcome->id] += 1;
  1016. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  1017. }
  1018. }
  1019. }
  1020. }
  1021. if ($school->id == 13) {
  1022. // 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'));
  1023. 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'));
  1024. } else {
  1025. // 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'));
  1026. 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'));
  1027. }
  1028. }
  1029. public function print_school($id)
  1030. {
  1031. ini_set('memory_limit', '256M');
  1032. DB::connection()->disableQueryLog();
  1033. $school = School::find($id);
  1034. $title = $school->name . ' Assessment Report - ' . date('m/d/Y');
  1035. $outcomes = Outcome::orderBy('name', 'asc')->get();
  1036. $outcomeCount = Outcome::all()->count();
  1037. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  1038. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  1039. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  1040. $undergrad_stu_outcome_attempted = [];
  1041. $grad_stu_outcome_attempted = [];
  1042. $undergrad_stu_outcome_achieved = [];
  1043. $grad_stu_outcome_achieved = [];
  1044. $attemptedUndergradProgramsPerOutcome = [];
  1045. $achievedUndergradProgramsPerOutcome = [];
  1046. $attemptedGradProgramsPerOutcome = [];
  1047. $achievedGradProgramsPerOutcome = [];
  1048. foreach ($outcomes_undergrad as $outcome) {
  1049. $undergrad_stu_outcome_attempted[$outcome->id] = 0;
  1050. $undergrad_stu_outcome_achieved[$outcome->id] = 0;
  1051. $attemptedUndergradProgramsPerOutcome[$outcome->id] = [];
  1052. $achievedUndergradProgramsPerOutcome[$outcome->id] = [];
  1053. }
  1054. foreach ($outcomes_grad as $outcome) {
  1055. $grad_stu_outcome_attempted[$outcome->id] = 0;
  1056. $grad_stu_outcome_achieved[$outcome->id] = 0;
  1057. $attemptedGradProgramsPerOutcome[$outcome->id] = [];
  1058. $achievedGradProgramsPerOutcome[$outcome->id] = [];
  1059. }
  1060. /**
  1061. * List of courses (grouped sections)
  1062. */
  1063. $program_ids = $school->programs->lists('id');
  1064. $undergrad_programs = DB::table('programs')
  1065. ->select('id', 'name', 'school_id', 'is_graduate')
  1066. ->where('is_graduate', '=', 0)
  1067. ->where('school_id', '=', $id)
  1068. ->orderBy('name', 'ASC')
  1069. ->get();
  1070. $grad_programs = DB::table('programs')
  1071. ->select('id', 'name', 'school_id', 'is_graduate')
  1072. ->where('is_graduate', '=', 1)
  1073. ->where('school_id', '=', $id)
  1074. ->orderBy('name', 'ASC')
  1075. ->get();
  1076. //quiero ver si monto el query tm aqui
  1077. $undergrad_programs_list = DB::table('programs')
  1078. ->select('id', 'name', 'school_id', 'is_graduate')
  1079. ->where('is_graduate', '=', 0)
  1080. ->where('school_id', '=', $id)
  1081. ->orderBy('name', 'ASC')
  1082. ->lists('id');
  1083. $grad_programs_list = DB::table('programs')
  1084. ->select('id', 'name', 'school_id', 'is_graduate')
  1085. ->where('is_graduate', '=', 1)
  1086. ->where('school_id', '=', $id)
  1087. ->orderBy('name', 'ASC')
  1088. ->lists('id');
  1089. /*
  1090. $undergraduate_student_query = DB::table("courses")
  1091. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1092. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  1093. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  1094. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  1095. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  1096. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  1097. ->join('program_criterion_objective_outcome as poco', function ($q) {
  1098. $q->on('courses.program_id', '=', 'poco.program_id')
  1099. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  1100. })
  1101. ->join('students', 'students.id', '=', 'assessments.student_id')
  1102. ->whereIn('poco.program_id', $undergrad_programs_list)
  1103. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  1104. ->whereIn('courses.program_id', $undergrad_programs_list)
  1105. ->select('students.number as student_id')
  1106. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  1107. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  1108. ->addSelect('outcome_id')
  1109. ->groupBy(array('students.id', 'outcome_id'))
  1110. ->get();
  1111. //Log::info($undergraduate_student_query);
  1112. $grad_student_query = DB::table("courses")
  1113. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1114. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  1115. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  1116. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  1117. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  1118. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  1119. ->join('program_criterion_objective_outcome as poco', function ($q) {
  1120. $q->on('courses.program_id', '=', 'poco.program_id')
  1121. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  1122. })
  1123. ->join('students', 'students.id', '=', 'assessments.student_id')
  1124. ->whereIn('poco.program_id', $grad_programs_list)
  1125. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  1126. ->whereIn('courses.program_id', $grad_programs_list)
  1127. ->select('students.number as student_id')
  1128. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  1129. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  1130. ->addSelect('outcome_id')
  1131. ->groupBy(array('students.id', 'outcome_id'))
  1132. ->get();
  1133. */
  1134. //school
  1135. /*
  1136. student x, crit achieved, crit attempted, outcome 1
  1137. student x, crit achieved, crit attempted, outcome 2
  1138. student x, crit achieved, crit attempted, outcome 3
  1139. student x, crit achieved, crit attempted, outcome 4
  1140. student y, crit achieved, crit attempted, outcome 1
  1141. student y, crit achieved, crit attempted, outcome 2
  1142. student y, crit achieved, crit attempted, outcome 3
  1143. ....
  1144. */
  1145. $grad_outcomes_attempted = [];
  1146. $grad_outcomes_achieved = [];
  1147. $undergrad_outcomes_attempted = [];
  1148. $undergrad_outcomes_achieved = [];
  1149. $school_info = $school->school_courses_per_outcome;
  1150. $grad_outcomes_attempted = $school_info['graduate_info']['outcomes_attempted_combined'];
  1151. $grad_outcomes_achieved = $school_info['graduate_info']['outcomes_achieved_combined'];
  1152. $undergrad_outcomes_attempted = $school_info['undergraduate_info']['outcomes_attempted_combined'];
  1153. $undergrad_outcomes_achieved = $school_info['undergraduate_info']['outcomes_achieved_combined'];
  1154. $grad_grouped_courses = Course::
  1155. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  1156. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  1157. ->with('semester')
  1158. ->with('program')
  1159. ->whereIn('courses.program_id', $program_ids)
  1160. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  1161. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  1162. ->where('programs.is_graduate', '=', 1)
  1163. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  1164. ->orderBy('courses.code')
  1165. ->orderBy('courses.number')
  1166. ->orderBy('courses.semester_id')
  1167. ->get();
  1168. $undergrad_grouped_courses = Course::
  1169. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  1170. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  1171. ->with('semester')
  1172. ->with('program')
  1173. ->whereIn('courses.program_id', $program_ids)
  1174. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  1175. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  1176. ->where('programs.is_graduate', '=', 0)
  1177. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  1178. ->orderBy('courses.code')
  1179. ->orderBy('courses.number')
  1180. ->orderBy('courses.semester_id')
  1181. ->get();
  1182. foreach ($undergrad_grouped_courses as $key => $courses) {
  1183. $undergrad_grouped_courses[$key]->outcomes_attempted = NULL;
  1184. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  1185. foreach ($coursesT as $course) {
  1186. if ($course->isAssessed()) {
  1187. $undergrad_grouped_courses[$key]->outcomes_attempted = true;
  1188. }
  1189. }
  1190. }
  1191. foreach ($grad_grouped_courses as $key => $courses) {
  1192. $grad_grouped_courses[$key]->outcomes_attempted = NULL;
  1193. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  1194. foreach ($coursesT as $course) {
  1195. if ($course->isAssessed()) {
  1196. $grad_grouped_courses[$key]->outcomes_attempted = true;
  1197. }
  1198. }
  1199. }
  1200. // Fetch programs with participation
  1201. $participating_programs = $this->participatingPrograms($school);
  1202. /**
  1203. * Calculate how many sections are doing assessment
  1204. */
  1205. $undergrad_assessed_sections_count = 0;
  1206. $undergrad_school_sections_count = 0;
  1207. $grad_assessed_sections_count = 0;
  1208. $grad_school_sections_count = 0;
  1209. foreach ($school->programs as $program) {
  1210. foreach ($program->courses as $course) {
  1211. if (!$course->program->is_graduate) {
  1212. $undergrad_school_sections_count += 1;
  1213. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  1214. } else {
  1215. $grad_school_sections_count += 1;
  1216. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  1217. }
  1218. }
  1219. }
  1220. $attemptedUndergradProgramsPerOutcome = $school_info['undergraduate_info']['programs_attempted_combined'];
  1221. $achievedUndergradProgramsPerOutcome = $school_info['undergraduate_info']['programs_achieved_combined'];
  1222. $attemptedGradProgramsPerOutcome = $school_info['graduate_info']['programs_attempted_combined'];
  1223. $achievedGradProgramsPerOutcome = $school_info['graduate_info']['programs_achieved_combined'];
  1224. //como resuelvo programsAttempted y eso
  1225. /*
  1226. //El query es el mismo de students, lo unico que dividido con programas,
  1227. //asi que lo que esta haciendo es, prog 1, y coge los dominios y estudiantes que evaluason
  1228. $undergrad_prog_attempted = DB::table("courses")
  1229. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1230. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  1231. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  1232. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  1233. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  1234. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  1235. ->join('program_criterion_objective_outcome as poco', function ($q) {
  1236. $q->on('courses.program_id', '=', 'poco.program_id')
  1237. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  1238. })
  1239. ->join('students', 'students.id', '=', 'assessments.student_id')
  1240. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  1241. ->whereIn('poco.program_id', $undergrad_programs_list)
  1242. ->whereIn('courses.program_id', $undergrad_programs_list)
  1243. ->select('students.number as student_id')
  1244. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  1245. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  1246. ->addSelect('outcome_id')
  1247. ->addSelect("courses.program_id")
  1248. ->groupBy(array('students.id', 'outcome_id', 'program_id'))
  1249. ->get();
  1250. $grad_prog_attempted = DB::table("courses")
  1251. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1252. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  1253. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  1254. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  1255. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  1256. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  1257. ->join('program_criterion_objective_outcome as poco', function ($q) {
  1258. $q->on('courses.program_id', '=', 'poco.program_id')
  1259. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  1260. })
  1261. ->join('students', 'students.id', '=', 'assessments.student_id')
  1262. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  1263. ->whereIn('poco.program_id', $grad_programs_list)
  1264. ->whereIn('courses.program_id', $grad_programs_list)
  1265. ->select('students.number as student_id')
  1266. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  1267. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  1268. ->addSelect('outcome_id')
  1269. ->addSelect("courses.program_id")
  1270. ->groupBy(array('students.id', 'outcome_id', 'program_id'))
  1271. ->get();
  1272. //este arreglo va a tener attempted[outcome->id][program->id]
  1273. //so la cardinalidad de attempted[outcome->id] dice cuantos programas intentaron, achieved[outcome->id], va
  1274. //a decir cuantos pasaron y attempted[outcome->id][program->id] la suma de estudiantes que intentaron
  1275. //
  1276. foreach ($undergrad_prog_attempted as $row) {
  1277. $program_id = $row->program_id;
  1278. $outcome_id = $row->outcome_id;
  1279. if (!isset($attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id]))
  1280. $attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  1281. $attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id]++;
  1282. $criteria_attempted_by_stu = $row->criteria_attempted;
  1283. $criteria_achieved_by_stu = $row->criteria_achieved;
  1284. if ($criteria_attempted_by_stu != 0 && $criteria_achieved_by_stu / $criteria_attempted_by_stu * 100 >= 66.66) {
  1285. if (!isset($achievedUndergradProgramsPerOutcome[$outcome_id][$program_id]))
  1286. $achievedUndergradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  1287. $achievedUndergradProgramsPerOutcome[$outcome_id][$program_id]++;
  1288. }
  1289. }
  1290. foreach ($grad_prog_attempted as $row) {
  1291. $program_id = $row->program_id;
  1292. $outcome_id = $row->outcome_id;
  1293. if (!isset($attemptedGradProgramsPerOutcome[$outcome_id][$program_id]))
  1294. $attemptedGradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  1295. $attemptedGradProgramsPerOutcome[$outcome_id][$program_id]++;
  1296. $criteria_attempted_by_stu = $row->criteria_attempted;
  1297. $criteria_achieved_by_stu = $row->criteria_achieved;
  1298. if ($criteria_attempted_by_stu != 0 && $criteria_achieved_by_stu / $criteria_attempted_by_stu * 100 >= 66.66) {
  1299. if (!isset($achievedGradProgramsPerOutcome[$outcome_id][$program_id]))
  1300. $achievedGradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  1301. $achievedGradProgramsPerOutcome[$outcome_id][$program_id]++;
  1302. }
  1303. }*/
  1304. //La linea negra de proposed.
  1305. //
  1306. $linea_undergrad = DB::table('target_outcomes_program')
  1307. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  1308. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  1309. ->whereIn('program_id', $undergrad_programs_list)
  1310. ->whereIn("semester_id", Session::get('semesters_ids'))
  1311. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  1312. ->addSelect(DB::raw("count(target_outcomes_program.semester_id) as count_semester_id"))
  1313. ->groupBy("expected_target")
  1314. ->orderBy("expected_target", "DESC")
  1315. ->first();
  1316. if (!isset($linea_undergrad)) {
  1317. $default_undergrad = 70;
  1318. } elseif ($linea_undergrad->count_semester_id > 1) {
  1319. $default_undergrad = null;
  1320. $linea_undergrad = DB::table('target_outcomes_program')
  1321. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  1322. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  1323. ->whereIn('program_id', $undergrad_programs_list)
  1324. ->where('expected_target', $linea_undergrad->expected_target)
  1325. ->whereIn("semester_id", Session::get('semesters_ids'))
  1326. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  1327. //->addSelect("count(semester_id) as count_semester_id")
  1328. //->groupBy("expected_target")
  1329. ->orderBy("semester_id", "DESC")
  1330. ->first();
  1331. }
  1332. $linea_grad = DB::table('target_outcomes_program')
  1333. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  1334. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  1335. ->whereIn('program_id', $grad_programs_list)
  1336. ->whereIn("semester_id", Session::get('semesters_ids'))
  1337. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  1338. ->addSelect(DB::raw("count(target_outcomes_program.semester_id) as count_semester_id"))
  1339. ->groupBy("expected_target")
  1340. ->orderBy("expected_target", "DESC")
  1341. ->first();
  1342. if (!isset($linea_grad)) {
  1343. $default_grad = 70;
  1344. } elseif ($linea_grad->count_semester_id > 1) {
  1345. $default_grad = null;
  1346. $linea_grad = DB::table('target_outcomes_program')
  1347. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  1348. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  1349. ->whereIn('program_id', $grad_programs_list)
  1350. ->where('expected_target', $linea_grad->expected_target)
  1351. ->whereIn("semester_id", Session::get('semesters_ids'))
  1352. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  1353. ->orderBy("semester_id", "DESC")
  1354. ->first();
  1355. }
  1356. $expected_target_for_undergradprograms = !isset($linea_undergrad) ? $default_undergrad : $linea_undergrad->expected_target;
  1357. $expected_target_for_gradprograms = !isset($linea_grad) ? $default_grad : $linea_grad->expected_target;
  1358. //Log::info($default_grad);
  1359. $undergrad_programs = $school->undergraduate_programs->get();
  1360. $grad_programs = $school->graduate_programs->get();
  1361. if ($school->id == 13) {
  1362. // 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'));
  1363. return View::make('local.managers.shared.print_school', compact('title', 'expected_target_for_undergradprograms', 'expected_target_for_gradprograms', 'undergrad_programs', 'grad_programs', 'default_undergrad', 'default_grad', 'linea_undergrad', 'linea_grad', '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'));
  1364. } else {
  1365. // 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'));
  1366. return View::make('local.managers.shared.print_school', compact('title', 'expected_target_for_undergradprograms', 'expected_target_for_gradprograms', 'undergrad_programs', 'grad_programs', 'default_undergrad', 'default_grad', 'linea_undergrad', 'linea_grad', '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'));
  1367. }
  1368. $grouped_courses = Course::
  1369. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  1370. select(DB::raw('name, code, number, semester_id, program_id'))
  1371. ->with('semester')
  1372. ->with('program')
  1373. ->whereIn('program_id', $program_ids)
  1374. ->whereIn('semester_id', Session::get('semesters_ids'))
  1375. ->groupBy(array('code', 'number', 'semester_id'))
  1376. ->orderBy('code')
  1377. ->orderBy('number')
  1378. ->orderBy('semester_id')
  1379. ->get();
  1380. // Fetch programs with participation
  1381. $participating_programs = $this->participatingPrograms($school);
  1382. /**
  1383. * Calculate how many sections are doing assessment
  1384. */
  1385. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  1386. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  1387. $assessed_sections_count = 0;
  1388. $school_sections_count = 0;
  1389. foreach ($school->programs as $program) {
  1390. foreach ($program->courses as $course) {
  1391. if ($course->outcomes_achieved != NULL) {
  1392. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  1393. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  1394. for ($i = 1; $i <= count($outcomes_attempted); $i++) {
  1395. $outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  1396. $outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  1397. }
  1398. $assessed_sections_count += 1;
  1399. }
  1400. $school_sections_count += 1;
  1401. }
  1402. }
  1403. /**
  1404. * Calculate how many programs achieved and attempted each outcome in this school
  1405. */
  1406. // Number of programs that achieved a particular learning outcome
  1407. $achievedProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  1408. // Number of programs that attempted a particular learning outcome
  1409. $attemptedProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  1410. $output = array();
  1411. // For each outcome
  1412. foreach ($outcomes as $outcome) {
  1413. // For each program with courses that do assessment
  1414. foreach (Program::with(array('courses' => function ($query) {
  1415. // $query->whereNotNull('outcomes_attempted');
  1416. $query->whereIn('semester_id', Session::get('semesters_ids'));
  1417. }))->where('school_id', $school->id)->orderBy('name', 'asc')->get() as $program) {
  1418. // To acummulate all criteria for one program
  1419. $achieved_outcomes_per_program = array_fill(1, $outcomeCount, 0);
  1420. $attempted_outcomes_per_program = array_fill(1, $outcomeCount, 0);
  1421. //Flag for counting programs
  1422. $flag = false;
  1423. // For each course in the program
  1424. foreach ($program->courses as $course) {
  1425. // If the outcome in question is being evaluated
  1426. $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  1427. $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  1428. if (
  1429. array_key_exists($outcome->id, $course_outcomes_attempted2)
  1430. && $course_outcomes_attempted2[$outcome->id] > 0
  1431. ) {
  1432. $achieved_outcomes_per_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  1433. $attempted_outcomes_per_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  1434. // Add one to the programs assessing, if it wasn't added before
  1435. if (!$flag) {
  1436. $attemptedProgramsPerOutcome[$outcome->id] += 1;
  1437. $flag = true;
  1438. }
  1439. }
  1440. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_program);
  1441. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  1442. }
  1443. //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
  1444. 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) {
  1445. $achievedProgramsPerOutcome[$outcome->id] += 1;
  1446. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  1447. }
  1448. }
  1449. }
  1450. 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'));
  1451. }
  1452. }