Geen omschrijving

ProgramsController.php 42KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. <?php
  2. class ProgramsController extends \BaseController
  3. {
  4. /**
  5. * Shows a particular program
  6. */
  7. public function show($id)
  8. {
  9. $program = Program::find($id);
  10. //Log::info(debug_backtrace()[1]['function']);
  11. // Log::info($program);
  12. $title = $program->school->name . ': ' . $program->name;
  13. $program_courses = $program->courses;
  14. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  15. $schools = School::all();
  16. // $outcomeCount = Outcome::all()->count();
  17. $selected_semesters = Semester::find(Session::get('semesters_ids'));
  18. $level = $program->is_graduate;
  19. $min_start = "9000-01-01 00:00:00";
  20. $max_end = "1000-01-01 00:00:00";
  21. foreach ($selected_semesters as $semester) {
  22. if ($min_start > $semester->start) {
  23. $min_start = $semester->start;
  24. }
  25. if ($max_end < $semester->end) {
  26. $max_end = $semester->end;
  27. }
  28. }
  29. $outcomes = Outcome::where(function ($query) use ($min_start) {
  30. $query->where('deactivation_date', '>=', $min_start)
  31. ->orWhere('deactivation_date', null);
  32. })
  33. ->where('activation_date', '<=', $max_end)
  34. ->where(function ($query2) use ($level) {
  35. $query2->where("level", $level + 1)
  36. ->orWhere("level", 3);
  37. })
  38. ->orderBy('name', 'ASC')
  39. ->get();
  40. $outcomeCount = Outcome::where(function ($query) use ($min_start) {
  41. $query->where('deactivation_date', '>=', $min_start)
  42. ->orWhere('deactivation_date', null);
  43. })
  44. ->where('activation_date', '<=', $max_end)
  45. ->where(function ($query2) use ($level) {
  46. $query2->where("level", $level + 1)
  47. ->orWhere("level", 3);
  48. })
  49. ->count();
  50. $outcomes_attempted = [];
  51. $outcomes_achieved = [];
  52. $program_info = $program->courses_students_score_per_outcome;
  53. $outcomes_attempted = $program_info['program_info']['outcomes_attempted_combined'];
  54. $outcomes_achieved = $program_info['program_info']['outcomes_achieved_combined'];
  55. /*
  56. foreach ($outcomes as $outcome) {
  57. $outcomes_attempted[$outcome->id] = 0;
  58. $outcomes_achieved[$outcome->id] = 0;
  59. }
  60. //foreach ($outcomes as $outcome) {
  61. // $outcomes_attempted[$outcome->id] = $program->attempted_outcome($outcome->id, $selected_semesters);
  62. // if ($outcomes_attempted[$outcome->id]) $outcomes_achieved[$outcome->id] = $program->achieved_outcome($outcome->id, $selected_semesters);
  63. //}
  64. foreach ($program->courses as $course) {
  65. $results = $course->student_report_for_outcome;
  66. //Log::info($results);
  67. foreach ($outcomes as $outcome) {
  68. $outcomes_attempted[$outcome->id] += isset($results[$outcome->id]) ? $results[$outcome->id]['calculations']['student_attempted'] : 0;
  69. $outcomes_achieved[$outcome->id] += isset($results[$outcome->id]) ? $results[$outcome->id]['calculations']['student_achieved'] : 0;
  70. }
  71. }
  72. */
  73. foreach ($outcomes as $outcome) {
  74. $assessed_courses[$outcome->id] = DB::table('activity_criterion')
  75. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  76. ->join('courses', 'activities.course_id', '=', 'courses.id')
  77. ->join('programs', 'programs.id', '=', 'courses.program_id')
  78. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  79. ->where('criterion_objective_outcome.outcome_id', '=', $outcome->id)
  80. ->where('programs.id', '=', $program->id)
  81. ->where('courses.semester_id', '=', $semester)
  82. ->count(DB::raw('DISTINCT courses.id'));
  83. }
  84. $assessed_courses_count = array_sum($assessed_courses);
  85. /**
  86. * List of grouped courses (grouped sections)
  87. */
  88. // $grouped_courses = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  89. $grouped_courses = Course::select(DB::raw('courses.name, code, number, semester_id, program_id, activities.id as activity_assessed'))
  90. ->leftJoin('activities', function ($query) {
  91. $query->on('activities.course_id', '=', 'courses.id');
  92. $query->on('activities.draft', '=', DB::raw('0'));
  93. $query->on('activities.diagnostic', '=', DB::raw('0'));
  94. })
  95. ->with('semester')
  96. ->with('program')
  97. ->where('program_id', $program->id)
  98. ->whereIn('semester_id', Session::get('semesters_ids'))
  99. ->groupBy(array('code', 'number', 'semester_id'))
  100. ->orderBy('code')
  101. ->orderBy('number')
  102. ->orderBy('semester_id')
  103. ->get();
  104. // Program contact information
  105. $users = User::select('users.*')
  106. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  107. ->where(function ($query) use ($program) {
  108. $query
  109. ->where('school_id', $program->school_id)
  110. ->where('role', 2);
  111. })
  112. ->orWhere(function ($query) use ($program) {
  113. $query
  114. ->where('role', 3)
  115. ->where('program_id', $program->id);
  116. })
  117. ->orWhere(function ($query) use ($program) {
  118. $query
  119. ->where('role', 4)
  120. ->where('program_id', $program->id);
  121. })
  122. ->get();
  123. // var_dump($outcomes_attempted);
  124. // print "<br>";
  125. // var_dump($outcomes_achieved);
  126. // print "<br>";
  127. return View::make('local.managers.shared.program', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses', 'program', 'users'));
  128. }
  129. // manage course index
  130. public function assignOtherProgramIndex()
  131. {
  132. $title = 'Assign courses to other Programs';
  133. $programs = Program::orderBy("name")->get();
  134. return View::make('local.managers.admins.assign_other_programs', compact('title', 'programs'));
  135. }
  136. //create other course pairing
  137. public function addToOtherProgramTYP()
  138. {
  139. $clean_input = Input::all();
  140. Log::info($clean_input);
  141. DB::beginTransaction();
  142. foreach ($clean_input['other_program'] as $index => $program_id) {
  143. $id = DB::table('other_programs_courses_typ')->insertGetId(array(
  144. 'program_id' => $clean_input['program'],
  145. 'other_program_id' => $program_id
  146. ));
  147. if (!isset($id)) {
  148. Session::flash('status', 'danger');
  149. Session::flash('message', 'Error saving Program. Try again later.');
  150. return Redirect::back();
  151. }
  152. }
  153. DB::commit();
  154. Session::flash('status', 'success');
  155. Session::flash('message', 'Pairing created.');
  156. return Redirect::action('ProgramsController@assignOtherProgramIndex');
  157. }
  158. public function updatePairingInfo()
  159. {
  160. $clean_input = Input::all();
  161. Log::info($clean_input);
  162. DB::beginTransaction();
  163. DB::table("other_programs_courses_typ")->where('program_id', $clean_input['program'])
  164. ->delete();
  165. foreach ($clean_input['other_program'] as $index => $program_id) {
  166. $id = DB::table('other_programs_courses_typ')->insertGetId(array(
  167. 'program_id' => $clean_input['program'],
  168. 'other_program_id' => $program_id
  169. ));
  170. if (!isset($id)) {
  171. Session::flash('status', 'danger');
  172. Session::flash('message', 'Error saving Program. Try again later.');
  173. return Redirect::back();
  174. }
  175. }
  176. DB::commit();
  177. Session::flash('status', 'success');
  178. Session::flash('message', 'Pairing created.');
  179. return Redirect::action('ProgramsController@assignOtherProgramIndex');
  180. }
  181. public function fetchPairingInfo()
  182. {
  183. return DB::table("other_programs_courses_typ")->where('program_id', Input::get('program_id'))
  184. ->lists("other_program_id");
  185. }
  186. public function showReport()
  187. {
  188. // create an array with the ID of Semesters selected in the form
  189. $selected_semesters_id = array();
  190. $semesters = Semester::all();
  191. foreach ($semesters as $semester) {
  192. if ($semester->is_visible) {
  193. if (Input::get('semester' . $semester->id) != null) {
  194. array_push($selected_semesters_id, $semester->id);
  195. }
  196. }
  197. }
  198. $selected_semesters = DB::table('semesters')
  199. ->wherein('semesters.id', $selected_semesters_id)
  200. ->get();
  201. // create a srting with the selected metodos de divulgfacion
  202. $selected_divulgaciones = '';
  203. $divulgaciones = array(
  204. 'profesores', 'comiteDepartamental', 'comiteFacultadEscuela',
  205. 'pleno', 'estudiantes', 'administrativos', 'senado', 'comunidadWeb',
  206. 'otros'
  207. );
  208. foreach ($divulgaciones as $divulgacion) {
  209. if (Input::get($divulgacion) != null) {
  210. $selected_divulgaciones = $selected_divulgaciones . '\n' . Input::get($divulgacion);
  211. }
  212. }
  213. //OUTCOMES Join criteria join program
  214. $programs = DB::table('programs')
  215. ->select('id', 'name')
  216. ->orderBy('name', 'asc')
  217. ->get();
  218. // $program
  219. $tables_names = '{';
  220. foreach ($programs as $program) {
  221. $tables_names = $tables_names . '"table' . $program->id . '" : "' . $program->name . '",'; // code...
  222. }
  223. $tables_names = $tables_names . '}';
  224. $title = "Programs Reports";
  225. // $title = "Program Report: ".$program->name;
  226. $programs_info = array();
  227. //OUTCOMES Join criteria join program
  228. foreach ($programs as $program) {
  229. $info_by_id = Program::find($program->id);
  230. $domains = DB::table('outcomes')
  231. ->join('criterion_objective_outcome as cobo', 'cobo.outcome_id', '=', 'outcomes.id')
  232. ->join('criteria', 'criteria.id', '=', 'cobo.criterion_id')
  233. ->join('program_criterion_objective_outcome', 'cobo.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
  234. ->join('courses', 'courses.program_id', '=', 'program_criterion_objective_outcome.program_id')
  235. ->where('program_criterion_objective_outcome.program_id', $program->id)
  236. ->select('outcomes.name', 'outcomes.activation_date')
  237. ->distinct()
  238. ->orderBy('outcomes.name', 'asc')
  239. ->get();
  240. /*
  241. $domains = DB::table('outcomes')
  242. ->join('criteria', 'criteria.outcome_id', '=', 'outcomes.id')
  243. ->join('programs', 'programs.id', '=', 'criteria.program_id')
  244. ->join('courses', 'courses.program_id', '=', 'programs.id')
  245. ->where('programs.id', $program->id)
  246. ->select('outcomes.name', 'outcomes.activation_date')
  247. ->distinct()
  248. ->orderBy('outcomes.name', 'asc')
  249. ->get();
  250. */
  251. $courses_used = DB::table('outcomes')
  252. ->join('criterion_objective_outcome as cobo', 'cobo.outcome_id', '=', 'outcomes.id')
  253. ->join('criteria', 'criteria.id', '=', 'cobo.criterion_id')
  254. ->join('program_criterion_objective_outcome', 'cobo.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
  255. ->join('courses', 'courses.program_id', '=', 'program_criterion_objective_outcome.program_id')
  256. ->where('program_criterion_objective_outcome.program_id', $program->id)
  257. ->select('courses.number', 'outcomes.name as domain_name', 'courses.code')
  258. ->distinct()
  259. ->orderBy('courses.name', 'asc')
  260. ->get();
  261. /*
  262. $courses_used = DB::table('outcomes')
  263. ->join('criteria', 'criteria.outcome_id', '=', 'outcomes.id')
  264. ->join('programs', 'programs.id', '=', 'criteria.program_id')
  265. ->join('courses', 'courses.program_id', '=', 'programs.id')
  266. ->where('programs.id', $program->id)
  267. ->select('courses.number', 'outcomes.name as domain_name', 'courses.code')
  268. ->distinct()
  269. ->orderBy('courses.name', 'asc')
  270. ->get(); */
  271. $transformative_actions = DB::table('outcomes')
  272. ->join('criterion_objective_outcome as cobo', 'cobo.outcome_id', '=', 'outcomes.id')
  273. ->join('criteria', 'criteria.id', '=', 'cobo.criterion_id')
  274. ->join('program_criterion_objective_outcome', 'cobo.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
  275. ->join('courses', 'courses.program_id', '=', 'program_criterion_objective_outcome.program_id')
  276. ->join('activities', 'activities.course_id', '=', 'courses.id')
  277. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  278. ->join('transformative_activity_criterion as taa', 'taa.activity_criterion_id', '=', 'activity_criterion.id')
  279. ->join('transformative_actions', 'transformative_actions.id', '=', 'taa.trans_action_id')
  280. ->where('program_criterion_objective_outcome.program_id', $program->id)
  281. ->select('transformative_actions.description', 'outcomes.name as domain_name')
  282. ->distinct()
  283. ->orderBy('transformative_actions.description', 'asc')
  284. ->get();
  285. $info = array($info_by_id, $domains, $courses_used, $transformative_actions);
  286. array_push($programs_info, $info);
  287. }
  288. return View::make('local.managers.shared.program_report', compact('title', 'programs_info', 'selected_divulgaciones', 'selected_semesters', 'tables_names'));
  289. }
  290. private function cmp($a, $b)
  291. {
  292. return strcmp($a->name, $b->name);
  293. }
  294. public function studentsProgramAssessmentReportForProfessors($program_id)
  295. {
  296. return $this->studentProgramAssessmentReport($program_id);
  297. }
  298. public function studentProgramAssessmentReport($program_id)
  299. {
  300. $id = $program_id;
  301. ini_set('memory_limit', -1);
  302. ini_set('max_execution_time', 300);
  303. $program = Program::find($program_id);
  304. $title = $program->school->name . ': ' . $program->name;
  305. $outcomes = Outcome::orderBy('name', 'asc')->get();
  306. $schools = School::all();
  307. $outcomeCount = Outcome::all()->count();
  308. // var_dump(json_encode($outcomes));
  309. $role = Auth::user()->role;
  310. $programs_ids = array($program->id);
  311. $users = User::select('users.*')
  312. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  313. ->where(function ($query) use ($program) {
  314. $query
  315. ->where('school_id', $program->school_id)
  316. ->where('role', 2);
  317. })
  318. ->orWhere(function ($query) use ($program) {
  319. $query
  320. ->where('role', 3)
  321. ->where('program_id', $program->id);
  322. })
  323. ->orWhere(function ($query) use ($program) {
  324. $query
  325. ->where('role', 4)
  326. ->where('program_id', $program->id);
  327. })
  328. ->get();
  329. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  330. // $school = School::find($school_id);
  331. // $title= $school->name;
  332. // $outcomeCount = Outcome::all()->count();
  333. // $programs=Program::where('school_id','=',$school_id)->get();
  334. // $programs_ids=array();
  335. // // var_dump($programs);exit();
  336. // $programs_name=array();
  337. // foreach($programs as $program)
  338. // {
  339. // // var_dump($program);
  340. // $programs_ids[]=$program->id;
  341. // $programs_name[$program->id]=$program->name;
  342. // }
  343. $grouped_courses = Course::
  344. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  345. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id, 1 as grouped'))
  346. ->with('semester')
  347. ->with('program')
  348. ->whereIn('courses.program_id', $programs_ids)
  349. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  350. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  351. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  352. ->orderBy('courses.code')
  353. ->orderBy('courses.number')
  354. ->orderBy('courses.semester_id')
  355. ->get();
  356. $role = Auth::user()->role;
  357. $users = array();
  358. /*
  359. $resultados_todos_obj = DB::table('assessments')
  360. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  361. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  362. ->join('courses', 'courses.id', '=', 'activities.course_id')
  363. ->join('students', 'students.id', '=', 'assessments.student_id')
  364. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  365. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  366. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  367. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  368. ->whereIn('students.program_id', $programs_ids)
  369. ->whereIn('semester_id', Session::get('semesters_ids'))
  370. ->where('semesters.is_visible', '=', 1)
  371. ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  372. ->distinct()
  373. ->get();
  374. foreach ($resultados_todos_obj as $resultado) {
  375. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'])) {
  376. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'] = array();
  377. }
  378. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'][] = $resultado->code;
  379. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'] = array_unique($resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters']);
  380. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted'])) {
  381. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted'] = 0;
  382. }
  383. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted']++;
  384. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved'])) {
  385. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved'] = 0;
  386. }
  387. if ($resultado->score >= $resultado->expected_points) {
  388. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved']++;
  389. }
  390. }*//*
  391. $outcomes_colap = array();
  392. $programs = array();
  393. // $outcomes_colap=array();
  394. $i = 0;
  395. $outcomes_attempted = array();
  396. $outcomes_attempted_colap = array();
  397. $outcomes_achieved_colap = array();
  398. $outcomes_attempted_semesters = array();
  399. foreach ($resultados_todos as $program_id => $resultados_prog) {
  400. $outcomes_attempted_semesters[$program_id] = array();
  401. foreach ($resultados_prog as $out => $datos_out) {
  402. $outcomes_achieved[$program_id][$out] = 0;
  403. $outcomes_attempted[$program_id][$out] = 0;
  404. // var_dump($datos_out);outcomes_attempted_semesters
  405. $outcomes_attempted_semesters[$program_id][$out] = $datos_out['semesters'];
  406. unset($datos_out['semesters']);
  407. // var_dump($outcomes_attempted_semesters[$program_id][$out]);
  408. // var_dump($datos_out);
  409. // exit();
  410. foreach ($datos_out as $res) {
  411. $outcomes_attempted[$program_id][$out]++;
  412. if (3 * $res['achieved'] >= 2 * $res['attempted'])
  413. $outcomes_achieved[$program_id][$out]++;
  414. }
  415. }
  416. $programs[] = Program::find($program_id);
  417. if (Program::find($program_id)->is_graduate) {
  418. $colapso = array(1 => array(), 3 => array(), 2 => array(11), 12 => array(7, 14), 10 => array(), 4 => array(6, 15));
  419. } else {
  420. $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());
  421. }
  422. $resultados_todos_colap[$program_id] = array();
  423. foreach ($colapso as $out => $pares) {
  424. $resultados_todos_colap[$program_id][$out]["semesters"] = array();
  425. if (isset($resultados_todos[$program_id][$out]))
  426. $resultados_todos_colap[$program_id][$out] = $resultados_todos[$program_id][$out];
  427. else $resultados_todos_colap[$program_id][$out] = array();
  428. foreach ($pares as $par) {
  429. if (isset($resultados_todos[$program_id][$par])) {
  430. // unset($resultados_todos[$program_id][$par]['semesters']);
  431. foreach ($resultados_todos[$program_id][$par] as $estu => $resus) {
  432. if ($estu != "semesters") {
  433. if (!isset($resultados_todos_colap[$program_id][$out][$estu])) {
  434. $resultados_todos_colap[$program_id][$out][$estu]['attempted'] = 0;
  435. $resultados_todos_colap[$program_id][$out][$estu]['achieved'] = 0;
  436. }
  437. // print $program_id." ".$par." ".$estu."<br>";
  438. // var_dump($resultados_todos[$program_id][$par][$estu]);
  439. $resultados_todos_colap[$program_id][$out][$estu]['attempted'] += $resultados_todos[$program_id][$par][$estu]['attempted'];
  440. $resultados_todos_colap[$program_id][$out][$estu]['achieved'] += $resultados_todos[$program_id][$par][$estu]['achieved'];
  441. } else if (isset($resultados_todos[$program_id][$par]["semesters"])) {
  442. if (isset($resultados_todos_colap[$program_id][$out]["semesters"])) {
  443. $tmp = array_merge($resultados_todos_colap[$program_id][$out]["semesters"], $resultados_todos[$program_id][$par]["semesters"]);
  444. // var_dump(($tmp));
  445. // var_dump(array_unique($tmp));
  446. // exit();
  447. $resultados_todos_colap[$program_id][$out]["semesters"] = array_unique($tmp);
  448. } else
  449. $resultados_todos_colap[$program_id][$out]["semesters"] = array_unique($resultados_todos[$program_id][$par]["semesters"]);
  450. }
  451. }
  452. }
  453. }
  454. }
  455. // var_dump($resultados_todos_colap);
  456. $outcomes_attempted_colap[$program_id] = array();
  457. $outcomes_achieved_colap[$program_id] = array();
  458. $outcomes_attempted_colap_semesters[$program_id] = array();
  459. // print $program_id."<br>";
  460. // var_dump($resultados_todos_colap[$program_id]);
  461. // print "<br>";
  462. foreach ($resultados_todos_colap[$program_id] as $out => $datos_out) {
  463. if (!$i) $outcomes_colap[] = Outcome::find($out);
  464. // $outcomes_attempted_colap_semesters[$program_id][$out]=array();
  465. if (isset($datos_out['semesters'])) {
  466. $outcomes_attempted_colap_semesters[$program_id][$out] = $datos_out['semesters'];
  467. unset($datos_out['semesters']);
  468. }
  469. foreach ($datos_out as $res) {
  470. if (!isset($outcomes_attempted_colap[$program_id][$out])) {
  471. $outcomes_attempted_colap[$program_id][$out] = 0;
  472. $outcomes_achieved_colap[$program_id][$out] = 0;
  473. }
  474. $outcomes_attempted_colap[$program_id][$out]++;
  475. if (3 * $res['achieved'] >= 2 * $res['attempted'])
  476. $outcomes_achieved_colap[$program_id][$out]++;
  477. }
  478. if (empty($datos_out)) {
  479. $outcomes_attempted_colap[$program_id][$out] = 0;
  480. $outcomes_achieved_colap[$program_id][$out] = 0;
  481. }
  482. }
  483. $i++;
  484. }/*
  485. usort($outcomes_colap, array($this, "cmp"));
  486. // var_dump($outcomes_attempted_colap); print "<br>";
  487. // var_dump($outcomes_achieved_colap); print "<br>";
  488. // exit();
  489. $outcomes_attempted_colap_todo = array();
  490. $outcomes_achieved_colap_todo = array();
  491. foreach ($outcomes_attempted_colap as $program_id => $out_res) {
  492. foreach ($out_res as $out => $res) {
  493. if (!isset($outcomes_attempted_colap_todo[$out])) {
  494. $outcomes_attempted_colap_todo[$out] = 0;
  495. $outcomes_achieved_colap_todo[$out] = 0;
  496. }
  497. $outcomes_attempted_colap_todo[$out] += $outcomes_attempted_colap[$program_id][$out];
  498. $outcomes_achieved_colap_todo[$out] += $outcomes_achieved_colap[$program_id][$out];
  499. }
  500. }
  501. /*
  502. $outcomes_attempted_todo = array();
  503. $outcomes_achieved_todo = array();
  504. foreach ($outcomes_attempted as $program_id => $out_res) {
  505. foreach ($out_res as $out => $res) {
  506. if (!isset($outcomes_attempted_todo[$out])) {
  507. $outcomes_attempted_todo[$out] = 0;
  508. $outcomes_achieved_todo[$out] = 0;
  509. }
  510. $outcomes_attempted_todo[$out] += $outcomes_attempted[$program_id][$out];
  511. $outcomes_achieved_todo[$out] += $outcomes_achieved[$program_id][$out];
  512. }
  513. }*/
  514. $program_info = $program->program_students_per_outcome['program_info'];
  515. $outcomes_attempted_colap = $program_info['outcomes_attempted_combined']; // $outcomes_attempted_colap_todo;
  516. $outcomes_achieved_colap = $program_info['outcomes_achieved_combined']; //$outcomes_achieved_colap_todo;
  517. $outcomes_attempted = $program_info['outcomes_attempted_uncombined'];
  518. //$outcomes_attempted_todo;
  519. $outcomes_achieved = $program_info['outcomes_achieved_uncombined'];
  520. $outcomes_colap = Outcome::whereNull('new_outcome_id')->get();
  521. //$outcomes_achieved_todo;
  522. // var_dump($outcomes_attempted_colap);
  523. // var_dump($outcomes_attempted_colap);
  524. // 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'));
  525. return View::make('local.managers.shared.program_student_result', compact('title', 'role', 'outcomes', 'outcomes_colap', 'outcomes_attempted', 'outcomes_achieved', 'outcomes_attempted_colap', 'outcomes_achieved_colap', 'program', 'users', 'program_courses', 'grouped_courses'));
  526. }
  527. // public function show($id)
  528. // {
  529. //
  530. // $program = Program::find($id);
  531. // $title= $program->school->name.': '.$program->name;
  532. // $program_courses = $program->courses;
  533. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  534. // $schools = School::all();
  535. // $outcomeCount = Outcome::all()->count();
  536. //
  537. //
  538. // $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  539. // $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  540. //
  541. // $assessed_courses_count=0;
  542. // foreach ($program_courses as $course)
  543. // {
  544. // if($course->outcomes_achieved!=NULL)
  545. // {
  546. // $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  547. // $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  548. // for($i=1; $i<=count($outcomes_attempted); $i++)
  549. // {
  550. // $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  551. // $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  552. // }
  553. // $assessed_courses_count+=1;
  554. // }
  555. // }
  556. //
  557. // /**
  558. // * List of grouped courses (grouped sections)
  559. // */
  560. //
  561. // $grouped_courses = Course::
  562. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  563. // ->with('semester')
  564. // ->with('program')
  565. // ->where('program_id', $program->id)
  566. // ->whereIn('semester_id', Session::get('semesters_ids'))
  567. // ->groupBy(array('code', 'number', 'semester_id'))
  568. // ->orderBy('code')
  569. // ->orderBy('number')
  570. // ->orderBy('semester_id')
  571. // ->get();
  572. //
  573. // // Program contact information
  574. // $users = User::
  575. // select('users.*')
  576. // ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  577. // ->where(function($query) use($program)
  578. // {
  579. // $query
  580. // ->where('school_id', $program->school_id)
  581. // ->where('role', 2);
  582. // })
  583. // ->orWhere(function($query) use($program)
  584. // {
  585. // $query
  586. // ->where('role', 3)
  587. // ->where('program_id', $program->id);
  588. // })
  589. // ->orWhere(function($query) use($program)
  590. // {
  591. // $query
  592. // ->where('role', 4)
  593. // ->where('program_id', $program->id);
  594. // })
  595. // ->get();
  596. //
  597. // return View::make('local.managers.shared.program', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses', 'program', 'users'));
  598. //
  599. // }
  600. public function print_program_students($program_id)
  601. {
  602. $id = $program_id;
  603. ini_set('memory_limit', -1);
  604. ini_set('max_execution_time', 300);
  605. $program = Program::find($program_id);
  606. $title = $program->school->name . ': ' . $program->name;
  607. $outcomes = Outcome::orderBy('name', 'asc')->get();
  608. $schools = School::all();
  609. $outcomeCount = Outcome::all()->count();
  610. // var_dump(json_encode($outcomes));
  611. $role = Auth::user()->role;
  612. $programs_ids = array($program->id);
  613. $users = User::select('users.*')
  614. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  615. ->where(function ($query) use ($program) {
  616. $query
  617. ->where('school_id', $program->school_id)
  618. ->where('role', 2);
  619. })
  620. ->orWhere(function ($query) use ($program) {
  621. $query
  622. ->where('role', 3)
  623. ->where('program_id', $program->id);
  624. })
  625. ->orWhere(function ($query) use ($program) {
  626. $query
  627. ->where('role', 4)
  628. ->where('program_id', $program->id);
  629. })
  630. ->get();
  631. $grouped_courses = Course::
  632. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  633. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id, 1 as grouped'))
  634. ->with('semester')
  635. ->with('program')
  636. ->whereIn('courses.program_id', $programs_ids)
  637. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  638. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  639. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  640. ->orderBy('courses.code')
  641. ->orderBy('courses.number')
  642. ->orderBy('courses.semester_id')
  643. ->get();
  644. $role = Auth::user()->role;
  645. $users = array();
  646. $program_info = $program->program_students_per_outcome['program_info'];
  647. $outcomes_attempted_colap = $program_info['outcomes_attempted_combined']; // $outcomes_attempted_colap_todo;
  648. $outcomes_achieved_colap = $program_info['outcomes_achieved_combined']; //$outcomes_achieved_colap_todo;
  649. $outcomes_attempted = $program_info['outcomes_attempted_uncombined'];
  650. //$outcomes_attempted_todo;
  651. $outcomes_achieved = $program_info['outcomes_achieved_uncombined'];
  652. $outcomes_colap = Outcome::whereNull('new_outcome_id')->get();
  653. //$outcomes_achieved_todo;
  654. // var_dump($outcomes_attempted_colap);
  655. // var_dump($outcomes_attempted_colap);
  656. // 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'));
  657. return View::make('local.managers.shared.print_program_students', compact('title', 'role', 'outcomes', 'outcomes_colap', 'outcomes_attempted', 'outcomes_achieved', 'outcomes_attempted_colap', 'outcomes_achieved_colap', 'program', 'users', 'program_courses', 'grouped_courses'));
  658. }
  659. /**
  660. * Info to print a program
  661. */
  662. public function print_program($id)
  663. {
  664. $program = Program::find($id);
  665. $title = $program->name . ' Assessment Report - ' . date('m/d/Y');
  666. $schools = School::all();
  667. // $outcomeCount = Outcome::all()->count();
  668. $semesters = Session::get('semesters_ids');
  669. // $semesters = DB::table('semesters')->where('id', $course->semester_id)->orderBy('start', 'ASC')->first();
  670. $semesters2 = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  671. $program_courses = $program->courses;
  672. //$outcomes = Outcome::orderBy('name', 'asc')->get();
  673. $outcomes = Outcome::active_by_semesters($semesters2, $program->is_graduate);
  674. $outcomeCount = count($outcomes);
  675. $outcomes_achieved = [];
  676. $outcomes_attempted = [];
  677. $program_outcomes_attempted = [];
  678. $program_outcomes_achieved = [];
  679. // Log::info($program_courses);
  680. foreach ($outcomes as $outcome) {
  681. $outcomes_attempted[$outcome->id] = 0;
  682. $outcomes_achieved[$outcome->id] = 0;
  683. $program_outcomes_attempted[$outcome->id] = 0;
  684. $program_outcomes_achieved[$outcome->id] = 0;
  685. }
  686. $assessed_courses_count = 0;
  687. //Log::info("Aqui");
  688. //Log::info($program->program_students_per_outcomes);
  689. //$program_info = $program->program_students_per_outcome['program_info'];
  690. //$program_outcomes_attempted = $program_info['outcomes_attempted_combined'];
  691. //$program_outcomes_achieved = $program_info['outcomes_achieved_combined'];
  692. $course_info = $program->courses_students_score_per_outcome['program_info'];
  693. $outcomes_attempted = $course_info['outcomes_attempted_combined'];
  694. $outcomes_achieved = $course_info['outcomes_achieved_combined'];
  695. $assessed_courses_count = $program->courses_with_assessment_count->courses_assessed;
  696. /*
  697. foreach ($program_courses as $course) {
  698. $student_report = $course->student_report_for_outcome;
  699. if ($student_report) {
  700. foreach ($student_report as $outcome_id => $score) {
  701. if (array_key_exists($outcome_id, $outcomes_attempted)) $outcomes_attempted[$outcome_id] += $student_report[$outcome_id]['calculations']['student_attempted'];
  702. else $outcomes_attempted[$outcome_id] = $student_report[$outcome_id]['calculations']['student_attempted'];
  703. if (array_key_exists($outcome_id, $outcomes_achieved)) $outcomes_achieved[$outcome_id] += $student_report[$outcome_id]['calculations']['student_achieved'];
  704. else $outcomes_achieved[$outcome_id] = $student_report[$outcome_id]['calculations']['student_achieved'];
  705. }
  706. }
  707. /*
  708. $course->with_program_report = 1;
  709. $student_report = $course->student_report_for_outcome;
  710. if ($student_report) {
  711. foreach ($student_report as $outcome_id => $score) {
  712. if (array_key_exists($outcome_id, $program_outcomes_attempted)) $program_outcomes_attempted[$outcome_id] += $student_report[$outcome_id]['calculations']['student_attempted'];
  713. else $program_outcomes_attempted[$outcome_id] = $student_report[$outcome_id]['calculations']['student_attempted'];
  714. if (array_key_exists($outcome_id, $program_outcomes_achieved)) $program_outcomes_achieved[$outcome_id] += $student_report[$outcome_id]['calculations']['student_achieved'];
  715. else $program_outcomes_achieved[$outcome_id] = $student_report[$outcome_id]['calculations']['student_achieved'];
  716. }
  717. }
  718. */
  719. /*
  720. if ($course->outcomes_att()) {
  721. $course_outcomes_attempted = $course->outcomes_att();
  722. foreach ($course_outcomes_attempted as $outcome => $score) {
  723. if (array_key_exists($outcome, $outcomes_attempted))
  724. $outcomes_attempted[$outcome] += $score;
  725. else $outcomes_attempted[$outcome] = $score;
  726. }
  727. $assessed_courses_count += 1;
  728. }
  729. if ($course->outcomes_ach()) {
  730. $course_outcomes_achieved = $course->outcomes_ach();
  731. foreach ($course_outcomes_achieved as $outcome => $score) {
  732. if (array_key_exists($outcome, $outcomes_achieved))
  733. $outcomes_achieved[$outcome] += $score;
  734. else $outcomes_achieved[$outcome] = $score;
  735. }
  736. }
  737. }
  738. */
  739. // $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  740. // ->whereNull('deleted_at')
  741. // ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  742. // ->orderBy('name', 'ASC')->get();
  743. //
  744. // $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  745. // $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  746. // $assessed_courses_count=0;
  747. // foreach ($program_courses as $course)
  748. // {
  749. // if($course->outcomes_achieved!=NULL)
  750. // {
  751. // $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  752. // $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  753. // for($i=1; $i<=count($outcomes_attempted); $i++)
  754. // {
  755. // $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  756. // $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  757. // }
  758. // $assessed_courses_count+=1;
  759. // }
  760. // }
  761. /**
  762. * List of grouped courses (grouped sections)
  763. */
  764. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  765. $grouped_courses = Course::select(DB::raw('id, name, code, number, semester_id, program_id'))
  766. ->with('semester')
  767. ->with('program')
  768. ->where('program_id', $program->id)
  769. ->whereIn('semester_id', Session::get('semesters_ids'))
  770. ->groupBy(array('code', 'number', 'semester_id'))
  771. ->orderBy('code')
  772. ->orderBy('number')
  773. ->orderBy('semester_id')
  774. ->get();
  775. foreach ($grouped_courses as &$course) {
  776. $course->outcomes_attempted = null;
  777. if (count($course->assessedActivities) and count($course->publishedActivities)) {
  778. $course->outcomes_attempted = true;
  779. }
  780. }
  781. // Log::info($grouped_courses);
  782. // exit();
  783. $semesters = Session::get('semesters_ids');
  784. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  785. Log::info($semesters->start);
  786. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  787. ->whereNull('deleted_at')
  788. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  789. ->orderBy('name', 'ASC')->get();
  790. $outcomeCount = count($outcomes);
  791. $programs_array = array();
  792. $programs_contact = array();
  793. $program_array = array();
  794. $program_array['program'] = $program;
  795. $program_array['outcomes_achieved'] = [];
  796. $program_array['outcomes_attempted'] = [];
  797. $program_array['program_courses'] = $program->courses;
  798. // $program_array['grouped_objectives'] = $program->objectives();
  799. /*
  800. $program_array['assessed_courses_count'] = 0;
  801. foreach ($program_array['program_courses'] as $course) {
  802. if (!$program_array['course_outcomes_achieved'] = $course->outcomes_ach()) {
  803. // $program_array['course_outcomes_achieved'] = $course->outcomes_ach();
  804. $program_array['course_outcomes_attempted'] = $course->outcomes_att();
  805. Log::info($program_array['course_outcomes_achieved']);
  806. foreach ($program_array['course_outcomes_achieved'] as $i => $score) {
  807. if (array_key_exists($i, $program_array['outcomes_achieved'])) $program_array['outcomes_achieved'][$i] += $program_array['course_outcomes_achieved'][$i];
  808. else $program_array['outcomes_achieved'][$i] = $program_array['course_outcomes_achieved'][$i];
  809. }
  810. foreach ($program_array['course_outcomes_attempted'] as $i => $score) {
  811. if (array_key_exists($i, $program_array['outcomes_attempted'])) $program_array['outcomes_attempted'][$i] += $program_array['course_outcomes_attempted'][$i];
  812. else $program_array['outcomes_attempted'][$i] = $program_array['course_outcomes_attempted'][$i];
  813. }
  814. $program_array['assessed_courses_count'] += 1;
  815. }
  816. }*/
  817. /**
  818. * List of grouped courses (grouped sections)
  819. */
  820. //old code
  821. /* $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  822. ->with('semester')
  823. ->with('program')
  824. ->where('program_id', $program->id)
  825. ->whereIn('semester_id', Session::get('semesters_ids'))
  826. ->groupBy(array('code', 'number', 'semester_id'))
  827. ->orderBy('code')
  828. ->orderBy('number')
  829. ->orderBy('semester_id')
  830. ->get(); */
  831. $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, semester_id, program_id'))
  832. ->with('semester')
  833. ->with('program')
  834. ->where('program_id', $program->id)
  835. ->whereIn('semester_id', Session::get('semesters_ids'))
  836. ->groupBy(array('code', 'number', 'semester_id'))
  837. ->orderBy('code')
  838. ->orderBy('number')
  839. ->orderBy('semester_id')
  840. ->get();
  841. $programs_array[] = $program_array;
  842. // Program contact information
  843. $users = User::select('users.*')
  844. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  845. ->where(function ($query) use ($program) {
  846. $query
  847. ->where('school_id', $program->school_id)
  848. ->where('role', 2);
  849. })
  850. ->orWhere(function ($query) use ($program) {
  851. $query
  852. ->where('role', 3)
  853. ->where('program_id', $program->id);
  854. })
  855. ->orWhere(function ($query) use ($program) {
  856. $query
  857. ->where('role', 4)
  858. ->where('program_id', $program->id);
  859. })
  860. ->get();
  861. $programs_contact[] = $users;
  862. return View::make('local.managers.shared.print_program', compact('title', 'program_outcomes_achieved', 'program_outcomes_attempted', 'program', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses'));
  863. }
  864. /**
  865. * A list of all programs
  866. */
  867. public function index()
  868. {
  869. $title = "Programs by School";
  870. $programs = Program::orderBy('name')->get();
  871. $schools = School::all();
  872. $semesters = Semester::all();
  873. return View::make('local.managers.shared.programs', compact('programs', 'schools', 'semesters', 'title'));
  874. }
  875. /**
  876. * Fetch a program
  877. */
  878. public function fetch()
  879. {
  880. Log::info('id:' . Input::get('id'));
  881. return School::find(Input::get('id'))->programs;
  882. }
  883. }