Sin descripción

OutcomesController.php 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. <?php
  2. use Illuminate\Database\Eloquent\Collection;
  3. class OutcomesController extends \BaseController
  4. {
  5. /**
  6. * Show all Learning Outcomes and expected values
  7. *
  8. */
  9. public function index()
  10. {
  11. $title = "Learning Outcomes";
  12. $outcomes = Outcome::withTrashed()->orderBy('name', 'ASC')->get();
  13. $schools = School::orderBy('name', 'ASC')->get();
  14. // $semesters_ids = Session::get('semesters_ids');
  15. // $semesters = Semester::whereIn('id',$semesters_ids)->get();
  16. return View::make('local.managers.admins.learning-outcomes', compact('title', 'outcomes', 'schools'));
  17. //return View::make('local.managers.admins.learning-outcomes', compact('title', 'outcomes', 'schools','semesters'));
  18. }
  19. // TODO: Change to home page
  20. public function newIndex()
  21. {
  22. $title = "Learning Outcomes";
  23. // TODO: Check when semester doesnt exist or session is empty
  24. $selected_semester = Semester::find(Session::get('semesters_ids')[0]);
  25. $outcomes = Outcome::withTrashed()->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null)->orderBy('name', 'ASC')->get();
  26. $schools = School::orderBy('name', 'ASC')->get();
  27. return View::make('local.managers.admins.new-learning-outcomes', compact('title', 'outcomes', 'schools'));
  28. }
  29. public function show($id)
  30. {
  31. $outcome = Outcome::find($id);
  32. $selected_semesters = Semester::find(Session::get('semesters_ids'));
  33. $programs = $outcome->programs_attempted($selected_semesters);
  34. $undergradResults = array("names" => array(), "schools" => array(), "achieved" => array(), "attempted" => array(), "successRate" => array());
  35. $gradResults = array("names" => array(), "schools" => array(), "achieved" => array(), "attempted" => array(), "successRate" => array());
  36. foreach ($programs as $program_id) {
  37. // var_dump($program_id);
  38. // exit();
  39. $program = Program::where('id', '=', $program_id->id)->first();
  40. $school = School::where('id', '=', $program->school_id)->first();
  41. if($program->is_graduate)
  42. {
  43. $gradResults['names'][] = $program->name;
  44. $gradResults['schools'][] = $school->name;
  45. $attempted = $program->attempted_criteria_by_outcome($id, $selected_semesters);
  46. $gradResults['attempted'][] = $attempted;
  47. $achieved = $program->achieved_criteria_by_outcome($id, $selected_semesters);
  48. $gradResults['achieved'][] = $achieved;
  49. $gradResults['successRate'][] = sprintf("%.2f",100*$achieved/$attempted);
  50. }
  51. else
  52. {
  53. $undergradResults['names'][] = $program->name;
  54. $undergradResults['schools'][] = $school->name;
  55. $attempted = $program->attempted_criteria_by_outcome($id,$selected_semesters);
  56. $undergradResults['attempted'][] = $attempted;
  57. $achieved = $program->achieved_criteria_by_outcome($id,$selected_semesters);
  58. $undergradResults['achieved'][] = $achieved;
  59. $undergradResults['successRate'][] = sprintf("%.2f",100*$achieved/$attempted);
  60. }
  61. }
  62. $title = "Outcome Results: ".$outcome->name;
  63. // $undergradResults["successRate"]
  64. return View::make('local.managers.admins.learning-outcome_new', compact('title', 'outcome', 'undergradResults', 'gradResults'));
  65. }
  66. // public function show($id)
  67. // {
  68. // DB::disableQueryLog();
  69. // $outcome = Outcome::find($id);
  70. //
  71. // $undergradResults=array("names"=>array(), "schools"=>array(), "achieved"=>array(), "attempted"=>array(), "successRate"=>array());
  72. // $gradResults = array("names"=>array(), "schools"=>array(), "achieved"=>array(), "attempted"=>array(), "successRate"=>array());
  73. //
  74. // //Calculate performance for this outcome for each undergrad program
  75. // $undergradPrograms = Program::where('is_graduate','=', 0)
  76. // ->where(function($query)
  77. // {
  78. // if(Auth::user()->school_id)
  79. // {
  80. // $query->where('school_id', Auth::user()->school_id);
  81. // }
  82. // })
  83. // ->with('courses')
  84. // ->orderBy('name', 'asc')->get();
  85. //
  86. // foreach($undergradPrograms as $program)
  87. // {
  88. // $undergradResults["names"][$program->id]=$program->name;
  89. // $undergradResults["schools"][$program->id]=$program->school->name;
  90. // $programAssessed=false;
  91. //
  92. // $undergradResults["attempted"][$program->id]=0;
  93. // $undergradResults["achieved"][$program->id]=0;
  94. //
  95. // foreach($program->courses as $course)
  96. // {
  97. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  98. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  99. //
  100. // $attemptedCriteriaCount=0;
  101. // $achievedCriteriaCount=0;
  102. //
  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. //
  114. // if($attemptedCriteriaCount>0 &&(float)$achievedCriteriaCount/$attemptedCriteriaCount*100 > $outcome->expected_outcome)
  115. // {
  116. // $undergradResults["achieved"][$program->id]+=1;
  117. // }
  118. // $undergradResults["attempted"][$program->id]+=1;
  119. // }
  120. // }
  121. //
  122. // // Calculate success rate for this program
  123. // if($programAssessed && $undergradResults["attempted"][$program->id]>0)
  124. // $undergradResults["successRate"][$program->id]= round((float)$undergradResults["achieved"][$program->id]/$undergradResults["attempted"][$program->id]*100, 2).'%';
  125. // else
  126. // $undergradResults["successRate"][$program->id]= 'N/M';
  127. // }
  128. //
  129. //
  130. // //Calculate performance for this outcome for each grad program
  131. // $gradPrograms = Program::where('is_graduate','=', 1)
  132. // ->where(function($query)
  133. // {
  134. // if(Auth::user()->school_id)
  135. // {
  136. // $query->where('school_id', Auth::user()->school_id);
  137. // }
  138. // })
  139. // ->with(array('courses'=>function($query)
  140. // {
  141. // $query->whereNotNull('outcomes_attempted');
  142. // }))
  143. // ->orderBy('name', 'asc')->get();
  144. //
  145. // foreach($gradPrograms as $program)
  146. // {
  147. // $gradResults["names"][$program->id]=$program->name;
  148. // $gradResults["schools"][$program->id]=$program->school->name;
  149. //
  150. // $programAssessed=false;
  151. //
  152. // $gradResults["attempted"][$program->id]=0;
  153. // $gradResults["achieved"][$program->id]=0;
  154. //
  155. // foreach($program->courses as $course)
  156. // {
  157. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  158. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  159. //
  160. // $attemptedCriteriaCount=0;
  161. // $achievedCriteriaCount=0;
  162. //
  163. // // If this outcome was evaluated
  164. // if(
  165. // $course_outcomes_attempted
  166. // && array_key_exists($outcome->id, $course_outcomes_attempted)
  167. // && $course_outcomes_attempted[$outcome->id]!=0)
  168. // {
  169. // // Count +1 for attempted and achieved in the program
  170. // $attemptedCriteriaCount+=$course_outcomes_attempted[$outcome->id];
  171. // $achievedCriteriaCount+=$course_outcomes_achieved[$outcome->id];
  172. // $programAssessed=true;
  173. //
  174. // if($attemptedCriteriaCount>0 &&(float)$achievedCriteriaCount/$attemptedCriteriaCount*100 > $outcome->expected_outcome)
  175. // {
  176. // $gradResults["achieved"][$program->id]+=1;
  177. // }
  178. // $gradResults["attempted"][$program->id]+=1;
  179. // }
  180. // }
  181. //
  182. // // Calculate success rate for this program
  183. // if($programAssessed && $gradResults["attempted"][$program->id]>0)
  184. // $gradResults["successRate"][$program->id]= round((float)$gradResults["achieved"][$program->id]/$gradResults["attempted"][$program->id]*100, 2).'%';
  185. // else
  186. // $gradResults["successRate"][$program->id]= 'N/M';
  187. // }
  188. //
  189. // $title = "Outcome Results: ".$outcome->name;
  190. //
  191. // return View::make('local.managers.admins.learning-outcome', compact('title', 'outcome', 'undergradResults', 'gradResults'));
  192. // }
  193. // TODO: Clean up and verify relationships are correct
  194. public function newShow($id)
  195. {
  196. // DB::disableQueryLog();
  197. // $outcome = null;
  198. if ($id === 'all') {
  199. $outcome = Outcome::with('objectives.criteria')->get();
  200. $title = 'All Outcomes';
  201. $criteria = $outcome->reduce(function ($carry, $outcome) {
  202. return $carry->merge($outcome->criteria);
  203. }, Collection::make([]));
  204. $report_link = URL::action('OutcomesController@newReportAll');
  205. } else {
  206. $outcome = Outcome::with(['objectives.criteria'])->find($id);
  207. $title = $outcome->name;
  208. $criteria = $outcome->criteria->load('rubrics');
  209. $report_link = URL::action('OutcomesController@newReport', ['id' => $outcome->id]);
  210. }
  211. // $objectives = $outcome->objectives;
  212. // var_dump(get_class_methods($criteria));
  213. // var_dump($criteria);
  214. $rubrics = $criteria->reduce(function ($carry, $crit) {
  215. return $carry->merge($crit->rubrics);
  216. }, Collection::make([]))->load('activities');
  217. $activities = $rubrics->reduce(function ($carry, $rubric) {
  218. return $carry->merge($rubric->activities);
  219. }, Collection::make([]));
  220. $courses = $activities->reduce(function ($carry, $activity) {
  221. if ($activity->course !== null) {
  222. $carry->push($activity->course);
  223. }
  224. return $carry;
  225. }, Collection::make([]));
  226. $activities = $activities->filter(function ($activity) {
  227. return ($activity->course === null);
  228. });
  229. // var_dump(DB::getQueryLog());
  230. return View::make('local.managers.admins.new-learning-outcome', compact('title', 'outcome', 'courses', 'activities', 'report_link'));
  231. }
  232. public function newReport($id)
  233. {
  234. $outcome = Outcome::find($id);
  235. $objectives = $outcome->objectives;
  236. $criteria = $outcome->criteria;
  237. $programs = $objectives->map(function ($objective) {
  238. return $objective->program;
  239. })
  240. ->merge($criteria->map(function ($criteria) {
  241. return $criteria->program;
  242. }))
  243. ->filter(function ($program) {
  244. return $program->users->contains(Auth::user());
  245. });
  246. $title = $outcome->name . ' Report';
  247. return View::make('local.managers.admins.new-report', compact('title', 'outcome', 'objectives'));
  248. }
  249. public function newReportAll()
  250. {
  251. $outcomes = Outcome::with('objectives')->get();
  252. $title = 'All Outcomes Report';
  253. return View::make('local.managers.admins.new-report-all', compact('title', 'outcomes'));
  254. }
  255. public function update()
  256. {
  257. $outcomeArray = json_decode(Input::get('outcomeArray'), true);
  258. Session::flash('status', 'success');
  259. Session::flash('message', 'Learning Outcomes updated.');
  260. foreach ($outcomeArray as $outcomeObject) {
  261. $validator = Validator::make(
  262. array(
  263. 'name' => $outcomeObject['name'],
  264. 'definition' => $outcomeObject['definition'],
  265. 'expected_outcome' => $outcomeObject['expected_outcome']
  266. ),
  267. array(
  268. 'name' => 'required',
  269. 'definition' => 'required',
  270. 'expected_outcome' => 'required|numeric'
  271. )
  272. );
  273. if (!$validator->fails()) {
  274. try {
  275. $outcome = Outcome::withTrashed()
  276. ->where('id', '=', $outcomeObject['id'])
  277. ->firstOrFail();
  278. $outcome->name = $outcomeObject['name'];
  279. $outcome->definition = $outcomeObject['definition'];
  280. $outcome->expected_outcome = $outcomeObject['expected_outcome'];
  281. $outcome->save();
  282. // If delete is 1, and outcome isn't already trashed, delete
  283. if ($outcomeObject['delete'] == 1 && !$outcome->trashed())
  284. $outcome->delete();
  285. // If delete is 0, and outcome is already trashed, restore
  286. elseif ($outcomeObject['delete'] == 0 && $outcome->trashed())
  287. $outcome->restore();
  288. } catch (Exception $e) {
  289. Session::flash('message', $e->getMessage());
  290. }
  291. } else {
  292. /** Prepare error message */
  293. $message = 'Error(s) updating the Learning Outcomes: <ul>';
  294. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  295. $message .= $validationError;
  296. }
  297. $message .= '</ul>';
  298. /** Send error message and old data */
  299. Session::flash('status', 'danger');
  300. Session::flash('message', $message);
  301. return;
  302. }
  303. }
  304. return;
  305. }
  306. /**
  307. *Copy of update(), but also updates activation_date, deactivation_date and level
  308. */
  309. public function updateMore()
  310. {
  311. $outcomeArray = json_decode(Input::get('outcomeArray'), true);
  312. Session::flash('status', 'success');
  313. Session::flash('message', 'Learning Outcomes updated.');
  314. foreach ($outcomeArray as $outcomeObject) {
  315. $validator = Validator::make(
  316. array(
  317. 'name' => $outcomeObject['name'],
  318. 'definition' => $outcomeObject['definition'],
  319. 'expected_outcome' => $outcomeObject['expected_outcome']
  320. // TODO- validar los otros 3 valores
  321. ),
  322. array(
  323. 'name' => 'required',
  324. 'definition' => 'required',
  325. 'expected_outcome' => 'required|numeric'
  326. // TODO- los requisitos de los otros 3 valores
  327. )
  328. );
  329. if (!$validator->fails()) {
  330. try {
  331. $outcome = Outcome::withTrashed()
  332. ->where('id', '=', $outcomeObject['id'])
  333. ->firstOrFail();
  334. $outcome->name = $outcomeObject['name'];
  335. $outcome->definition = $outcomeObject['definition'];
  336. $outcome->expected_outcome = $outcomeObject['expected_outcome'];
  337. $outcome->activation_date = $outcomeObject['activation_date'];
  338. $outcome->deactivation_date = $outcomeObject['deactivation_date'];
  339. $outcome->level = $outcomeObject['level'];
  340. $outcome->save();
  341. // If delete is 1, and outcome isn't already trashed, delete
  342. if ($outcomeObject['delete'] == 1 && !$outcome->trashed())
  343. $outcome->delete();
  344. // If delete is 0, and outcome is already trashed, restore
  345. elseif ($outcomeObject['delete'] == 0 && $outcome->trashed())
  346. $outcome->restore();
  347. } catch (Exception $e) {
  348. Session::flash('message', $e->getMessage());
  349. }
  350. } else {
  351. /** Prepare error message */
  352. $message = 'Error(s) updating the Learning Outcomes: <ul>';
  353. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  354. $message .= $validationError;
  355. }
  356. $message .= '</ul>';
  357. /** Send error message and old data */
  358. Session::flash('status', 'danger');
  359. Session::flash('message', $message);
  360. return;
  361. }
  362. }
  363. return;
  364. }
  365. public function fetchCriteria()
  366. {
  367. if (Input::get('filter')) {
  368. switch (Input::get('filter')) {
  369. case 'all':
  370. return Outcome::find(Input::get('id'))->criteria;
  371. break;
  372. case 'school':
  373. // If scoord
  374. if (Auth::user()->role == '2') {
  375. // Fetch all the programs whose school is the user's
  376. $program_ids = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
  377. // Return all criteria belonging to any of those programs
  378. return Criterion::where('outcome_id', Input::get('id'))
  379. ->whereIn('program_id', $program_ids)
  380. ->orderBy('name', 'ASC')
  381. ->get();
  382. }
  383. // If pcoord
  384. else {
  385. // Fetch all the programs from the user's school;
  386. $program_ids = DB::table('programs')->where('school_id', Auth::user()->programs[0]->school->id)->lists('id');
  387. return Criterion::where('outcome_id', Input::get('id'))
  388. ->whereIn('program_id', $program_ids)
  389. ->orderBy('name', 'ASC')
  390. ->get();
  391. }
  392. break;
  393. case 'program':
  394. return Criterion::where('outcome_id', Input::get('id'))
  395. ->whereIn('program_id', Auth::user()->programs->lists('id'))
  396. ->orderBy('name', 'ASC')
  397. ->get();
  398. break;
  399. default:
  400. return Outcome::find(Input::get('id'))->criteria;
  401. break;
  402. }
  403. } else {
  404. return Outcome::find(Input::get('id'))->criteria;
  405. }
  406. }
  407. /**
  408. * Create a new learning outcome.
  409. */
  410. public function create()
  411. {
  412. /** Validation rules */
  413. $validator = Validator::make(
  414. array(
  415. 'name' => Input::get('name'),
  416. 'definition' => Input::get('definition')
  417. ),
  418. array(
  419. 'name' => 'required|unique:outcomes',
  420. 'definition' => 'required|min:10'
  421. )
  422. );
  423. /** If validation fails */
  424. if ($validator->fails()) {
  425. /** Prepare error message */
  426. $message = '<p>Error(s) creating a new Learning Outcome</p><ul>';
  427. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  428. $message .= $validationError;
  429. }
  430. $message .= '</ul>';
  431. /** Send error message and old data */
  432. Session::flash('status', 'warning');
  433. Session::flash('message', $message);
  434. return Redirect::to('learning-outcomes')->withInput();
  435. } else {
  436. /** Instantiate new outcome */
  437. $outcome = new Outcome;
  438. $outcome->name = Input::get('name');
  439. $outcome->definition = Input::get('definition');
  440. /** If outcome is saved, send success message */
  441. if ($outcome->save()) {
  442. Session::flash('status', 'success');
  443. Session::flash('message', '<p>Learning Outcome added.</p>');
  444. return Redirect::to('learning-outcomes');
  445. }
  446. /** If saving fails, send error message and old data */
  447. else {
  448. Session::flash('status', 'warning');
  449. Session::flash('message', '<p>Error adding Learning Outcome. Please try again later.</p>');
  450. return Redirect::to('learning-outcomes')->withInput();
  451. }
  452. }
  453. }
  454. public function fetchOutcome()
  455. {
  456. // original code using models
  457. // TODO: models have to be updated because of the database update
  458. $id = Input::get('id');
  459. $outcome_info = DB::table('outcomes')
  460. ->where('outcomes.id', $id)
  461. ->get();
  462. $outcome = $outcome_info[0];
  463. $diferent_levels = DB::table('criterion_objective_outcome')
  464. ->join('new_criteria', 'new_criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  465. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  466. ->where('criterion_objective_outcome.outcome_id', $id)
  467. ->distinct('new_criteria.number_of_scales')
  468. ->select('new_criteria.number_of_scales as levels')
  469. ->orderBy('new_criteria.number_of_scales', 'asc')
  470. ->get();
  471. $criteria_array = array();
  472. $outcome->criteria = array();
  473. foreach ($diferent_levels as $level) {
  474. $level = $level->levels;
  475. // buscar todos los criterios con el level y ponerlos en un array
  476. $outcome_criterias = DB::table('criterion_objective_outcome')
  477. ->join('new_criteria', 'new_criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  478. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  479. ->where('criterion_objective_outcome.outcome_id', $id)
  480. ->where('new_criteria.number_of_scales', $level)
  481. ->whereNull('new_criteria.deleted_at')
  482. ->select('new_criteria.id','new_criteria.name')
  483. ->orderBy('new_criteria.name', 'asc')
  484. ->get();
  485. $outcome_criterias = $outcome_criterias;
  486. foreach ($outcome_criterias as $criteria_id) {
  487. $scales =
  488. DB::select(
  489. DB::raw("
  490. SELECT *
  491. FROM (
  492. SELECT new_criteria.id as criterion_id,
  493. ROW_NUMBER() OVER(PARTITION BY scales.id) rn,
  494. scales.position,
  495. scales.title, scales.description,
  496. criterion_objective_outcome.outcome_id,criterion_objective_outcome.objective_id,
  497. criterion_scale.scale_id
  498. FROM new_criteria,criterion_scale,scales, criterion_objective_outcome, objectives
  499. where new_criteria.id=criterion_scale.criterion_id
  500. and scales.id = criterion_scale.scale_id
  501. and new_criteria.id = criterion_objective_outcome.criterion_id
  502. and objectives.id = criterion_objective_outcome.objective_id
  503. and criterion_objective_outcome.outcome_id = $id
  504. and new_criteria.id = $criteria_id->id
  505. ORDER BY new_criteria.name ASC) a
  506. WHERE rn = 1
  507. ORDER BY `a`.`position` ASC
  508. ")
  509. );
  510. // insertar la informacion de los criterios con N niveles en el arreglo de arreglos
  511. $criteria_id->scales = $scales;
  512. // $i++;
  513. }//ends foreach criteria_id
  514. array_push($outcome->criteria, array($outcome_criterias,'amount_of_levels'=>$level));
  515. }//ends foreach level
  516. return array
  517. (
  518. 'outcome' => $outcome,
  519. );
  520. }
  521. public function managerAssessmentReports()
  522. {
  523. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  524. switch (Auth::user()->role) {
  525. case 1:
  526. $title = "Campus Assessment Reports";
  527. return View::make('local.managers.admins.assessment_reports', compact('title', 'outcomes'));
  528. break;
  529. case 2:
  530. $title = "School Assessment Reports";
  531. return View::make('local.managers.sCoords.assessment_reports', compact('title', 'outcomes'));
  532. break;
  533. case 3:
  534. $title = "Program Assessment Reports";
  535. $programs = Auth::user()->programs;
  536. return View::make('local.managers.pCoords.assessment_reports', compact('title', 'outcomes', 'programs'));
  537. break;
  538. default:
  539. App::abort('404');
  540. break;
  541. }
  542. }
  543. /**
  544. * Campus Assessment Reports
  545. */
  546. public function assessmentReport($outcome_id)
  547. {
  548. $outcome = Outcome::find($outcome_id);
  549. if (!$outcome)
  550. App::abort('404');
  551. $title = "Assessment Report: " . $outcome->name;
  552. $schools = School::has('courses')
  553. ->with(array('programs' => function ($query) use ($outcome_id) {
  554. $query
  555. ->has('courses')
  556. ->with(array('courses' => function ($query2) use ($outcome_id) {
  557. $query2
  558. ->has('activities')
  559. ->whereNotNull('outcomes_attempted')
  560. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  561. ->whereIn('semester_id', Session::get('semesters_ids'))
  562. ->groupBy(array('code', 'number'));
  563. }));
  564. }))
  565. ->get();
  566. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  567. }
  568. // TODO: Change later
  569. public function newAssessmentReport($outcome_id)
  570. {
  571. $outcome = Outcome::find($outcome_id);
  572. if (!$outcome)
  573. App::abort('404');
  574. $title = "Assessment Report: " . $outcome->name;
  575. $schools = School::has('courses')
  576. ->with(array('programs' => function ($query) use ($outcome_id) {
  577. $query
  578. ->has('courses')
  579. ->with(array('courses' => function ($query2) use ($outcome_id) {
  580. $query2
  581. ->has('activities')
  582. ->whereNotNull('outcomes_attempted')
  583. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  584. ->whereIn('semester_id', Session::get('semesters_ids'))
  585. ->groupBy(array('code', 'number'));
  586. }));
  587. }))
  588. ->get();
  589. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  590. }
  591. /**
  592. * School Assessment Reports
  593. */
  594. public function schoolAssessmentReport($outcome_id)
  595. {
  596. $outcome = Outcome::find($outcome_id);
  597. if (!$outcome)
  598. App::abort('404');
  599. $title = "Assessment Report: " . $outcome->name;
  600. $school = School::where('id', Auth::user()->school_id)
  601. ->has('courses')
  602. ->with(array('programs' => function ($query) {
  603. $query
  604. ->has('courses')
  605. ->with(array('courses' => function ($query2) {
  606. $query2
  607. ->has('activities')
  608. ->whereNotNull('outcomes_attempted')
  609. ->whereIn('semester_id', Session::get('semesters_ids'))
  610. ->groupBy(array('code', 'number'));
  611. }));
  612. }))
  613. ->first();
  614. return View::make('local.managers.sCoords.assessment_report', compact('title', 'outcome', 'school'));
  615. }
  616. /**
  617. * Program Assessment Reports
  618. */
  619. public function programAssessmentReport($outcome_id, $program_id)
  620. {
  621. $outcome = Outcome::find($outcome_id);
  622. if (!$outcome)
  623. App::abort('404');
  624. $title = "Assessment Report: " . $outcome->name;
  625. $program = Program::where('id', $program_id)
  626. ->has('courses')
  627. ->with(array('courses' => function ($query) {
  628. $query
  629. ->has('activities')
  630. ->whereNotNull('outcomes_attempted')
  631. ->whereIn('semester_id', Session::get('semesters_ids'))
  632. ->groupBy(array('code', 'number'));
  633. }))
  634. ->first();
  635. return View::make('local.managers.pCoords.assessment_report', compact('title', 'outcome', 'program'));
  636. }
  637. public function professorAssessmentReports()
  638. {
  639. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  640. $title = "My Courses' Assessment Reports";
  641. return View::make('local.professors.assessment_reports', compact('title', 'outcomes'));
  642. }
  643. // Report for a single professor with a single learning outcome
  644. public function professorAssessmentReport($outcome_id)
  645. {
  646. $outcome = Outcome::find($outcome_id);
  647. if (!$outcome)
  648. App::abort('404');
  649. $title = "My Courses' Assessment Report: " . $outcome->name;
  650. $courses = Course::where('user_id', Auth::user()->id)
  651. ->has('activities')
  652. ->whereNotNull('outcomes_attempted')
  653. ->whereIn('semester_id', Session::get('semesters_ids'))
  654. ->groupBy(array('code', 'number'))
  655. ->get();
  656. return View::make('local.professors.assessment_report', compact('title', 'outcome', 'courses'));
  657. }
  658. }