Nav apraksta

ProgramsController.php 32KB

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