No Description

OutcomesController.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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. return View::make('local.managers.admins.new-learning-outcome', compact('title', 'outcome'));
  135. }
  136. public function update()
  137. {
  138. $outcomeArray = json_decode(Input::get('outcomeArray'), true);
  139. Session::flash('status', 'success');
  140. Session::flash('message', 'Learning Outcomes updated.');
  141. foreach ($outcomeArray as $outcomeObject)
  142. {
  143. $validator = Validator::make(
  144. array(
  145. 'name' => $outcomeObject['name'],
  146. 'definition' => $outcomeObject['definition'],
  147. 'expected_outcome' => $outcomeObject['expected_outcome']
  148. ),
  149. array(
  150. 'name' => 'required',
  151. 'definition' => 'required',
  152. 'expected_outcome' => 'required|numeric'
  153. )
  154. );
  155. if(!$validator->fails())
  156. {
  157. try
  158. {
  159. $outcome = Outcome::withTrashed()
  160. ->where('id','=', $outcomeObject['id'])
  161. ->firstOrFail();
  162. $outcome->name = $outcomeObject['name'];
  163. $outcome->definition = $outcomeObject['definition'];
  164. $outcome->expected_outcome = $outcomeObject['expected_outcome'];
  165. $outcome->save();
  166. // If delete is 1, and outcome isn't already trashed, delete
  167. if($outcomeObject['delete']==1 && !$outcome->trashed())
  168. $outcome->delete();
  169. // If delete is 0, and outcome is already trashed, restore
  170. elseif($outcomeObject['delete']==0 && $outcome->trashed())
  171. $outcome->restore();
  172. }
  173. catch(Exception $e)
  174. {
  175. Session::flash('message', $e->getMessage());
  176. }
  177. }
  178. else
  179. {
  180. /** Prepare error message */
  181. $message = 'Error(s) updating the Learning Outcomes: <ul>';
  182. foreach ($validator->messages()->all('<li>:message</li>') as $validationError)
  183. {
  184. $message.=$validationError;
  185. }
  186. $message.='</ul>';
  187. /** Send error message and old data */
  188. Session::flash('status', 'danger');
  189. Session::flash('message', $message);
  190. return;
  191. }
  192. }
  193. return;
  194. }
  195. public function fetchCriteria()
  196. {
  197. if(Input::get('filter'))
  198. {
  199. switch (Input::get('filter'))
  200. {
  201. case 'all':
  202. return Outcome::find(Input::get('id'))->criteria;
  203. break;
  204. case 'school':
  205. // If scoord
  206. if(Auth::user()->role == '2')
  207. {
  208. // Fetch all the programs whose school is the user's
  209. $program_ids = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
  210. // Return all criteria belonging to any of those programs
  211. return Criterion::
  212. where('outcome_id', Input::get('id'))
  213. ->whereIn('program_id', $program_ids)
  214. ->orderBy('name', 'ASC')
  215. ->get();
  216. }
  217. // If pcoord
  218. else
  219. {
  220. // Fetch all the programs from the user's school;
  221. $program_ids = DB::table('programs')->where('school_id', Auth::user()->programs[0]->school->id)->lists('id');
  222. return Criterion::
  223. where('outcome_id', Input::get('id'))
  224. ->whereIn('program_id', $program_ids)
  225. ->orderBy('name', 'ASC')
  226. ->get();
  227. }
  228. break;
  229. case 'program':
  230. return Criterion::
  231. where('outcome_id', Input::get('id'))
  232. ->whereIn('program_id', Auth::user()->programs->lists('id'))
  233. ->orderBy('name', 'ASC')
  234. ->get();
  235. break;
  236. default:
  237. return Outcome::find(Input::get('id'))->criteria;
  238. break;
  239. }
  240. }
  241. else
  242. {
  243. return Outcome::find(Input::get('id'))->criteria;
  244. }
  245. }
  246. /**
  247. * Create a new learning outcome.
  248. */
  249. public function create()
  250. {
  251. /** Validation rules */
  252. $validator = Validator::make(
  253. array(
  254. 'name' => Input::get('name'),
  255. 'definition' => Input::get('definition')
  256. ),
  257. array(
  258. 'name' => 'required|unique:outcomes',
  259. 'definition' => 'required|min:10'
  260. )
  261. );
  262. /** If validation fails */
  263. if ($validator->fails())
  264. {
  265. /** Prepare error message */
  266. $message = '<p>Error(s) creating a new Learning Outcome</p><ul>';
  267. foreach ($validator->messages()->all('<li>:message</li>') as $validationError)
  268. {
  269. $message.=$validationError;
  270. }
  271. $message.='</ul>';
  272. /** Send error message and old data */
  273. Session::flash('status', 'warning');
  274. Session::flash('message', $message);
  275. return Redirect::to('learning-outcomes-criteria')->withInput();
  276. }
  277. else
  278. {
  279. /** Instantiate new outcome */
  280. $outcome = new Outcome;
  281. $outcome->name= Input::get('name');
  282. $outcome->definition = Input::get('definition');
  283. /** If outcome is saved, send success message */
  284. if($outcome->save())
  285. {
  286. Session::flash('status', 'success');
  287. Session::flash('message', '<p>Learning Outcome added.</p>');
  288. return Redirect::to('learning-outcomes-criteria');
  289. }
  290. /** If saving fails, send error message and old data */
  291. else
  292. {
  293. Session::flash('status', 'warning');
  294. Session::flash('message', '<p>Error adding Learning Outcome. Please try again later.</p>');
  295. return Redirect::to('learning-outcomes-criteria')->withInput();
  296. }
  297. }
  298. }
  299. public function fetchOutcome()
  300. {
  301. $id = Input::get('id');
  302. $outcome = Outcome::find($id);
  303. $outcome->criteria;
  304. return array
  305. (
  306. 'outcome' => $outcome
  307. );
  308. }
  309. public function managerAssessmentReports()
  310. {
  311. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  312. switch (Auth::user()->role) {
  313. case 1:
  314. $title = "Campus Assessment Reports";
  315. return View::make('local.managers.admins.assessment_reports', compact('title', 'outcomes'));
  316. break;
  317. case 2:
  318. $title = "School Assessment Reports";
  319. return View::make('local.managers.sCoords.assessment_reports', compact('title', 'outcomes'));
  320. break;
  321. case 3:
  322. $title = "Program Assessment Reports";
  323. $programs = Auth::user()->programs;
  324. return View::make('local.managers.pCoords.assessment_reports', compact('title', 'outcomes', 'programs'));
  325. break;
  326. default:
  327. App::abort('404');
  328. break;
  329. }
  330. }
  331. /**
  332. * Campus Assessment Reports
  333. */
  334. public function assessmentReport($outcome_id)
  335. {
  336. $outcome = Outcome::find($outcome_id);
  337. if(!$outcome)
  338. App::abort('404');
  339. $title = "Assessment Report: ".$outcome->name;
  340. $schools = School::
  341. has('courses')
  342. ->with(array('programs'=>function($query) use($outcome_id){
  343. $query
  344. ->has('courses')
  345. ->with(array('courses'=>function($query2) use($outcome_id){
  346. $query2
  347. ->has('activities')
  348. ->whereNotNull('outcomes_attempted')
  349. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  350. ->whereIn('semester_id', Session::get('semesters_ids'))
  351. ->groupBy(array('code', 'number'));
  352. }));
  353. }))
  354. ->get();
  355. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  356. }
  357. // TODO: Change later
  358. public function newAssessmentReport($outcome_id)
  359. {
  360. $outcome = Outcome::find($outcome_id);
  361. if(!$outcome)
  362. App::abort('404');
  363. $title = "Assessment Report: ".$outcome->name;
  364. $schools = School::
  365. has('courses')
  366. ->with(array('programs'=>function($query) use($outcome_id){
  367. $query
  368. ->has('courses')
  369. ->with(array('courses'=>function($query2) use($outcome_id){
  370. $query2
  371. ->has('activities')
  372. ->whereNotNull('outcomes_attempted')
  373. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  374. ->whereIn('semester_id', Session::get('semesters_ids'))
  375. ->groupBy(array('code', 'number'));
  376. }));
  377. }))
  378. ->get();
  379. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  380. }
  381. /**
  382. * School Assessment Reports
  383. */
  384. public function schoolAssessmentReport($outcome_id)
  385. {
  386. $outcome = Outcome::find($outcome_id);
  387. if(!$outcome)
  388. App::abort('404');
  389. $title = "Assessment Report: ".$outcome->name;
  390. $school = School::
  391. where('id', Auth::user()->school_id)
  392. ->has('courses')
  393. ->with(array('programs'=>function($query){
  394. $query
  395. ->has('courses')
  396. ->with(array('courses'=>function($query2){
  397. $query2
  398. ->has('activities')
  399. ->whereNotNull('outcomes_attempted')
  400. ->whereIn('semester_id', Session::get('semesters_ids'))
  401. ->groupBy(array('code', 'number'));
  402. }));
  403. }))
  404. ->first();
  405. return View::make('local.managers.sCoords.assessment_report', compact('title', 'outcome', 'school'));
  406. }
  407. /**
  408. * Program Assessment Reports
  409. */
  410. public function programAssessmentReport($outcome_id, $program_id)
  411. {
  412. $outcome = Outcome::find($outcome_id);
  413. if(!$outcome)
  414. App::abort('404');
  415. $title = "Assessment Report: ".$outcome->name;
  416. $program = Program::
  417. where('id', $program_id)
  418. ->has('courses')
  419. ->with(array('courses'=>function($query){
  420. $query
  421. ->has('activities')
  422. ->whereNotNull('outcomes_attempted')
  423. ->whereIn('semester_id', Session::get('semesters_ids'))
  424. ->groupBy(array('code', 'number'));
  425. }))
  426. ->first();
  427. return View::make('local.managers.pCoords.assessment_report', compact('title', 'outcome', 'program'));
  428. }
  429. public function professorAssessmentReports()
  430. {
  431. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  432. $title = "My Courses' Assessment Reports";
  433. return View::make('local.professors.assessment_reports', compact('title', 'outcomes'));
  434. }
  435. // Report for a single professor with a single learning outcome
  436. public function professorAssessmentReport($outcome_id)
  437. {
  438. $outcome = Outcome::find($outcome_id);
  439. if(!$outcome)
  440. App::abort('404');
  441. $title = "My Courses' Assessment Report: ".$outcome->name;
  442. $courses = Course::
  443. where('user_id', Auth::user()->id)
  444. ->has('activities')
  445. ->whereNotNull('outcomes_attempted')
  446. ->whereIn('semester_id', Session::get('semesters_ids'))
  447. ->groupBy(array('code', 'number'))
  448. ->get();
  449. return View::make('local.professors.assessment_report', compact('title', 'outcome', 'courses'));
  450. }
  451. }