Keine Beschreibung

ProgramsController.php 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  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->program_students_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', 'criteria.id', '=', 'program_criterion.criterion_id')
  234. ->join('courses', 'courses.program_id', '=', 'program_criterion.program_id')
  235. ->where('program_criterion.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', 'criteria.id', '=', 'program_criterion.criterion_id')
  255. ->join('courses', 'courses.program_id', '=', 'program_criterion.program_id')
  256. ->where('program_criterion.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', 'criteria.id', '=', 'program_criterion.criterion_id')
  275. ->join('courses', 'courses.program_id', '=', 'program_criterion.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.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 studentProgramAssessmentReport($program_id)
  295. {
  296. $id = $program_id;
  297. ini_set('memory_limit', -1);
  298. ini_set('max_execution_time', 300);
  299. $program = Program::find($program_id);
  300. $title = $program->school->name . ': ' . $program->name;
  301. $outcomes = Outcome::orderBy('name', 'asc')->get();
  302. $schools = School::all();
  303. $outcomeCount = Outcome::all()->count();
  304. // var_dump(json_encode($outcomes));
  305. $role = Auth::user()->role;
  306. $programs_ids = array($program->id);
  307. $users = User::select('users.*')
  308. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  309. ->where(function ($query) use ($program) {
  310. $query
  311. ->where('school_id', $program->school_id)
  312. ->where('role', 2);
  313. })
  314. ->orWhere(function ($query) use ($program) {
  315. $query
  316. ->where('role', 3)
  317. ->where('program_id', $program->id);
  318. })
  319. ->orWhere(function ($query) use ($program) {
  320. $query
  321. ->where('role', 4)
  322. ->where('program_id', $program->id);
  323. })
  324. ->get();
  325. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  326. // $school = School::find($school_id);
  327. // $title= $school->name;
  328. // $outcomeCount = Outcome::all()->count();
  329. // $programs=Program::where('school_id','=',$school_id)->get();
  330. // $programs_ids=array();
  331. // // var_dump($programs);exit();
  332. // $programs_name=array();
  333. // foreach($programs as $program)
  334. // {
  335. // // var_dump($program);
  336. // $programs_ids[]=$program->id;
  337. // $programs_name[$program->id]=$program->name;
  338. // }
  339. $grouped_courses = Course::
  340. // select(DB::raw('courses.name, courses.code, courses.number, max(courses.outcomes_attempted) as outcomes_attempted, courses.semester_id, courses.program_id'))
  341. select(DB::raw('courses.name, courses.code, courses.number, courses.semester_id, courses.program_id'))
  342. ->with('semester')
  343. ->with('program')
  344. ->whereIn('courses.program_id', $programs_ids)
  345. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  346. ->leftJoin('programs', 'courses.program_id', '=', 'programs.id')
  347. ->groupBy(array('courses.code', 'courses.number', 'courses.semester_id'))
  348. ->orderBy('courses.code')
  349. ->orderBy('courses.number')
  350. ->orderBy('courses.semester_id')
  351. ->get();
  352. $role = Auth::user()->role;
  353. $users = array();
  354. $resultados_todos_obj = DB::table('assessments')
  355. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  356. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  357. ->join('courses', 'courses.id', '=', 'activities.course_id')
  358. ->join('students', 'students.id', '=', 'assessments.student_id')
  359. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  360. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  361. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  362. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  363. ->whereIn('students.program_id', $programs_ids)
  364. ->whereIn('semester_id', Session::get('semesters_ids'))
  365. ->where('semesters.is_visible', '=', 1)
  366. ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  367. ->distinct()
  368. ->get();
  369. foreach ($resultados_todos_obj as $resultado) {
  370. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'])) {
  371. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'] = array();
  372. }
  373. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'][] = $resultado->code;
  374. $resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters'] = array_unique($resultados_todos[$resultado->program_id][$resultado->outcome_id]['semesters']);
  375. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted'])) {
  376. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted'] = 0;
  377. }
  378. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['attempted']++;
  379. if (!isset($resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved'])) {
  380. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved'] = 0;
  381. }
  382. if ($resultado->score >= $resultado->expected_points) {
  383. $resultados_todos[$resultado->program_id][$resultado->outcome_id][$resultado->student_id]['achieved']++;
  384. }
  385. }
  386. $outcomes_colap = array();
  387. $programs = array();
  388. // $outcomes_colap=array();
  389. $i = 0;
  390. $outcomes_attempted = array();
  391. $outcomes_attempted_colap = array();
  392. $outcomes_achieved_colap = array();
  393. $outcomes_attempted_semesters = array();
  394. foreach ($resultados_todos as $program_id => $resultados_prog) {
  395. $outcomes_attempted_semesters[$program_id] = array();
  396. foreach ($resultados_prog as $out => $datos_out) {
  397. $outcomes_achieved[$program_id][$out] = 0;
  398. $outcomes_attempted[$program_id][$out] = 0;
  399. // var_dump($datos_out);outcomes_attempted_semesters
  400. $outcomes_attempted_semesters[$program_id][$out] = $datos_out['semesters'];
  401. unset($datos_out['semesters']);
  402. // var_dump($outcomes_attempted_semesters[$program_id][$out]);
  403. // var_dump($datos_out);
  404. // exit();
  405. foreach ($datos_out as $res) {
  406. $outcomes_attempted[$program_id][$out]++;
  407. if (3 * $res['achieved'] >= 2 * $res['attempted'])
  408. $outcomes_achieved[$program_id][$out]++;
  409. }
  410. }
  411. $programs[] = Program::find($program_id);
  412. if (Program::find($program_id)->is_graduate) {
  413. $colapso = array(1 => array(), 3 => array(), 2 => array(11), 12 => array(7, 14), 10 => array(), 4 => array(6, 15));
  414. } else {
  415. $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());
  416. }
  417. $resultados_todos_colap[$program_id] = array();
  418. foreach ($colapso as $out => $pares) {
  419. $resultados_todos_colap[$program_id][$out]["semesters"] = array();
  420. if (isset($resultados_todos[$program_id][$out]))
  421. $resultados_todos_colap[$program_id][$out] = $resultados_todos[$program_id][$out];
  422. else $resultados_todos_colap[$program_id][$out] = array();
  423. foreach ($pares as $par) {
  424. if (isset($resultados_todos[$program_id][$par])) {
  425. // unset($resultados_todos[$program_id][$par]['semesters']);
  426. foreach ($resultados_todos[$program_id][$par] as $estu => $resus) {
  427. if ($estu != "semesters") {
  428. if (!isset($resultados_todos_colap[$program_id][$out][$estu])) {
  429. $resultados_todos_colap[$program_id][$out][$estu]['attempted'] = 0;
  430. $resultados_todos_colap[$program_id][$out][$estu]['achieved'] = 0;
  431. }
  432. // print $program_id." ".$par." ".$estu."<br>";
  433. // var_dump($resultados_todos[$program_id][$par][$estu]);
  434. $resultados_todos_colap[$program_id][$out][$estu]['attempted'] += $resultados_todos[$program_id][$par][$estu]['attempted'];
  435. $resultados_todos_colap[$program_id][$out][$estu]['achieved'] += $resultados_todos[$program_id][$par][$estu]['achieved'];
  436. } else if (isset($resultados_todos[$program_id][$par]["semesters"])) {
  437. if (isset($resultados_todos_colap[$program_id][$out]["semesters"])) {
  438. $tmp = array_merge($resultados_todos_colap[$program_id][$out]["semesters"], $resultados_todos[$program_id][$par]["semesters"]);
  439. // var_dump(($tmp));
  440. // var_dump(array_unique($tmp));
  441. // exit();
  442. $resultados_todos_colap[$program_id][$out]["semesters"] = array_unique($tmp);
  443. } else
  444. $resultados_todos_colap[$program_id][$out]["semesters"] = array_unique($resultados_todos[$program_id][$par]["semesters"]);
  445. }
  446. }
  447. }
  448. }
  449. }
  450. // var_dump($resultados_todos_colap);
  451. $outcomes_attempted_colap[$program_id] = array();
  452. $outcomes_achieved_colap[$program_id] = array();
  453. $outcomes_attempted_colap_semesters[$program_id] = array();
  454. // print $program_id."<br>";
  455. // var_dump($resultados_todos_colap[$program_id]);
  456. // print "<br>";
  457. foreach ($resultados_todos_colap[$program_id] as $out => $datos_out) {
  458. if (!$i) $outcomes_colap[] = Outcome::find($out);
  459. // $outcomes_attempted_colap_semesters[$program_id][$out]=array();
  460. if (isset($datos_out['semesters'])) {
  461. $outcomes_attempted_colap_semesters[$program_id][$out] = $datos_out['semesters'];
  462. unset($datos_out['semesters']);
  463. }
  464. foreach ($datos_out as $res) {
  465. if (!isset($outcomes_attempted_colap[$program_id][$out])) {
  466. $outcomes_attempted_colap[$program_id][$out] = 0;
  467. $outcomes_achieved_colap[$program_id][$out] = 0;
  468. }
  469. $outcomes_attempted_colap[$program_id][$out]++;
  470. if (3 * $res['achieved'] >= 2 * $res['attempted'])
  471. $outcomes_achieved_colap[$program_id][$out]++;
  472. }
  473. if (empty($datos_out)) {
  474. $outcomes_attempted_colap[$program_id][$out] = 0;
  475. $outcomes_achieved_colap[$program_id][$out] = 0;
  476. }
  477. }
  478. $i++;
  479. }
  480. usort($outcomes_colap, array($this, "cmp"));
  481. // var_dump($outcomes_attempted_colap); print "<br>";
  482. // var_dump($outcomes_achieved_colap); print "<br>";
  483. // exit();
  484. $outcomes_attempted_colap_todo = array();
  485. $outcomes_achieved_colap_todo = array();
  486. foreach ($outcomes_attempted_colap as $program_id => $out_res) {
  487. foreach ($out_res as $out => $res) {
  488. if (!isset($outcomes_attempted_colap_todo[$out])) {
  489. $outcomes_attempted_colap_todo[$out] = 0;
  490. $outcomes_achieved_colap_todo[$out] = 0;
  491. }
  492. $outcomes_attempted_colap_todo[$out] += $outcomes_attempted_colap[$program_id][$out];
  493. $outcomes_achieved_colap_todo[$out] += $outcomes_achieved_colap[$program_id][$out];
  494. }
  495. }
  496. $outcomes_attempted_todo = array();
  497. $outcomes_achieved_todo = array();
  498. foreach ($outcomes_attempted as $program_id => $out_res) {
  499. foreach ($out_res as $out => $res) {
  500. if (!isset($outcomes_attempted_todo[$out])) {
  501. $outcomes_attempted_todo[$out] = 0;
  502. $outcomes_achieved_todo[$out] = 0;
  503. }
  504. $outcomes_attempted_todo[$out] += $outcomes_attempted[$program_id][$out];
  505. $outcomes_achieved_todo[$out] += $outcomes_achieved[$program_id][$out];
  506. }
  507. }
  508. $outcomes_attempted_colap = $outcomes_attempted_colap_todo;
  509. $outcomes_achieved_colap = $outcomes_achieved_colap_todo;
  510. $outcomes_attempted = $outcomes_attempted_todo;
  511. $outcomes_achieved = $outcomes_achieved_todo;
  512. // var_dump($outcomes_attempted_colap);
  513. // var_dump($outcomes_attempted_colap);
  514. // 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'));
  515. 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'));
  516. }
  517. // public function show($id)
  518. // {
  519. //
  520. // $program = Program::find($id);
  521. // $title= $program->school->name.': '.$program->name;
  522. // $program_courses = $program->courses;
  523. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  524. // $schools = School::all();
  525. // $outcomeCount = Outcome::all()->count();
  526. //
  527. //
  528. // $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  529. // $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  530. //
  531. // $assessed_courses_count=0;
  532. // foreach ($program_courses as $course)
  533. // {
  534. // if($course->outcomes_achieved!=NULL)
  535. // {
  536. // $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  537. // $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  538. // for($i=1; $i<=count($outcomes_attempted); $i++)
  539. // {
  540. // $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  541. // $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  542. // }
  543. // $assessed_courses_count+=1;
  544. // }
  545. // }
  546. //
  547. // /**
  548. // * List of grouped courses (grouped sections)
  549. // */
  550. //
  551. // $grouped_courses = Course::
  552. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  553. // ->with('semester')
  554. // ->with('program')
  555. // ->where('program_id', $program->id)
  556. // ->whereIn('semester_id', Session::get('semesters_ids'))
  557. // ->groupBy(array('code', 'number', 'semester_id'))
  558. // ->orderBy('code')
  559. // ->orderBy('number')
  560. // ->orderBy('semester_id')
  561. // ->get();
  562. //
  563. // // Program contact information
  564. // $users = User::
  565. // select('users.*')
  566. // ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  567. // ->where(function($query) use($program)
  568. // {
  569. // $query
  570. // ->where('school_id', $program->school_id)
  571. // ->where('role', 2);
  572. // })
  573. // ->orWhere(function($query) use($program)
  574. // {
  575. // $query
  576. // ->where('role', 3)
  577. // ->where('program_id', $program->id);
  578. // })
  579. // ->orWhere(function($query) use($program)
  580. // {
  581. // $query
  582. // ->where('role', 4)
  583. // ->where('program_id', $program->id);
  584. // })
  585. // ->get();
  586. //
  587. // return View::make('local.managers.shared.program', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses', 'program', 'users'));
  588. //
  589. // }
  590. /**
  591. * Info to print a program
  592. */
  593. public function print_program($id)
  594. {
  595. $program = Program::find($id);
  596. $title = $program->name . ' Assessment Report - ' . date('m/d/Y');
  597. $schools = School::all();
  598. // $outcomeCount = Outcome::all()->count();
  599. $semesters = Session::get('semesters_ids');
  600. // $semesters = DB::table('semesters')->where('id', $course->semester_id)->orderBy('start', 'ASC')->first();
  601. $semesters2 = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  602. $program_courses = $program->courses;
  603. //$outcomes = Outcome::orderBy('name', 'asc')->get();
  604. $outcomes = Outcome::active_by_semesters($semesters2, $program->is_graduate);
  605. $outcomeCount = count($outcomes);
  606. $outcomes_achieved = [];
  607. $outcomes_attempted = [];
  608. $program_outcomes_attempted = [];
  609. $program_outcomes_achieved = [];
  610. // Log::info($program_courses);
  611. foreach ($outcomes as $outcome) {
  612. $outcomes_attempted[$outcome->id] = 0;
  613. $outcomes_achieved[$outcome->id] = 0;
  614. $program_outcomes_attempted[$outcome->id] = 0;
  615. $program_outcomes_achieved[$outcome->id] = 0;
  616. }
  617. $assessed_courses_count = 0;
  618. $program_outcomes_attempted = $program->program_students_per_outcomes['program_info']['outcomes_attempted_combined'];
  619. $program_outcomes_achieved = $program->program_students_per_outcomes['program_info']['outcomes_achieved_combined'];
  620. foreach ($program_courses as $course) {
  621. $student_report = $course->student_report_for_outcome;
  622. if ($student_report) {
  623. foreach ($student_report as $outcome_id => $score) {
  624. if (array_key_exists($outcome_id, $outcomes_attempted)) $outcomes_attempted[$outcome_id] += $student_report[$outcome_id]['calculations']['student_attempted'];
  625. else $outcomes_attempted[$outcome_id] = $student_report[$outcome_id]['calculations']['student_attempted'];
  626. if (array_key_exists($outcome_id, $outcomes_achieved)) $outcomes_achieved[$outcome_id] += $student_report[$outcome_id]['calculations']['student_achieved'];
  627. else $outcomes_achieved[$outcome_id] = $student_report[$outcome_id]['calculations']['student_achieved'];
  628. }
  629. }
  630. /*
  631. $course->with_program_report = 1;
  632. $student_report = $course->student_report_for_outcome;
  633. if ($student_report) {
  634. foreach ($student_report as $outcome_id => $score) {
  635. if (array_key_exists($outcome_id, $program_outcomes_attempted)) $program_outcomes_attempted[$outcome_id] += $student_report[$outcome_id]['calculations']['student_attempted'];
  636. else $program_outcomes_attempted[$outcome_id] = $student_report[$outcome_id]['calculations']['student_attempted'];
  637. if (array_key_exists($outcome_id, $program_outcomes_achieved)) $program_outcomes_achieved[$outcome_id] += $student_report[$outcome_id]['calculations']['student_achieved'];
  638. else $program_outcomes_achieved[$outcome_id] = $student_report[$outcome_id]['calculations']['student_achieved'];
  639. }
  640. }
  641. */
  642. /*
  643. if ($course->outcomes_att()) {
  644. $course_outcomes_attempted = $course->outcomes_att();
  645. foreach ($course_outcomes_attempted as $outcome => $score) {
  646. if (array_key_exists($outcome, $outcomes_attempted))
  647. $outcomes_attempted[$outcome] += $score;
  648. else $outcomes_attempted[$outcome] = $score;
  649. }
  650. $assessed_courses_count += 1;
  651. }
  652. if ($course->outcomes_ach()) {
  653. $course_outcomes_achieved = $course->outcomes_ach();
  654. foreach ($course_outcomes_achieved as $outcome => $score) {
  655. if (array_key_exists($outcome, $outcomes_achieved))
  656. $outcomes_achieved[$outcome] += $score;
  657. else $outcomes_achieved[$outcome] = $score;
  658. }
  659. }
  660. */
  661. }
  662. // $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  663. // ->whereNull('deleted_at')
  664. // ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  665. // ->orderBy('name', 'ASC')->get();
  666. //
  667. // $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  668. // $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  669. // $assessed_courses_count=0;
  670. // foreach ($program_courses as $course)
  671. // {
  672. // if($course->outcomes_achieved!=NULL)
  673. // {
  674. // $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  675. // $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  676. // for($i=1; $i<=count($outcomes_attempted); $i++)
  677. // {
  678. // $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  679. // $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  680. // }
  681. // $assessed_courses_count+=1;
  682. // }
  683. // }
  684. /**
  685. * List of grouped courses (grouped sections)
  686. */
  687. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  688. $grouped_courses = Course::select(DB::raw('id, name, code, number, semester_id, program_id'))
  689. ->with('semester')
  690. ->with('program')
  691. ->where('program_id', $program->id)
  692. ->whereIn('semester_id', Session::get('semesters_ids'))
  693. ->groupBy(array('code', 'number', 'semester_id'))
  694. ->orderBy('code')
  695. ->orderBy('number')
  696. ->orderBy('semester_id')
  697. ->get();
  698. foreach ($grouped_courses as &$course) {
  699. $course->outcomes_attempted = null;
  700. if (count($course->assessedActivities) and count($course->publishedActivities)) {
  701. $course->outcomes_attempted = true;
  702. }
  703. }
  704. // Log::info($grouped_courses);
  705. // exit();
  706. $semesters = Session::get('semesters_ids');
  707. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  708. Log::info($semesters->start);
  709. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  710. ->whereNull('deleted_at')
  711. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  712. ->orderBy('name', 'ASC')->get();
  713. $outcomeCount = count($outcomes);
  714. $programs_array = array();
  715. $programs_contact = array();
  716. $program_array = array();
  717. $program_array['program'] = $program;
  718. $program_array['outcomes_achieved'] = [];
  719. $program_array['outcomes_attempted'] = [];
  720. $program_array['program_courses'] = $program->courses;
  721. // $program_array['grouped_objectives'] = $program->objectives();
  722. $program_array['assessed_courses_count'] = 0;
  723. foreach ($program_array['program_courses'] as $course) {
  724. if (!$program_array['course_outcomes_achieved'] = $course->outcomes_ach()) {
  725. // $program_array['course_outcomes_achieved'] = $course->outcomes_ach();
  726. $program_array['course_outcomes_attempted'] = $course->outcomes_att();
  727. Log::info($program_array['course_outcomes_achieved']);
  728. foreach ($program_array['course_outcomes_achieved'] as $i => $score) {
  729. if (array_key_exists($i, $program_array['outcomes_achieved'])) $program_array['outcomes_achieved'][$i] += $program_array['course_outcomes_achieved'][$i];
  730. else $program_array['outcomes_achieved'][$i] = $program_array['course_outcomes_achieved'][$i];
  731. }
  732. foreach ($program_array['course_outcomes_attempted'] as $i => $score) {
  733. if (array_key_exists($i, $program_array['outcomes_attempted'])) $program_array['outcomes_attempted'][$i] += $program_array['course_outcomes_attempted'][$i];
  734. else $program_array['outcomes_attempted'][$i] = $program_array['course_outcomes_attempted'][$i];
  735. }
  736. $program_array['assessed_courses_count'] += 1;
  737. }
  738. }
  739. /**
  740. * List of grouped courses (grouped sections)
  741. */
  742. //old code
  743. /* $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  744. ->with('semester')
  745. ->with('program')
  746. ->where('program_id', $program->id)
  747. ->whereIn('semester_id', Session::get('semesters_ids'))
  748. ->groupBy(array('code', 'number', 'semester_id'))
  749. ->orderBy('code')
  750. ->orderBy('number')
  751. ->orderBy('semester_id')
  752. ->get(); */
  753. $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, semester_id, program_id'))
  754. ->with('semester')
  755. ->with('program')
  756. ->where('program_id', $program->id)
  757. ->whereIn('semester_id', Session::get('semesters_ids'))
  758. ->groupBy(array('code', 'number', 'semester_id'))
  759. ->orderBy('code')
  760. ->orderBy('number')
  761. ->orderBy('semester_id')
  762. ->get();
  763. $programs_array[] = $program_array;
  764. // Program contact information
  765. $users = User::select('users.*')
  766. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  767. ->where(function ($query) use ($program) {
  768. $query
  769. ->where('school_id', $program->school_id)
  770. ->where('role', 2);
  771. })
  772. ->orWhere(function ($query) use ($program) {
  773. $query
  774. ->where('role', 3)
  775. ->where('program_id', $program->id);
  776. })
  777. ->orWhere(function ($query) use ($program) {
  778. $query
  779. ->where('role', 4)
  780. ->where('program_id', $program->id);
  781. })
  782. ->get();
  783. $programs_contact[] = $users;
  784. 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'));
  785. }
  786. /**
  787. * A list of all programs
  788. */
  789. public function index()
  790. {
  791. $title = "Programs by School";
  792. $programs = Program::orderBy('name')->get();
  793. $schools = School::all();
  794. $semesters = Semester::all();
  795. return View::make('local.managers.shared.programs', compact('programs', 'schools', 'semesters', 'title'));
  796. }
  797. /**
  798. * Fetch a program
  799. */
  800. public function fetch()
  801. {
  802. Log::info('id:' . Input::get('id'));
  803. return School::find(Input::get('id'))->programs;
  804. }
  805. }