Geen omschrijving

SchoolsController.php 89KB

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