Ei kuvausta

ProgramsController.php 32KB

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