Aucune description

OutcomesController.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <?php
  2. class OutcomesController extends \BaseController {
  3. /**
  4. * Show all Learning Outcomes and expected values
  5. *
  6. */
  7. public function index()
  8. {
  9. $title = "Learning Outcomes";
  10. $outcomes = Outcome::withTrashed()->orderBy('name', 'ASC')->get();
  11. $schools = School::orderBy('name', 'ASC')->get();
  12. return View::make('local.managers.admins.learning-outcomes', compact('title', 'outcomes', 'schools'));
  13. }
  14. // TODO: Change to home page
  15. public function newIndex()
  16. {
  17. $title = "Learning Outcomes";
  18. $outcomes = Outcome::withTrashed()->orderBy('name', 'ASC')->get();
  19. $schools = School::orderBy('name', 'ASC')->get();
  20. return View::make('local.managers.admins.new-learning-outcomes', compact('title', 'outcomes', 'schools'));
  21. // return View::make('local.managers.admins.learning-outcomes', compact('title', 'outcomes', 'schools'));
  22. }
  23. public function show($id)
  24. {
  25. DB::disableQueryLog();
  26. $outcome = Outcome::find($id);
  27. $undergradResults=array("names"=>array(), "schools"=>array(), "achieved"=>array(), "attempted"=>array(), "successRate"=>array());
  28. $gradResults = array("names"=>array(), "schools"=>array(), "achieved"=>array(), "attempted"=>array(), "successRate"=>array());
  29. //Calculate performance for this outcome for each undergrad program
  30. $undergradPrograms = Program::where('is_graduate','=', 0)
  31. ->where(function($query)
  32. {
  33. if(Auth::user()->school_id)
  34. {
  35. $query->where('school_id', Auth::user()->school_id);
  36. }
  37. })
  38. ->with('courses')
  39. ->orderBy('name', 'asc')->get();
  40. foreach($undergradPrograms as $program)
  41. {
  42. $undergradResults["names"][$program->id]=$program->name;
  43. $undergradResults["schools"][$program->id]=$program->school->name;
  44. $programAssessed=false;
  45. $undergradResults["attempted"][$program->id]=0;
  46. $undergradResults["achieved"][$program->id]=0;
  47. foreach($program->courses as $course)
  48. {
  49. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  50. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  51. $attemptedCriteriaCount=0;
  52. $achievedCriteriaCount=0;
  53. // If this outcome was evaluated
  54. if(
  55. $course_outcomes_attempted
  56. && array_key_exists($outcome->id, $course_outcomes_attempted)
  57. && $course_outcomes_attempted[$outcome->id]!=0)
  58. {
  59. // Count +1 for attempted and achieved in the program
  60. $attemptedCriteriaCount+=$course_outcomes_attempted[$outcome->id];
  61. $achievedCriteriaCount+=$course_outcomes_achieved[$outcome->id];
  62. $programAssessed=true;
  63. if($attemptedCriteriaCount>0 &&(float)$achievedCriteriaCount/$attemptedCriteriaCount*100 > $outcome->expected_outcome)
  64. {
  65. $undergradResults["achieved"][$program->id]+=1;
  66. }
  67. $undergradResults["attempted"][$program->id]+=1;
  68. }
  69. }
  70. // Calculate success rate for this program
  71. if($programAssessed && $undergradResults["attempted"][$program->id]>0)
  72. $undergradResults["successRate"][$program->id]= round((float)$undergradResults["achieved"][$program->id]/$undergradResults["attempted"][$program->id]*100, 2).'%';
  73. else
  74. $undergradResults["successRate"][$program->id]= 'N/M';
  75. }
  76. //Calculate performance for this outcome for each grad program
  77. $gradPrograms = Program::where('is_graduate','=', 1)
  78. ->where(function($query)
  79. {
  80. if(Auth::user()->school_id)
  81. {
  82. $query->where('school_id', Auth::user()->school_id);
  83. }
  84. })
  85. ->with(array('courses'=>function($query)
  86. {
  87. $query->whereNotNull('outcomes_attempted');
  88. }))
  89. ->orderBy('name', 'asc')->get();
  90. foreach($gradPrograms as $program)
  91. {
  92. $gradResults["names"][$program->id]=$program->name;
  93. $gradResults["schools"][$program->id]=$program->school->name;
  94. $programAssessed=false;
  95. $gradResults["attempted"][$program->id]=0;
  96. $gradResults["achieved"][$program->id]=0;
  97. foreach($program->courses as $course)
  98. {
  99. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  100. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  101. $attemptedCriteriaCount=0;
  102. $achievedCriteriaCount=0;
  103. // If this outcome was evaluated
  104. if(
  105. $course_outcomes_attempted
  106. && array_key_exists($outcome->id, $course_outcomes_attempted)
  107. && $course_outcomes_attempted[$outcome->id]!=0)
  108. {
  109. // Count +1 for attempted and achieved in the program
  110. $attemptedCriteriaCount+=$course_outcomes_attempted[$outcome->id];
  111. $achievedCriteriaCount+=$course_outcomes_achieved[$outcome->id];
  112. $programAssessed=true;
  113. if($attemptedCriteriaCount>0 &&(float)$achievedCriteriaCount/$attemptedCriteriaCount*100 > $outcome->expected_outcome)
  114. {
  115. $gradResults["achieved"][$program->id]+=1;
  116. }
  117. $gradResults["attempted"][$program->id]+=1;
  118. }
  119. }
  120. // Calculate success rate for this program
  121. if($programAssessed && $gradResults["attempted"][$program->id]>0)
  122. $gradResults["successRate"][$program->id]= round((float)$gradResults["achieved"][$program->id]/$gradResults["attempted"][$program->id]*100, 2).'%';
  123. else
  124. $gradResults["successRate"][$program->id]= 'N/M';
  125. }
  126. $title = "Outcome Results: ".$outcome->name;
  127. return View::make('local.managers.admins.learning-outcome', compact('title', 'outcome', 'undergradResults', 'gradResults'));
  128. }
  129. public function newShow($id)
  130. {
  131. // DB::disableQueryLog();
  132. $outcome = Outcome::find($id);
  133. $title = $outcome->name;
  134. $courses = Auth::user()->courses()->get();
  135. $activities = [];
  136. foreach ($courses as $course) {
  137. foreach ($course->activities as $activity) {
  138. $activities[] = $activity;
  139. }
  140. }
  141. return View::make('local.managers.admins.new-learning-outcome', compact('title', 'outcome', 'courses', 'activities'));
  142. }
  143. public function update()
  144. {
  145. $outcomeArray = json_decode(Input::get('outcomeArray'), true);
  146. Session::flash('status', 'success');
  147. Session::flash('message', 'Learning Outcomes updated.');
  148. foreach ($outcomeArray as $outcomeObject)
  149. {
  150. $validator = Validator::make(
  151. array(
  152. 'name' => $outcomeObject['name'],
  153. 'definition' => $outcomeObject['definition'],
  154. 'expected_outcome' => $outcomeObject['expected_outcome']
  155. ),
  156. array(
  157. 'name' => 'required',
  158. 'definition' => 'required',
  159. 'expected_outcome' => 'required|numeric'
  160. )
  161. );
  162. if(!$validator->fails())
  163. {
  164. try
  165. {
  166. $outcome = Outcome::withTrashed()
  167. ->where('id','=', $outcomeObject['id'])
  168. ->firstOrFail();
  169. $outcome->name = $outcomeObject['name'];
  170. $outcome->definition = $outcomeObject['definition'];
  171. $outcome->expected_outcome = $outcomeObject['expected_outcome'];
  172. $outcome->save();
  173. // If delete is 1, and outcome isn't already trashed, delete
  174. if($outcomeObject['delete']==1 && !$outcome->trashed())
  175. $outcome->delete();
  176. // If delete is 0, and outcome is already trashed, restore
  177. elseif($outcomeObject['delete']==0 && $outcome->trashed())
  178. $outcome->restore();
  179. }
  180. catch(Exception $e)
  181. {
  182. Session::flash('message', $e->getMessage());
  183. }
  184. }
  185. else
  186. {
  187. /** Prepare error message */
  188. $message = 'Error(s) updating the Learning Outcomes: <ul>';
  189. foreach ($validator->messages()->all('<li>:message</li>') as $validationError)
  190. {
  191. $message.=$validationError;
  192. }
  193. $message.='</ul>';
  194. /** Send error message and old data */
  195. Session::flash('status', 'danger');
  196. Session::flash('message', $message);
  197. return;
  198. }
  199. }
  200. return;
  201. }
  202. public function fetchCriteria()
  203. {
  204. if(Input::get('filter'))
  205. {
  206. switch (Input::get('filter'))
  207. {
  208. case 'all':
  209. return Outcome::find(Input::get('id'))->criteria;
  210. break;
  211. case 'school':
  212. // If scoord
  213. if(Auth::user()->role == '2')
  214. {
  215. // Fetch all the programs whose school is the user's
  216. $program_ids = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
  217. // Return all criteria belonging to any of those programs
  218. return Criterion::
  219. where('outcome_id', Input::get('id'))
  220. ->whereIn('program_id', $program_ids)
  221. ->orderBy('name', 'ASC')
  222. ->get();
  223. }
  224. // If pcoord
  225. else
  226. {
  227. // Fetch all the programs from the user's school;
  228. $program_ids = DB::table('programs')->where('school_id', Auth::user()->programs[0]->school->id)->lists('id');
  229. return Criterion::
  230. where('outcome_id', Input::get('id'))
  231. ->whereIn('program_id', $program_ids)
  232. ->orderBy('name', 'ASC')
  233. ->get();
  234. }
  235. break;
  236. case 'program':
  237. return Criterion::
  238. where('outcome_id', Input::get('id'))
  239. ->whereIn('program_id', Auth::user()->programs->lists('id'))
  240. ->orderBy('name', 'ASC')
  241. ->get();
  242. break;
  243. default:
  244. return Outcome::find(Input::get('id'))->criteria;
  245. break;
  246. }
  247. }
  248. else
  249. {
  250. return Outcome::find(Input::get('id'))->criteria;
  251. }
  252. }
  253. /**
  254. * Create a new learning outcome.
  255. */
  256. public function create()
  257. {
  258. /** Validation rules */
  259. $validator = Validator::make(
  260. array(
  261. 'name' => Input::get('name'),
  262. 'definition' => Input::get('definition')
  263. ),
  264. array(
  265. 'name' => 'required|unique:outcomes',
  266. 'definition' => 'required|min:10'
  267. )
  268. );
  269. /** If validation fails */
  270. if ($validator->fails())
  271. {
  272. /** Prepare error message */
  273. $message = '<p>Error(s) creating a new Learning Outcome</p><ul>';
  274. foreach ($validator->messages()->all('<li>:message</li>') as $validationError)
  275. {
  276. $message.=$validationError;
  277. }
  278. $message.='</ul>';
  279. /** Send error message and old data */
  280. Session::flash('status', 'warning');
  281. Session::flash('message', $message);
  282. return Redirect::to('learning-outcomes-criteria')->withInput();
  283. }
  284. else
  285. {
  286. /** Instantiate new outcome */
  287. $outcome = new Outcome;
  288. $outcome->name= Input::get('name');
  289. $outcome->definition = Input::get('definition');
  290. /** If outcome is saved, send success message */
  291. if($outcome->save())
  292. {
  293. Session::flash('status', 'success');
  294. Session::flash('message', '<p>Learning Outcome added.</p>');
  295. return Redirect::to('learning-outcomes-criteria');
  296. }
  297. /** If saving fails, send error message and old data */
  298. else
  299. {
  300. Session::flash('status', 'warning');
  301. Session::flash('message', '<p>Error adding Learning Outcome. Please try again later.</p>');
  302. return Redirect::to('learning-outcomes-criteria')->withInput();
  303. }
  304. }
  305. }
  306. public function fetchOutcome()
  307. {
  308. $id = Input::get('id');
  309. $outcome = Outcome::find($id);
  310. $outcome->criteria;
  311. return array
  312. (
  313. 'outcome' => $outcome
  314. );
  315. }
  316. public function managerAssessmentReports()
  317. {
  318. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  319. switch (Auth::user()->role) {
  320. case 1:
  321. $title = "Campus Assessment Reports";
  322. return View::make('local.managers.admins.assessment_reports', compact('title', 'outcomes'));
  323. break;
  324. case 2:
  325. $title = "School Assessment Reports";
  326. return View::make('local.managers.sCoords.assessment_reports', compact('title', 'outcomes'));
  327. break;
  328. case 3:
  329. $title = "Program Assessment Reports";
  330. $programs = Auth::user()->programs;
  331. return View::make('local.managers.pCoords.assessment_reports', compact('title', 'outcomes', 'programs'));
  332. break;
  333. default:
  334. App::abort('404');
  335. break;
  336. }
  337. }
  338. /**
  339. * Campus Assessment Reports
  340. */
  341. public function assessmentReport($outcome_id)
  342. {
  343. $outcome = Outcome::find($outcome_id);
  344. if(!$outcome)
  345. App::abort('404');
  346. $title = "Assessment Report: ".$outcome->name;
  347. $schools = School::
  348. has('courses')
  349. ->with(array('programs'=>function($query) use($outcome_id){
  350. $query
  351. ->has('courses')
  352. ->with(array('courses'=>function($query2) use($outcome_id){
  353. $query2
  354. ->has('activities')
  355. ->whereNotNull('outcomes_attempted')
  356. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  357. ->whereIn('semester_id', Session::get('semesters_ids'))
  358. ->groupBy(array('code', 'number'));
  359. }));
  360. }))
  361. ->get();
  362. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  363. }
  364. // TODO: Change later
  365. public function newAssessmentReport($outcome_id)
  366. {
  367. $outcome = Outcome::find($outcome_id);
  368. if(!$outcome)
  369. App::abort('404');
  370. $title = "Assessment Report: ".$outcome->name;
  371. $schools = School::
  372. has('courses')
  373. ->with(array('programs'=>function($query) use($outcome_id){
  374. $query
  375. ->has('courses')
  376. ->with(array('courses'=>function($query2) use($outcome_id){
  377. $query2
  378. ->has('activities')
  379. ->whereNotNull('outcomes_attempted')
  380. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  381. ->whereIn('semester_id', Session::get('semesters_ids'))
  382. ->groupBy(array('code', 'number'));
  383. }));
  384. }))
  385. ->get();
  386. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  387. }
  388. /**
  389. * School Assessment Reports
  390. */
  391. public function schoolAssessmentReport($outcome_id)
  392. {
  393. $outcome = Outcome::find($outcome_id);
  394. if(!$outcome)
  395. App::abort('404');
  396. $title = "Assessment Report: ".$outcome->name;
  397. $school = School::
  398. where('id', Auth::user()->school_id)
  399. ->has('courses')
  400. ->with(array('programs'=>function($query){
  401. $query
  402. ->has('courses')
  403. ->with(array('courses'=>function($query2){
  404. $query2
  405. ->has('activities')
  406. ->whereNotNull('outcomes_attempted')
  407. ->whereIn('semester_id', Session::get('semesters_ids'))
  408. ->groupBy(array('code', 'number'));
  409. }));
  410. }))
  411. ->first();
  412. return View::make('local.managers.sCoords.assessment_report', compact('title', 'outcome', 'school'));
  413. }
  414. /**
  415. * Program Assessment Reports
  416. */
  417. public function programAssessmentReport($outcome_id, $program_id)
  418. {
  419. $outcome = Outcome::find($outcome_id);
  420. if(!$outcome)
  421. App::abort('404');
  422. $title = "Assessment Report: ".$outcome->name;
  423. $program = Program::
  424. where('id', $program_id)
  425. ->has('courses')
  426. ->with(array('courses'=>function($query){
  427. $query
  428. ->has('activities')
  429. ->whereNotNull('outcomes_attempted')
  430. ->whereIn('semester_id', Session::get('semesters_ids'))
  431. ->groupBy(array('code', 'number'));
  432. }))
  433. ->first();
  434. return View::make('local.managers.pCoords.assessment_report', compact('title', 'outcome', 'program'));
  435. }
  436. public function professorAssessmentReports()
  437. {
  438. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  439. $title = "My Courses' Assessment Reports";
  440. return View::make('local.professors.assessment_reports', compact('title', 'outcomes'));
  441. }
  442. // Report for a single professor with a single learning outcome
  443. public function professorAssessmentReport($outcome_id)
  444. {
  445. $outcome = Outcome::find($outcome_id);
  446. if(!$outcome)
  447. App::abort('404');
  448. $title = "My Courses' Assessment Report: ".$outcome->name;
  449. $courses = Course::
  450. where('user_id', Auth::user()->id)
  451. ->has('activities')
  452. ->whereNotNull('outcomes_attempted')
  453. ->whereIn('semester_id', Session::get('semesters_ids'))
  454. ->groupBy(array('code', 'number'))
  455. ->get();
  456. return View::make('local.professors.assessment_report', compact('title', 'outcome', 'courses'));
  457. }
  458. }