暫無描述

ProgramsController.php 32KB

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