Ingen beskrivning

SchoolsController.php 96KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764
  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.67) {
  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.67) {
  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. $resultados_todos=array();
  547. foreach ($resultados_todos_obj as $resultado) {
  548. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'])) {
  549. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'] = array();
  550. }
  551. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'][] = $resultado->code;
  552. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'] = array_unique($resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters']);
  553. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted'])) {
  554. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted'] = 0;
  555. }
  556. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted']++;
  557. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved'])) {
  558. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved'] = 0;
  559. }
  560. if ($resultado->score >= $resultado->expected_points) {
  561. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved']++;
  562. }
  563. }
  564. $outcomes_colap = array();
  565. $programs = array();
  566. // $outcomes_colap=array();
  567. $i = 0;
  568. $outcomes_attempted = array();
  569. $outcomes_attempted_colap = array();
  570. $outcomes_achieved_colap = array();
  571. $outcomes_attempted_semesters = array();
  572. foreach ($resultados_todos as $program_id => $resultados_prog) {
  573. $outcomes_attempted_semesters[$program_id] = array();
  574. foreach ($resultados_prog as $out => $datos_out) {
  575. $outcomes_achieved[$program_id][$out] = 0;
  576. $outcomes_attempted[$program_id][$out] = 0;
  577. // var_dump($datos_out);outcomes_attempted_semesters
  578. $outcomes_attempted_semesters[$program_id][$out] = $datos_out['semesters'];
  579. unset($datos_out['semesters']);
  580. // var_dump($outcomes_attempted_semesters[$program_id][$out]);
  581. // var_dump($datos_out);
  582. // exit();
  583. foreach ($datos_out as $res) {
  584. $outcomes_attempted[$program_id][$out]++;
  585. if (3 * $res['achieved'] >= 2 * $res['attempted'])
  586. $outcomes_achieved[$program_id][$out]++;
  587. }
  588. }
  589. $programs[] = Program::find($program_id);
  590. if (Program::find($program_id)->is_graduate) {
  591. $colapso = array(1 => array(), 3 => array(), 2 => array(11), 12 => array(7, 14), 10 => array(), 4 => array(6, 15));
  592. } else {
  593. $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());
  594. }
  595. $resultados_todos_colap[$program_id] = array();
  596. foreach ($colapso as $out => $pares) {
  597. $resultados_todos_colap[$program_id][$out]["semesters"] = array();
  598. if (isset($resultados_todos[$program_id][$out]))
  599. $resultados_todos_colap[$program_id][$out] = $resultados_todos[$program_id][$out];
  600. else $resultados_todos_colap[$program_id][$out] = array();
  601. foreach ($pares as $par) {
  602. if (isset($resultados_todos[$program_id][$par])) {
  603. // unset($resultados_todos[$program_id][$par]['semesters']);
  604. foreach ($resultados_todos[$program_id][$par] as $estu => $resus) {
  605. if ($estu != "semesters") {
  606. if (!isset($resultados_todos_colap[$program_id][$out][$estu])) {
  607. $resultados_todos_colap[$program_id][$out][$estu]['attempted'] = 0;
  608. $resultados_todos_colap[$program_id][$out][$estu]['achieved'] = 0;
  609. }
  610. // print $program_id." ".$par." ".$estu."<br>";
  611. // var_dump($resultados_todos[$program_id][$par][$estu]);
  612. $resultados_todos_colap[$program_id][$out][$estu]['attempted'] += $resultados_todos[$program_id][$par][$estu]['attempted'];
  613. $resultados_todos_colap[$program_id][$out][$estu]['achieved'] += $resultados_todos[$program_id][$par][$estu]['achieved'];
  614. } else if (isset($resultados_todos[$program_id][$par]["semesters"])) {
  615. if (isset($resultados_todos_colap[$program_id][$out]["semesters"])) {
  616. $tmp = array_merge($resultados_todos_colap[$program_id][$out]["semesters"], $resultados_todos[$program_id][$par]["semesters"]);
  617. // var_dump(($tmp));
  618. // var_dump(array_unique($tmp));
  619. // exit();
  620. $resultados_todos_colap[$program_id][$out]["semesters"] = array_unique($tmp);
  621. } else
  622. $resultados_todos_colap[$program_id][$out]["semesters"] = array_unique($resultados_todos[$program_id][$par]["semesters"]);
  623. }
  624. }
  625. }
  626. }
  627. }
  628. // var_dump($resultados_todos_colap);
  629. /*
  630. $outcomes_attempted_colap[$program_id] = array();
  631. $outcomes_achieved_colap[$program_id] = array();
  632. $outcomes_attempted_colap_semesters[$program_id] = array();
  633. // print $program_id."<br>";
  634. // var_dump($resultados_todos_colap[$program_id]);
  635. // print "<br>";
  636. foreach ($resultados_todos_colap[$program_id] as $out => $datos_out) {
  637. if (!$i) $outcomes_colap[] = Outcome::find($out);
  638. // $outcomes_attempted_colap_semesters[$program_id][$out]=array();
  639. if (isset($datos_out['semesters'])) {
  640. $outcomes_attempted_colap_semesters[$program_id][$out] = $datos_out['semesters'];
  641. unset($datos_out['semesters']);
  642. }
  643. foreach ($datos_out as $res) {
  644. if (!isset($outcomes_attempted_colap[$program_id][$out])) {
  645. $outcomes_attempted_colap[$program_id][$out] = 0;
  646. $outcomes_achieved_colap[$program_id][$out] = 0;
  647. }
  648. $outcomes_attempted_colap[$program_id][$out]++;
  649. if (3 * $res['achieved'] >= 2 * $res['attempted'])
  650. $outcomes_achieved_colap[$program_id][$out]++;
  651. }
  652. if (empty($datos_out)) {
  653. $outcomes_attempted_colap[$program_id][$out] = 0;
  654. $outcomes_achieved_colap[$program_id][$out] = 0;
  655. }
  656. }
  657. $i++;
  658. }
  659. /*
  660. usort($outcomes_colap, array($this, "cmp"));
  661. // var_dump($outcomes_attempted_colap); print "<br>";
  662. // var_dump($outcomes_achieved_colap); print "<br>";
  663. // exit();
  664. $outcomes_attempted_colap_todo = array();
  665. $outcomes_achieved_colap_todo = array();
  666. foreach ($outcomes_attempted_colap as $program_id => $out_res) {
  667. foreach ($out_res as $out => $res) {
  668. if (!isset($outcomes_attempted_colap_todo[$out])) {
  669. $outcomes_attempted_colap_todo[$out] = 0;
  670. $outcomes_achieved_colap_todo[$out] = 0;
  671. }
  672. $outcomes_attempted_colap_todo[$out] += $outcomes_attempted_colap[$program_id][$out];
  673. $outcomes_achieved_colap_todo[$out] += $outcomes_achieved_colap[$program_id][$out];
  674. }
  675. }
  676. /*
  677. $outcomes_attempted_todo = array();
  678. $outcomes_achieved_todo = array();
  679. foreach ($outcomes_attempted as $program_id => $out_res) {
  680. foreach ($out_res as $out => $res) {
  681. if (!isset($outcomes_attempted_todo[$out])) {
  682. $outcomes_attempted_todo[$out] = 0;
  683. $outcomes_achieved_todo[$out] = 0;
  684. }
  685. $outcomes_attempted_todo[$out] += $outcomes_attempted[$program_id][$out];
  686. $outcomes_achieved_todo[$out] += $outcomes_achieved[$program_id][$out];
  687. }
  688. }*/
  689. $info = $school->school_students_per_outcome;
  690. Log::info("BRR");
  691. Log::info($info);
  692. $outcomes_undergraduate_achieved_colap_todo = $info['undergraduate_info']['outcomes_achieved_combined'];
  693. $outcomes_undergraduate_attempted_colap_todo = $info['undergraduate_info']['outcomes_attempted_combined'];
  694. $outcomes_undergraduate_achieved_todo = $info['undergraduate_info']['outcomes_achieved_uncombined'];
  695. $outcomes_undergraduate_attempted_todo = $info['undergraduate_info']['outcomes_attempted_uncombined'];
  696. $outcomes_graduate_achieved_colap_todo = $info['graduate_info']['outcomes_achieved_combined'];
  697. $outcomes_graduate_attempted_colap_todo = $info['graduate_info']['outcomes_attempted_combined'];
  698. $outcomes_graduate_achieved_todo = $info['graduate_info']['outcomes_achieved_uncombined'];
  699. $outcomes_graduate_attempted_todo = $info['graduate_info']['outcomes_attempted_uncombined'];
  700. $outcomes_undergrad_program_attempted_colap = $info['undergraduate_info']['programs_attempted_combined'];
  701. $outcomes_undergrad_program_achieved_colap = $info['undergraduate_info']['programs_achieved_combined'];
  702. $outcomes_grad_program_attempted_colap = $info['graduate_info']['programs_attempted_combined'];
  703. $outcomes_grad_program_achieved_colap = $info['graduate_info']['programs_achieved_combined'];
  704. Log::info("mera");
  705. Log::info($outcomes_grad_program_attempted_colap);
  706. $outcomes_undergrad_program_attempted_todo = $info['undergraduate_info']['programs_attempted_uncombined'];
  707. $outcomes_undergrad_program_achieved_todo = $info['undergraduate_info']['programs_achieved_uncombined'];
  708. $outcomes_grad_program_attempted_todo = $info['graduate_info']['programs_attempted_uncombined'];
  709. $outcomes_grad_program_achieved_todo = $info['graduate_info']['programs_achieved_uncombined'];
  710. $undergraduate_programs = $school->undergraduate_programs->get();
  711. $graduate_programs = $school->graduate_programs->get();
  712. return View::make('local.managers.shared.school_student_result', compact(
  713. 'title', #'outcomes_attempted_colap_semesters', 'outcomes_attempted_semesters',
  714. 'outcomes_undergraduate_attempted_colap_todo',
  715. 'outcomes_undergraduate_achieved_colap_todo',
  716. 'outcomes_undergraduate_attempted_todo',
  717. 'outcomes_undergraduate_achieved_todo',
  718. 'outcomes_graduate_attempted_colap_todo',
  719. 'outcomes_graduate_achieved_colap_todo',
  720. 'outcomes_graduate_attempted_todo',
  721. 'outcomes_graduate_achieved_todo',
  722. 'outcomes_undergrad_program_attempted_colap',
  723. 'outcomes_undergrad_program_achieved_colap',
  724. 'outcomes_grad_program_attempted_colap',
  725. 'outcomes_grad_program_achieved_colap',
  726. 'outcomes_undergrad_program_attempted_todo',
  727. 'outcomes_undergrad_program_achieved_todo',
  728. 'outcomes_grad_program_attempted_todo',
  729. 'outcomes_grad_program_achieved_todo',
  730. 'undergraduate_programs',
  731. 'graduate_programs',
  732. 'school',
  733. 'programs_name',
  734. 'role',
  735. 'outcomes',
  736. 'outcomes_colap',
  737. 'outcomes_attempted',
  738. 'outcomes_achieved',
  739. 'outcomes_attempted_colap',
  740. 'outcomes_achieved_colap',
  741. 'programs',
  742. 'users',
  743. 'program_courses',
  744. 'grouped_courses'
  745. ));
  746. }
  747. public function showQuasiOri($id)
  748. {
  749. ini_set('memory_limit', '256M');
  750. DB::connection()->disableQueryLog();
  751. $school = School::find($id);
  752. $title = $school->name;
  753. $schools = School::all();
  754. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  755. // $outcomeCount = Outcome::all()->count();
  756. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  757. // var_dump($semesters);
  758. // exit();
  759. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  760. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  761. /**
  762. * List of grouped courses (grouped sections)
  763. */
  764. $program_ids = $school->programs->lists('id');
  765. $undergrad_programs = DB::table('programs')
  766. ->select('id', 'name', 'school_id', 'is_graduate')
  767. ->where('is_graduate', '=', 0)
  768. ->where('school_id', '=', $id)
  769. ->orderBy('name', 'ASC')
  770. ->get();
  771. $grad_programs = DB::table('programs')
  772. ->select('id', 'name', 'school_id', 'is_graduate')
  773. ->where('is_graduate', '=', 1)
  774. ->where('school_id', '=', $id)
  775. ->orderBy('name', 'ASC')
  776. ->get();
  777. $grad_grouped_courses = Course::
  778. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  779. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  780. ->with('semester')
  781. ->with('program')
  782. ->whereIn('courses.program_id', $program_ids)
  783. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  784. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  785. ->where('programs.is_graduate', '=', 1)
  786. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  787. ->orderBy('courses.code')
  788. ->orderBy('courses.number')
  789. ->orderBy('courses.semester_id')
  790. ->get();
  791. $undergrad_grouped_courses = Course::
  792. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  793. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  794. ->with('semester')
  795. ->with('program')
  796. ->whereIn('courses.program_id', $program_ids)
  797. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  798. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  799. ->where('programs.is_graduate', '=', 0)
  800. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  801. ->orderBy('courses.code')
  802. ->orderBy('courses.number')
  803. ->orderBy('courses.semester_id')
  804. ->get();
  805. // Fetch programs with participation
  806. $participating_programs = $this->participatingPrograms($school);
  807. /**
  808. * Calculate how many sections are doing assessment
  809. */
  810. // $undergrad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  811. // $undergrad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  812. $undergrad_assessed_sections_count = 0;
  813. $undergrad_school_sections_count = 0;
  814. // $grad_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  815. // $grad_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  816. $grad_assessed_sections_count = 0;
  817. $grad_school_sections_count = 0;
  818. foreach ($school->programs as $program) {
  819. foreach ($program->courses as $course) {
  820. // Log::info("aqui".$course);
  821. if (!$course->program->is_graduate) {
  822. $undergrad_school_sections_count += 1;
  823. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  824. // Log::info("aqui".$course);
  825. } else {
  826. $grad_school_sections_count += 1;
  827. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  828. // Log::info("aqui".$course);
  829. }
  830. // if (!$course->program->is_graduate) {
  831. // if ($course->outcomes_achieved != NULL) {
  832. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  833. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  834. // for ($i = 1; $i <= count($undergrad_outcomes_attempted); $i++) {
  835. // $undergrad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  836. // $undergrad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  837. // }
  838. // $undergrad_assessed_sections_count += 1;
  839. // }
  840. // $undergrad_school_sections_count += 1;
  841. // } else {
  842. // if ($course->outcomes_achieved != NULL) {
  843. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  844. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  845. // for ($i = 1; $i <= count($grad_outcomes_attempted); $i++) {
  846. // $grad_outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  847. // $grad_outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  848. // }
  849. // $grad_assessed_sections_count += 1;
  850. // }
  851. // $grad_school_sections_count += 1;
  852. // }
  853. }
  854. }
  855. /**
  856. * Calculate how many programs achieved and attempted each outcome in this school
  857. */
  858. // Number of programs that achieved a particular learning outcome
  859. // $achievedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  860. // Number of programs that attempted a particular learning outcome
  861. // $attemptedUndergradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  862. // Fetch programs with participation for the school
  863. // $participating_undergrad_programs = DB::table('programs')
  864. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  865. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  866. // ->addSelect('courses.semester_id')
  867. // ->whereIn('semester_id', Session::get('semesters_ids'))
  868. // ->where('is_graduate', 0)
  869. // ->where('school_id', $school->id)
  870. // ->groupBy('id')
  871. // ->get();
  872. $output = array();
  873. // For each outcome
  874. foreach ($outcomes_undergrad as $outcome) {
  875. // $attempted_outcomes_per_undergrad_program[$outcome->id]=0;
  876. $achieved_outcomes_per_undergrad_program[$outcome->id] = 0;
  877. $attemptedUndergradProgramsPerOutcome[$outcome->id] = 0;
  878. $achievedUndergradProgramsPerOutcome[$outcome->id] = 0;
  879. $programs_attempted_in_school[$outcome->id] = $outcome->programs_attempted_in_school($semesters, $school->id);
  880. // var_dump($programs_attempted_in_school);exit();
  881. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  882. // var_dump($program_id->id);exit();
  883. $program = DB::table('programs')
  884. ->where('id', '=', $program_id->id)
  885. ->first();
  886. // $program=Program::where('id', $program_id->id);
  887. // var_dump($program);exit();
  888. if (!$program->is_graduate) {
  889. $attemptedUndergradProgramsPerOutcome[$outcome->id]++;
  890. }
  891. }
  892. $undergrad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 0);
  893. $undergrad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 0);
  894. // For each program with courses that do assessment
  895. $programs_with_courses = Program::with(array('courses' => function ($query) {
  896. // $query->whereNotNull('outcomes_attempted');
  897. $query->whereIn('semester_id', Session::get('semesters_ids'));
  898. }))->where('is_graduate', 0)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  899. foreach ($programs_with_courses as $program) {
  900. if (in_array($program->id, $participating_programs)) {
  901. // To acummulate all criteria for one program
  902. // $achieved_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  903. // $attempted_outcomes_per_undergrad_program = array_fill(1, $outcomeCount, 0);
  904. //Flag for counting programs
  905. $flag = false;
  906. // For each course in the program
  907. // foreach ($program->courses as $course) {
  908. // if($course->isAssessed()){
  909. // // If the outcome in question is being evaluated
  910. // $course_outcomes_attempted2 = $course->outcomes_att();
  911. // // $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  912. // // $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  913. // $course_outcomes_achieved2 = $course->outcomes_ach();
  914. // if (
  915. // array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  916. // && $course_outcomes_attempted2[$outcome->id] > 0
  917. // ) {
  918. // $achieved_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  919. // // $attempted_outcomes_per_undergrad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  920. //
  921. // // Add one to the programs assessing, if it wasn't added before
  922. // if (!$flag) {
  923. // $attemptedUndergradProgramsPerOutcome[$outcome->id] += 1;
  924. // $flag = true;
  925. // }
  926. // }
  927. //
  928. // // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_undergrad_program);
  929. // // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  930. // }
  931. // }
  932. //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
  933. // 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) {
  934. // $achievedUndergradProgramsPerOutcome[$outcome->id] += 1;
  935. // // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  936. // }
  937. }
  938. }
  939. }
  940. /**
  941. * Calculate how many programs achieved and attempted each outcome in this school
  942. */
  943. // Number of programs that achieved a particular learning outcome
  944. // $achievedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  945. // Number of programs that attempted a particular learning outcome
  946. // $attemptedGradProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  947. //
  948. // Fetch programs with participation for the school
  949. // $participating_grad_programs = DB::table('programs')
  950. // ->join('courses', 'courses.program_id', '=', 'programs.id')
  951. // ->select('programs.id', 'programs.name', 'programs.is_graduate', 'programs.school_id')
  952. // ->addSelect('courses.semester_id')
  953. // ->whereIn('semester_id', Session::get('semesters_ids'))
  954. // ->where('is_graduate', 1)
  955. // ->where('school_id', $school->id)
  956. // ->groupBy('id')
  957. // ->get();
  958. $output = array();
  959. // For each outcome
  960. foreach ($outcomes_grad as $outcome) {
  961. // $attempted_outcomes_per_grad_program[$outcome->id]=0;
  962. $achieved_outcomes_per_grad_program[$outcome->id] = 0;
  963. $attemptedGradProgramsPerOutcome[$outcome->id] = 0;
  964. $achievedGradProgramsPerOutcome[$outcome->id] = 0;
  965. $grad_outcomes_attempted[$outcome->id] = $outcome->attempted_by_school($semesters, $school->id, 1);
  966. $grad_outcomes_achieved[$outcome->id] = $outcome->achieved_by_school($semesters, $school->id, 1);
  967. // For each program with courses that do assessment
  968. foreach ($programs_attempted_in_school[$outcome->id] as $program_id) {
  969. // var_dump($program_id->id);exit();
  970. $program = DB::table('programs')
  971. ->where('id', '=', $program_id->id)
  972. ->first();
  973. // $program=Program::where('id', $program_id->id);
  974. // var_dump($program);exit();
  975. if ($program->is_graduate) {
  976. $attemptedGradProgramsPerOutcome[$outcome->id]++;
  977. }
  978. }
  979. $programs_with_courses = Program::with(array('courses' => function ($query) {
  980. // $query->whereNotNull('outcomes_attempted');
  981. $query->whereIn('semester_id', Session::get('semesters_ids'));
  982. }))->where('is_graduate', 1)->where('school_id', $school->id)->orderBy('name', 'asc')->get();
  983. foreach ($programs_with_courses as $program) {
  984. if (in_array($program->id, $participating_programs)) {
  985. // To acummulate all criteria for one program
  986. // $achieved_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  987. // $attempted_outcomes_per_grad_program = array_fill(1, $outcomeCount, 0);
  988. //Flag for counting programs
  989. $flag = false;
  990. // For each course in the program
  991. foreach ($program->courses as $course) {
  992. if ($course->isAssessed()) {
  993. // If the outcome in question is being evaluated
  994. // $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  995. $course_outcomes_attempted2 = ($course->outcomes_att());
  996. $course_outcomes_achieved2 = ($course->outcomes_ach());
  997. // $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  998. if (
  999. array_key_exists($outcome->id, $course_outcomes_attempted2) && array_key_exists($outcome->id, $course_outcomes_achieved2)
  1000. && $course_outcomes_attempted2[$outcome->id] > 0
  1001. ) {
  1002. $achieved_outcomes_per_grad_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  1003. $attempted_outcomes_per_grad_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  1004. // Add one to the programs assessing, if it wasn't added before
  1005. if (!$flag) {
  1006. $attemptedGradProgramsPerOutcome[$outcome->id] += 1;
  1007. $flag = true;
  1008. }
  1009. }
  1010. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_grad_program);
  1011. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  1012. }
  1013. }
  1014. //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
  1015. 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) {
  1016. $achievedGradProgramsPerOutcome[$outcome->id] += 1;
  1017. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  1018. }
  1019. }
  1020. }
  1021. }
  1022. if ($school->id == 13) {
  1023. // 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'));
  1024. 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'));
  1025. } else {
  1026. // 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'));
  1027. 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'));
  1028. }
  1029. }
  1030. public function print_school($id)
  1031. {
  1032. ini_set('memory_limit', '256M');
  1033. DB::connection()->disableQueryLog();
  1034. $school = School::find($id);
  1035. $title = $school->name . ' Assessment Report - ' . date('m/d/Y');
  1036. $outcomes = Outcome::orderBy('name', 'asc')->get();
  1037. $outcomeCount = Outcome::all()->count();
  1038. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  1039. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  1040. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  1041. $undergrad_stu_outcome_attempted = [];
  1042. $grad_stu_outcome_attempted = [];
  1043. $undergrad_stu_outcome_achieved = [];
  1044. $grad_stu_outcome_achieved = [];
  1045. $attemptedUndergradProgramsPerOutcome = [];
  1046. $achievedUndergradProgramsPerOutcome = [];
  1047. $attemptedGradProgramsPerOutcome = [];
  1048. $achievedGradProgramsPerOutcome = [];
  1049. foreach ($outcomes_undergrad as $outcome) {
  1050. $undergrad_stu_outcome_attempted[$outcome->id] = 0;
  1051. $undergrad_stu_outcome_achieved[$outcome->id] = 0;
  1052. $attemptedUndergradProgramsPerOutcome[$outcome->id] = [];
  1053. $achievedUndergradProgramsPerOutcome[$outcome->id] = [];
  1054. }
  1055. foreach ($outcomes_grad as $outcome) {
  1056. $grad_stu_outcome_attempted[$outcome->id] = 0;
  1057. $grad_stu_outcome_achieved[$outcome->id] = 0;
  1058. $attemptedGradProgramsPerOutcome[$outcome->id] = [];
  1059. $achievedGradProgramsPerOutcome[$outcome->id] = [];
  1060. }
  1061. /**
  1062. * List of courses (grouped sections)
  1063. */
  1064. $program_ids = $school->programs->lists('id');
  1065. $undergrad_programs = DB::table('programs')
  1066. ->select('id', 'name', 'school_id', 'is_graduate')
  1067. ->where('is_graduate', '=', 0)
  1068. ->where('school_id', '=', $id)
  1069. ->orderBy('name', 'ASC')
  1070. ->get();
  1071. $grad_programs = DB::table('programs')
  1072. ->select('id', 'name', 'school_id', 'is_graduate')
  1073. ->where('is_graduate', '=', 1)
  1074. ->where('school_id', '=', $id)
  1075. ->orderBy('name', 'ASC')
  1076. ->get();
  1077. //quiero ver si monto el query tm aqui
  1078. $undergrad_programs_list = DB::table('programs')
  1079. ->select('id', 'name', 'school_id', 'is_graduate')
  1080. ->where('is_graduate', '=', 0)
  1081. ->where('school_id', '=', $id)
  1082. ->orderBy('name', 'ASC')
  1083. ->lists('id');
  1084. $grad_programs_list = DB::table('programs')
  1085. ->select('id', 'name', 'school_id', 'is_graduate')
  1086. ->where('is_graduate', '=', 1)
  1087. ->where('school_id', '=', $id)
  1088. ->orderBy('name', 'ASC')
  1089. ->lists('id');
  1090. /*
  1091. $undergraduate_student_query = DB::table("courses")
  1092. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1093. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  1094. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  1095. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  1096. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  1097. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  1098. ->join('program_criterion_objective_outcome as poco', function ($q) {
  1099. $q->on('courses.program_id', '=', 'poco.program_id')
  1100. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  1101. })
  1102. ->join('students', 'students.id', '=', 'assessments.student_id')
  1103. ->whereIn('poco.program_id', $undergrad_programs_list)
  1104. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  1105. ->whereIn('courses.program_id', $undergrad_programs_list)
  1106. ->select('students.number as student_id')
  1107. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  1108. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  1109. ->addSelect('outcome_id')
  1110. ->groupBy(array('students.id', 'outcome_id'))
  1111. ->get();
  1112. //Log::info($undergraduate_student_query);
  1113. $grad_student_query = DB::table("courses")
  1114. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1115. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  1116. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  1117. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  1118. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  1119. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  1120. ->join('program_criterion_objective_outcome as poco', function ($q) {
  1121. $q->on('courses.program_id', '=', 'poco.program_id')
  1122. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  1123. })
  1124. ->join('students', 'students.id', '=', 'assessments.student_id')
  1125. ->whereIn('poco.program_id', $grad_programs_list)
  1126. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  1127. ->whereIn('courses.program_id', $grad_programs_list)
  1128. ->select('students.number as student_id')
  1129. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  1130. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  1131. ->addSelect('outcome_id')
  1132. ->groupBy(array('students.id', 'outcome_id'))
  1133. ->get();
  1134. */
  1135. //school
  1136. /*
  1137. student x, crit achieved, crit attempted, outcome 1
  1138. student x, crit achieved, crit attempted, outcome 2
  1139. student x, crit achieved, crit attempted, outcome 3
  1140. student x, crit achieved, crit attempted, outcome 4
  1141. student y, crit achieved, crit attempted, outcome 1
  1142. student y, crit achieved, crit attempted, outcome 2
  1143. student y, crit achieved, crit attempted, outcome 3
  1144. ....
  1145. */
  1146. $grad_outcomes_attempted = [];
  1147. $grad_outcomes_achieved = [];
  1148. $undergrad_outcomes_attempted = [];
  1149. $undergrad_outcomes_achieved = [];
  1150. $school_info = $school->school_courses_per_outcome;
  1151. $grad_outcomes_attempted = $school_info['graduate_info']['outcomes_attempted_combined'];
  1152. $grad_outcomes_achieved = $school_info['graduate_info']['outcomes_achieved_combined'];
  1153. $undergrad_outcomes_attempted = $school_info['undergraduate_info']['outcomes_attempted_combined'];
  1154. $undergrad_outcomes_achieved = $school_info['undergraduate_info']['outcomes_achieved_combined'];
  1155. $grad_grouped_courses = Course::
  1156. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  1157. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  1158. ->with('semester')
  1159. ->with('program')
  1160. ->whereIn('courses.program_id', $program_ids)
  1161. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  1162. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  1163. ->where('programs.is_graduate', '=', 1)
  1164. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  1165. ->orderBy('courses.code')
  1166. ->orderBy('courses.number')
  1167. ->orderBy('courses.semester_id')
  1168. ->get();
  1169. $undergrad_grouped_courses = Course::
  1170. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  1171. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  1172. ->with('semester')
  1173. ->with('program')
  1174. ->whereIn('courses.program_id', $program_ids)
  1175. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  1176. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  1177. ->where('programs.is_graduate', '=', 0)
  1178. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  1179. ->orderBy('courses.code')
  1180. ->orderBy('courses.number')
  1181. ->orderBy('courses.semester_id')
  1182. ->get();
  1183. foreach ($undergrad_grouped_courses as $key => $courses) {
  1184. $undergrad_grouped_courses[$key]->outcomes_attempted = NULL;
  1185. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  1186. foreach ($coursesT as $course) {
  1187. if ($course->isAssessed()) {
  1188. $undergrad_grouped_courses[$key]->outcomes_attempted = true;
  1189. }
  1190. }
  1191. }
  1192. foreach ($grad_grouped_courses as $key => $courses) {
  1193. $grad_grouped_courses[$key]->outcomes_attempted = NULL;
  1194. $coursesT = Course::where('courses.code', $courses->code)->where('courses.number', $courses->number)->where('courses.semester_id', $courses->semester_id)->get();
  1195. foreach ($coursesT as $course) {
  1196. if ($course->isAssessed()) {
  1197. $grad_grouped_courses[$key]->outcomes_attempted = true;
  1198. }
  1199. }
  1200. }
  1201. // Fetch programs with participation
  1202. $participating_programs = $this->participatingPrograms($school);
  1203. /**
  1204. * Calculate how many sections are doing assessment
  1205. */
  1206. $undergrad_assessed_sections_count = 0;
  1207. $undergrad_school_sections_count = 0;
  1208. $grad_assessed_sections_count = 0;
  1209. $grad_school_sections_count = 0;
  1210. foreach ($school->programs as $program) {
  1211. foreach ($program->courses as $course) {
  1212. if (!$course->program->is_graduate) {
  1213. $undergrad_school_sections_count += 1;
  1214. if ($course->isAssessed()) $undergrad_assessed_sections_count += 1;
  1215. } else {
  1216. $grad_school_sections_count += 1;
  1217. if ($course->isAssessed()) $grad_assessed_sections_count += 1;
  1218. }
  1219. }
  1220. }
  1221. $attemptedUndergradProgramsPerOutcome = $school_info['undergraduate_info']['programs_attempted_combined'];
  1222. $achievedUndergradProgramsPerOutcome = $school_info['undergraduate_info']['programs_achieved_combined'];
  1223. $attemptedGradProgramsPerOutcome = $school_info['graduate_info']['programs_attempted_combined'];
  1224. $achievedGradProgramsPerOutcome = $school_info['graduate_info']['programs_achieved_combined'];
  1225. //como resuelvo programsAttempted y eso
  1226. /*
  1227. //El query es el mismo de students, lo unico que dividido con programas,
  1228. //asi que lo que esta haciendo es, prog 1, y coge los dominios y estudiantes que evaluason
  1229. $undergrad_prog_attempted = DB::table("courses")
  1230. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1231. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  1232. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  1233. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  1234. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  1235. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  1236. ->join('program_criterion_objective_outcome as poco', function ($q) {
  1237. $q->on('courses.program_id', '=', 'poco.program_id')
  1238. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  1239. })
  1240. ->join('students', 'students.id', '=', 'assessments.student_id')
  1241. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  1242. ->whereIn('poco.program_id', $undergrad_programs_list)
  1243. ->whereIn('courses.program_id', $undergrad_programs_list)
  1244. ->select('students.number as student_id')
  1245. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  1246. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  1247. ->addSelect('outcome_id')
  1248. ->addSelect("courses.program_id")
  1249. ->groupBy(array('students.id', 'outcome_id', 'program_id'))
  1250. ->get();
  1251. $grad_prog_attempted = DB::table("courses")
  1252. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1253. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  1254. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  1255. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  1256. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  1257. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'activity_criterion.criterion_id')
  1258. ->join('program_criterion_objective_outcome as poco', function ($q) {
  1259. $q->on('courses.program_id', '=', 'poco.program_id')
  1260. ->on('cobo.id', '=', 'poco.cri_obj_out_id');
  1261. })
  1262. ->join('students', 'students.id', '=', 'assessments.student_id')
  1263. ->whereIn("courses.semester_id", Session::get('semesters_ids'))
  1264. ->whereIn('poco.program_id', $grad_programs_list)
  1265. ->whereIn('courses.program_id', $grad_programs_list)
  1266. ->select('students.number as student_id')
  1267. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  1268. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  1269. ->addSelect('outcome_id')
  1270. ->addSelect("courses.program_id")
  1271. ->groupBy(array('students.id', 'outcome_id', 'program_id'))
  1272. ->get();
  1273. //este arreglo va a tener attempted[outcome->id][program->id]
  1274. //so la cardinalidad de attempted[outcome->id] dice cuantos programas intentaron, achieved[outcome->id], va
  1275. //a decir cuantos pasaron y attempted[outcome->id][program->id] la suma de estudiantes que intentaron
  1276. //
  1277. foreach ($undergrad_prog_attempted as $row) {
  1278. $program_id = $row->program_id;
  1279. $outcome_id = $row->outcome_id;
  1280. if (!isset($attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id]))
  1281. $attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  1282. $attemptedUndergradProgramsPerOutcome[$outcome_id][$program_id]++;
  1283. $criteria_attempted_by_stu = $row->criteria_attempted;
  1284. $criteria_achieved_by_stu = $row->criteria_achieved;
  1285. if ($criteria_attempted_by_stu != 0 && $criteria_achieved_by_stu / $criteria_attempted_by_stu * 100 >= 66.67) {
  1286. if (!isset($achievedUndergradProgramsPerOutcome[$outcome_id][$program_id]))
  1287. $achievedUndergradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  1288. $achievedUndergradProgramsPerOutcome[$outcome_id][$program_id]++;
  1289. }
  1290. }
  1291. foreach ($grad_prog_attempted as $row) {
  1292. $program_id = $row->program_id;
  1293. $outcome_id = $row->outcome_id;
  1294. if (!isset($attemptedGradProgramsPerOutcome[$outcome_id][$program_id]))
  1295. $attemptedGradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  1296. $attemptedGradProgramsPerOutcome[$outcome_id][$program_id]++;
  1297. $criteria_attempted_by_stu = $row->criteria_attempted;
  1298. $criteria_achieved_by_stu = $row->criteria_achieved;
  1299. if ($criteria_attempted_by_stu != 0 && $criteria_achieved_by_stu / $criteria_attempted_by_stu * 100 >= 66.67) {
  1300. if (!isset($achievedGradProgramsPerOutcome[$outcome_id][$program_id]))
  1301. $achievedGradProgramsPerOutcome[$outcome_id][$program_id] = 0;
  1302. $achievedGradProgramsPerOutcome[$outcome_id][$program_id]++;
  1303. }
  1304. }*/
  1305. //La linea negra de proposed.
  1306. //
  1307. $linea_undergrad = DB::table('target_outcomes_program')
  1308. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  1309. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  1310. ->whereIn('program_id', $undergrad_programs_list)
  1311. ->whereIn("semester_id", Session::get('semesters_ids'))
  1312. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  1313. ->addSelect(DB::raw("count(target_outcomes_program.semester_id) as count_semester_id"))
  1314. ->groupBy("expected_target")
  1315. ->orderBy("expected_target", "DESC")
  1316. ->first();
  1317. if (!isset($linea_undergrad)) {
  1318. $default_undergrad = 70;
  1319. } elseif ($linea_undergrad->count_semester_id > 1) {
  1320. $default_undergrad = null;
  1321. $linea_undergrad = DB::table('target_outcomes_program')
  1322. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  1323. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  1324. ->whereIn('program_id', $undergrad_programs_list)
  1325. ->where('expected_target', $linea_undergrad->expected_target)
  1326. ->whereIn("semester_id", Session::get('semesters_ids'))
  1327. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  1328. //->addSelect("count(semester_id) as count_semester_id")
  1329. //->groupBy("expected_target")
  1330. ->orderBy("semester_id", "DESC")
  1331. ->first();
  1332. }
  1333. $linea_grad = DB::table('target_outcomes_program')
  1334. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  1335. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  1336. ->whereIn('program_id', $grad_programs_list)
  1337. ->whereIn("semester_id", Session::get('semesters_ids'))
  1338. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  1339. ->addSelect(DB::raw("count(target_outcomes_program.semester_id) as count_semester_id"))
  1340. ->groupBy("expected_target")
  1341. ->orderBy("expected_target", "DESC")
  1342. ->first();
  1343. if (!isset($linea_grad)) {
  1344. $default_grad = 70;
  1345. } elseif ($linea_grad->count_semester_id > 1) {
  1346. $default_grad = null;
  1347. $linea_grad = DB::table('target_outcomes_program')
  1348. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  1349. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  1350. ->whereIn('program_id', $grad_programs_list)
  1351. ->where('expected_target', $linea_grad->expected_target)
  1352. ->whereIn("semester_id", Session::get('semesters_ids'))
  1353. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  1354. ->orderBy("semester_id", "DESC")
  1355. ->first();
  1356. }
  1357. $expected_target_for_undergradprograms = !isset($linea_undergrad) ? $default_undergrad : $linea_undergrad->expected_target;
  1358. $expected_target_for_gradprograms = !isset($linea_grad) ? $default_grad : $linea_grad->expected_target;
  1359. //Log::info($default_grad);
  1360. $undergrad_programs = $school->undergraduate_programs->get();
  1361. $grad_programs = $school->graduate_programs->get();
  1362. if ($school->id == 13) {
  1363. // 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'));
  1364. 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'));
  1365. } else {
  1366. // 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'));
  1367. 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'));
  1368. }
  1369. $grouped_courses = Course::
  1370. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  1371. select(DB::raw('name, code, number, semester_id, program_id'))
  1372. ->with('semester')
  1373. ->with('program')
  1374. ->whereIn('program_id', $program_ids)
  1375. ->whereIn('semester_id', Session::get('semesters_ids'))
  1376. ->groupBy(array('code', 'number', 'semester_id'))
  1377. ->orderBy('code')
  1378. ->orderBy('number')
  1379. ->orderBy('semester_id')
  1380. ->get();
  1381. // Fetch programs with participation
  1382. $participating_programs = $this->participatingPrograms($school);
  1383. /**
  1384. * Calculate how many sections are doing assessment
  1385. */
  1386. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  1387. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  1388. $assessed_sections_count = 0;
  1389. $school_sections_count = 0;
  1390. foreach ($school->programs as $program) {
  1391. foreach ($program->courses as $course) {
  1392. if ($course->outcomes_achieved != NULL) {
  1393. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  1394. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  1395. for ($i = 1; $i <= count($outcomes_attempted); $i++) {
  1396. $outcomes_achieved[$i] += $course_outcomes_achieved[$i];
  1397. $outcomes_attempted[$i] += $course_outcomes_attempted[$i];
  1398. }
  1399. $assessed_sections_count += 1;
  1400. }
  1401. $school_sections_count += 1;
  1402. }
  1403. }
  1404. /**
  1405. * Calculate how many programs achieved and attempted each outcome in this school
  1406. */
  1407. // Number of programs that achieved a particular learning outcome
  1408. $achievedProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  1409. // Number of programs that attempted a particular learning outcome
  1410. $attemptedProgramsPerOutcome = array_fill(1, $outcomeCount, 0);
  1411. $output = array();
  1412. // For each outcome
  1413. foreach ($outcomes as $outcome) {
  1414. // For each program with courses that do assessment
  1415. foreach (Program::with(array('courses' => function ($query) {
  1416. // $query->whereNotNull('outcomes_attempted');
  1417. $query->whereIn('semester_id', Session::get('semesters_ids'));
  1418. }))->where('school_id', $school->id)->orderBy('name', 'asc')->get() as $program) {
  1419. // To acummulate all criteria for one program
  1420. $achieved_outcomes_per_program = array_fill(1, $outcomeCount, 0);
  1421. $attempted_outcomes_per_program = array_fill(1, $outcomeCount, 0);
  1422. //Flag for counting programs
  1423. $flag = false;
  1424. // For each course in the program
  1425. foreach ($program->courses as $course) {
  1426. // If the outcome in question is being evaluated
  1427. $course_outcomes_attempted2 = json_decode($course->outcomes_attempted, true);
  1428. $course_outcomes_achieved2 = json_decode($course->outcomes_achieved, true);
  1429. if (
  1430. array_key_exists($outcome->id, $course_outcomes_attempted2)
  1431. && $course_outcomes_attempted2[$outcome->id] > 0
  1432. ) {
  1433. $achieved_outcomes_per_program[$outcome->id] += $course_outcomes_achieved2[$outcome->id];
  1434. $attempted_outcomes_per_program[$outcome->id] += $course_outcomes_attempted2[$outcome->id];
  1435. // Add one to the programs assessing, if it wasn't added before
  1436. if (!$flag) {
  1437. $attemptedProgramsPerOutcome[$outcome->id] += 1;
  1438. $flag = true;
  1439. }
  1440. }
  1441. // $output[] = 'ACHIEVED: '.$program->name.'-'.json_encode($achieved_outcomes_per_program);
  1442. // $output[] = 'ATTEMPTED: '.$program->name.'-'.json_encode($attempted_outcomes_per_program);
  1443. }
  1444. //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
  1445. 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) {
  1446. $achievedProgramsPerOutcome[$outcome->id] += 1;
  1447. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  1448. }
  1449. }
  1450. }
  1451. 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'));
  1452. }
  1453. }