설명 없음

OutcomesController.php 33KB

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