Açıklama Yok

OutcomesController.php 22KB

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