No Description

ProgramsController.php 34KB

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