Без опису

OutcomesController.php 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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. ->where('criterion_objective_outcome.outcome_id', $id)
  492. ->distinct('criteria.num_scales')
  493. ->select('criteria.num_scales as levels')
  494. ->orderBy('criteria.num_scales', 'asc')
  495. ->get();
  496. $criteria_array = array();
  497. // switch para el query, dependiendo del usuario
  498. $role = Auth::user()['role'];
  499. switch ($role) {
  500. case 1:
  501. $program_ids = DB::table('programs')->lists('id');
  502. break;
  503. case 2:
  504. $school_id = Auth::user()['school_id'];
  505. $program_ids = DB::table('programs')->where('school_id', $school_id)->lists('id');
  506. break;
  507. case 3:
  508. $program_ids = DB::table('program_user')->where('user_id', Auth::user()['id'])->lists('program_id');
  509. break;
  510. }
  511. $outcome->criteria = array();
  512. foreach ($diferent_levels as $level) {
  513. $level = $level->levels;
  514. // buscar todos los criterios con el level y ponerlos en un array
  515. // $outcome_criterias = DB::table('criterion_objective_outcome')
  516. // ->join('new_criteria', 'new_criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  517. // ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  518. // ->where('criterion_objective_outcome.outcome_id', $id)
  519. // ->where('new_criteria.number_of_scales', $level)
  520. // ->whereNull('new_criteria.deleted_at')
  521. // ->select('new_criteria.id', 'new_criteria.name')
  522. // ->orderBy('new_criteria.name', 'asc')
  523. // ->get();
  524. $outcome_criterias = DB::table('criterion_objective_outcome')
  525. ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  526. ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
  527. ->whereIn('program_criterion.program_id', $program_ids)
  528. ->where('criterion_objective_outcome.outcome_id', $id)
  529. ->where('criteria.num_scales', $level)
  530. ->select('criteria.id', 'criteria.name', 'criteria.deleted_at')
  531. ->orderBy('criteria.name', 'asc')
  532. ->get();
  533. // $outcome_criterias = $outcome_criterias;
  534. foreach ($outcome_criterias as $criteria_id) {
  535. $scales = DB::select("select * FROM scales INNER join `criterion_scale` on `criterion_scale`.`scale_id` = `scales`.`id` where criterion_scale.criterion_id ={$criteria_id->id} ORDER BY position");
  536. $programs = DB::table('programs')
  537. ->join('program_criterion', 'program_criterion.program_id', '=', 'programs.id')
  538. ->where('criterion_id', $criteria_id->id)
  539. ->lists('programs.name');
  540. Log::info($scales);
  541. /* $scales =
  542. DB::select(
  543. DB::raw("
  544. SELECT *
  545. FROM (
  546. SELECT criteria.id as criterion_id,
  547. ROW_NUMBER() OVER(PARTITION BY scales.id) rn,
  548. scales.position,
  549. scales.title, scales.description,
  550. criterion_objective_outcome.outcome_id,criterion_objective_outcome.objective_id,
  551. criterion_scale.scale_id
  552. FROM criteria,criterion_scale,scales, criterion_objective_outcome, objectives
  553. where criteria.id=criterion_scale.criterion_id
  554. and scales.id = criterion_scale.scale_id
  555. and criteria.id = criterion_objective_outcome.criterion_id
  556. and objectives.id = criterion_objective_outcome.objective_id
  557. and criterion_objective_outcome.outcome_id = $id
  558. and criteria.id = $criteria_id->id
  559. ORDER BY criteria.name ASC) a
  560. WHERE rn = 1
  561. ORDER BY `a`.`position` ASC
  562. ")
  563. );*/
  564. $criteria_id->programs = $programs;
  565. // insertar la informacion de los criterios con N niveles en el arreglo de arreglos
  566. $criteria_id->scales = $scales;
  567. // $i++;
  568. } //ends foreach criteria_id
  569. array_push($outcome->criteria, array($outcome_criterias, 'amount_of_levels' => $level));
  570. } //ends foreach level
  571. return array(
  572. 'outcome' => $outcome,
  573. );
  574. }
  575. public function managerAssessmentReports()
  576. {
  577. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  578. switch (Auth::user()->role) {
  579. case 1:
  580. $title = "Campus Assessment Reports";
  581. return View::make('local.managers.admins.assessment_reports', compact('title', 'outcomes'));
  582. break;
  583. case 2:
  584. $title = "School Assessment Reports";
  585. return View::make('local.managers.sCoords.assessment_reports', compact('title', 'outcomes'));
  586. break;
  587. case 3:
  588. $title = "Program Assessment Reports";
  589. $programs = Auth::user()->programs;
  590. return View::make('local.managers.pCoords.assessment_reports', compact('title', 'outcomes', 'programs'));
  591. break;
  592. default:
  593. App::abort('404');
  594. break;
  595. }
  596. }
  597. /**
  598. * Campus Assessment Reports
  599. */
  600. public function assessmentReport($outcome_id)
  601. {
  602. $outcome = Outcome::find($outcome_id);
  603. if (!$outcome)
  604. App::abort('404');
  605. $title = "Assessment Report: " . $outcome->name;
  606. $schools = School::has('courses')
  607. ->with(array('programs' => function ($query) use ($outcome_id) {
  608. $query
  609. ->has('courses')
  610. ->with(array('courses' => function ($query2) use ($outcome_id) {
  611. $query2
  612. ->has('activities')
  613. ->whereNotNull('outcomes_attempted')
  614. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  615. ->whereIn('semester_id', Session::get('semesters_ids'))
  616. ->groupBy(array('code', 'number'));
  617. }));
  618. }))
  619. ->get();
  620. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  621. }
  622. // TODO: Change later
  623. public function newAssessmentReport($outcome_id)
  624. {
  625. $outcome = Outcome::find($outcome_id);
  626. if (!$outcome)
  627. App::abort('404');
  628. $title = "Assessment Report: " . $outcome->name;
  629. $schools = School::has('courses')
  630. ->with(array('programs' => function ($query) use ($outcome_id) {
  631. $query
  632. ->has('courses')
  633. ->with(array('courses' => function ($query2) use ($outcome_id) {
  634. $query2
  635. ->has('activities')
  636. ->whereNotNull('outcomes_attempted')
  637. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  638. ->whereIn('semester_id', Session::get('semesters_ids'))
  639. ->groupBy(array('code', 'number'));
  640. }));
  641. }))
  642. ->get();
  643. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  644. }
  645. /**
  646. * School Assessment Reports
  647. */
  648. public function schoolAssessmentReport($outcome_id)
  649. {
  650. $outcome = Outcome::find($outcome_id);
  651. if (!$outcome)
  652. App::abort('404');
  653. $title = "Assessment Report: " . $outcome->name;
  654. $school = School::where('id', Auth::user()->school_id)
  655. ->has('courses')
  656. ->with(array('programs' => function ($query) {
  657. $query
  658. ->has('courses')
  659. ->with(array('courses' => function ($query2) {
  660. $query2
  661. ->has('activities')
  662. ->whereNotNull('outcomes_attempted')
  663. ->whereIn('semester_id', Session::get('semesters_ids'))
  664. ->groupBy(array('code', 'number'));
  665. }));
  666. }))
  667. ->first();
  668. return View::make('local.managers.sCoords.assessment_report', compact('title', 'outcome', 'school'));
  669. }
  670. /**
  671. * Program Assessment Reports
  672. */
  673. public function programAssessmentReport($outcome_id, $program_id)
  674. {
  675. $outcome = Outcome::find($outcome_id);
  676. if (!$outcome)
  677. App::abort('404');
  678. $title = "Assessment Report: " . $outcome->name;
  679. $program = Program::where('id', $program_id)
  680. ->has('courses')
  681. ->with(array('courses' => function ($query) {
  682. $query
  683. ->has('activities')
  684. ->whereNotNull('outcomes_attempted')
  685. ->whereIn('semester_id', Session::get('semesters_ids'))
  686. ->groupBy(array('code', 'number'));
  687. }))
  688. ->first();
  689. return View::make('local.managers.pCoords.assessment_report', compact('title', 'outcome', 'program'));
  690. }
  691. public function professorAssessmentReports()
  692. {
  693. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  694. $title = "My Courses' Assessment Reports";
  695. return View::make('local.professors.assessment_reports', compact('title', 'outcomes'));
  696. }
  697. // Report for a single professor with a single learning outcome
  698. public function professorAssessmentReport($outcome_id)
  699. {
  700. $outcome = Outcome::find($outcome_id);
  701. if (!$outcome)
  702. App::abort('404');
  703. $title = "My Courses' Assessment Report: " . $outcome->name;
  704. $activity_criterion = DB::table('assessments')->lists('activity_criterion_id');
  705. $courses = DB::table("courses")
  706. ->join('activities', 'activities.course_id', '=', 'courses.id')
  707. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  708. ->whereIn('activity_criterion.id', $activity_criterion)
  709. ->where('courses.user_id', '=', Auth::user()->id)
  710. ->where('activities.draft', '=', 0)
  711. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  712. ->groupBy(array('code', 'number'))
  713. ->get();
  714. /*$courses = Course::has('activites')
  715. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  716. ->where('user_id', Auth::user()->id)
  717. ->where('activities.draft', '=', 0)
  718. ->whereIn('semester_id', Semester::get('semester_ids'))
  719. ->whereIn('activity_criterion.id', $activity_criterion)
  720. ->groupBy(array('code', 'number'))
  721. ->get();*/
  722. /*$courses = Course::where('user_id', Auth::user()->id)
  723. ->has('activities')
  724. //->whereNotNull('outcomes_attempted')
  725. ->whereIn('semester_id', Session::get('semesters_ids'))
  726. ->groupBy(array('code', 'number'))
  727. ->get();*/
  728. return View::make('local.professors.assessment_report', compact('title', 'outcome', 'courses'));
  729. }
  730. }