Nessuna descrizione

OutcomesController.php 38KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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('outcome_id'))
  370. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  371. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  372. ->where('criteria.max_score', '=', Input::get('maximum'))
  373. ->select('criterion_id as id', 'name')
  374. ->orderBy('name', 'ASC')
  375. ->get();
  376. break;
  377. case 'school':
  378. // If scoord
  379. if (Auth::user()->role == '2') {
  380. // Fetch all the programs whose school is the user's
  381. $program_ids = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
  382. $criteria = DB::table('criteria')
  383. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  384. ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
  385. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  386. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  387. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  388. ->where('criteria.max_score', '=', Input::get('maximum'))
  389. ->whereIn('program_criterion.program_id', $program_ids)
  390. ->select('criterion_id as id', 'name')
  391. ->orderBy('name', 'ASC')
  392. ->get();
  393. // Return all criteria belonging to any of those programs
  394. return $criteria;
  395. }
  396. // If pcoord
  397. else {
  398. // Fetch all the programs from the user's school;
  399. $program_ids = DB::table('programs')->where('school_id', Auth::user()->programs[0]->school->id)->lists('id');
  400. return DB::table('criteria')
  401. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  402. ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
  403. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  404. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  405. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  406. ->where('criteria.max_score', '=', Input::get('maximum'))
  407. ->whereIn('program_criterion.program_id', $program_ids)
  408. ->select('criterion_id as id', 'name')
  409. ->orderBy('name', 'ASC')
  410. ->get();
  411. }
  412. break;
  413. case 'program':
  414. $criteria = DB::table('criteria')
  415. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  416. ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
  417. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  418. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  419. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  420. ->where('criteria.max_score', '=', Input::get('maximum'))
  421. ->whereIn('program_criterion.program_id', Auth::user()->programs->lists('id'))
  422. ->select('criterion_id as id', 'name')
  423. ->orderBy('name', 'ASC')
  424. ->get();
  425. return $criteria;
  426. break;
  427. default:
  428. return DB::table('criteria')
  429. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  430. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  431. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  432. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  433. ->where('criteria.max_score', '=', Input::get('maximum'))
  434. ->select('criterion_id as id', 'name')
  435. ->orderBy('name', 'ASC')
  436. ->get();
  437. break;
  438. }
  439. } else {
  440. return DB::table('criteria')
  441. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  442. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  443. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  444. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  445. ->where('criteria.max_score', '=', Input::get('maximum'))
  446. ->select('criterion_id as id', 'name')
  447. ->orderBy('name', 'ASC')
  448. ->get();
  449. }
  450. }
  451. /**
  452. * Create a new learning outcome.
  453. */
  454. public function create()
  455. {
  456. /** Validation rules */
  457. $validator = Validator::make(
  458. array(
  459. 'name' => Input::get('name'),
  460. 'definition' => Input::get('definition')
  461. ),
  462. array(
  463. 'name' => 'required|unique:outcomes',
  464. 'definition' => 'required|min:10'
  465. )
  466. );
  467. /** If validation fails */
  468. if ($validator->fails()) {
  469. /** Prepare error message */
  470. $message = '<p>Error(s) creating a new Learning Outcome</p><ul>';
  471. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  472. $message .= $validationError;
  473. }
  474. $message .= '</ul>';
  475. /** Send error message and old data */
  476. Session::flash('status', 'warning');
  477. Session::flash('message', $message);
  478. return Redirect::to('learning-outcomes')->withInput();
  479. } else {
  480. /** Instantiate new outcome */
  481. $outcome = new Outcome;
  482. $outcome->name = Input::get('name');
  483. $outcome->definition = Input::get('definition');
  484. /** If outcome is saved, send success message */
  485. if ($outcome->save()) {
  486. Session::flash('status', 'success');
  487. Session::flash('message', '<p>Learning Outcome added.</p>');
  488. return Redirect::to('learning-outcomes');
  489. }
  490. /** If saving fails, send error message and old data */
  491. else {
  492. Session::flash('status', 'warning');
  493. Session::flash('message', '<p>Error adding Learning Outcome. Please try again later.</p>');
  494. return Redirect::to('learning-outcomes')->withInput();
  495. }
  496. }
  497. }
  498. public function fetchOutcome()
  499. {
  500. // original code using models
  501. // TODO: models have to be updated because of the database update
  502. $id = Input::get('id');
  503. $outcome_info = DB::table('outcomes')
  504. ->where('outcomes.id', $id)
  505. ->get();
  506. $outcome = $outcome_info[0];
  507. $diferent_levels = DB::table('criterion_objective_outcome')
  508. ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  509. ->where('criterion_objective_outcome.outcome_id', $id)
  510. ->distinct('criteria.num_scales')
  511. ->select('criteria.num_scales as levels')
  512. ->orderBy('criteria.num_scales', 'asc')
  513. ->get();
  514. $criteria_array = array();
  515. // switch para el query, dependiendo del usuario
  516. $role = Auth::user()['role'];
  517. switch ($role) {
  518. case 1:
  519. $program_ids = DB::table('programs')->lists('id');
  520. break;
  521. case 2:
  522. $school_id = Auth::user()['school_id'];
  523. $program_ids = DB::table('programs')->where('school_id', $school_id)->lists('id');
  524. break;
  525. case 3:
  526. $program_ids = DB::table('program_user')->where('user_id', Auth::user()['id'])->lists('program_id');
  527. break;
  528. }
  529. $outcome->criteria = array();
  530. foreach ($diferent_levels as $level) {
  531. $level = $level->levels;
  532. // buscar todos los criterios con el level y ponerlos en un array
  533. // $outcome_criterias = DB::table('criterion_objective_outcome')
  534. // ->join('new_criteria', 'new_criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  535. // ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  536. // ->where('criterion_objective_outcome.outcome_id', $id)
  537. // ->where('new_criteria.number_of_scales', $level)
  538. // ->whereNull('new_criteria.deleted_at')
  539. // ->select('new_criteria.id', 'new_criteria.name')
  540. // ->orderBy('new_criteria.name', 'asc')
  541. // ->get();
  542. $outcome_criterias = DB::table('criterion_objective_outcome')
  543. ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  544. ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
  545. ->whereIn('program_criterion.program_id', $program_ids)
  546. ->where('criterion_objective_outcome.outcome_id', $id)
  547. ->where('criteria.num_scales', $level)
  548. ->select('criteria.id', 'criteria.name', 'criteria.deleted_at')
  549. ->orderBy('criteria.name', 'asc')
  550. ->get();
  551. // $outcome_criterias = $outcome_criterias;
  552. foreach ($outcome_criterias as $criteria_id) {
  553. $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");
  554. $programs = DB::table('programs')
  555. ->join('program_criterion', 'program_criterion.program_id', '=', 'programs.id')
  556. ->where('criterion_id', $criteria_id->id)
  557. ->lists('programs.name');
  558. Log::info($scales);
  559. /* $scales =
  560. DB::select(
  561. DB::raw("
  562. SELECT *
  563. FROM (
  564. SELECT criteria.id as criterion_id,
  565. ROW_NUMBER() OVER(PARTITION BY scales.id) rn,
  566. scales.position,
  567. scales.title, scales.description,
  568. criterion_objective_outcome.outcome_id,criterion_objective_outcome.objective_id,
  569. criterion_scale.scale_id
  570. FROM criteria,criterion_scale,scales, criterion_objective_outcome, objectives
  571. where criteria.id=criterion_scale.criterion_id
  572. and scales.id = criterion_scale.scale_id
  573. and criteria.id = criterion_objective_outcome.criterion_id
  574. and objectives.id = criterion_objective_outcome.objective_id
  575. and criterion_objective_outcome.outcome_id = $id
  576. and criteria.id = $criteria_id->id
  577. ORDER BY criteria.name ASC) a
  578. WHERE rn = 1
  579. ORDER BY `a`.`position` ASC
  580. ")
  581. );*/
  582. $criteria_id->programs = $programs;
  583. // insertar la informacion de los criterios con N niveles en el arreglo de arreglos
  584. $criteria_id->scales = $scales;
  585. // $i++;
  586. } //ends foreach criteria_id
  587. array_push($outcome->criteria, array($outcome_criterias, 'amount_of_levels' => $level));
  588. } //ends foreach level
  589. return array(
  590. 'outcome' => $outcome,
  591. );
  592. }
  593. public function managerAssessmentReports()
  594. {
  595. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  596. switch (Auth::user()->role) {
  597. case 1:
  598. $title = "Campus Assessment Reports";
  599. return View::make('local.managers.admins.assessment_reports', compact('title', 'outcomes'));
  600. break;
  601. case 2:
  602. $title = "School Assessment Reports";
  603. return View::make('local.managers.sCoords.assessment_reports', compact('title', 'outcomes'));
  604. break;
  605. case 3:
  606. $title = "Program Assessment Reports";
  607. $programs = Auth::user()->programs;
  608. return View::make('local.managers.pCoords.assessment_reports', compact('title', 'outcomes', 'programs'));
  609. break;
  610. default:
  611. App::abort('404');
  612. break;
  613. }
  614. }
  615. /**
  616. * Campus Assessment Reports
  617. */
  618. public function assessmentReport($outcome_id)
  619. {
  620. $outcome = Outcome::find($outcome_id);
  621. if (!$outcome)
  622. App::abort('404');
  623. $title = "Assessment Report: " . $outcome->name;
  624. $schools = School::has('courses')
  625. ->with(array('programs' => function ($query) use ($outcome_id) {
  626. $query
  627. ->has('courses')
  628. ->with(array('courses' => function ($query2) use ($outcome_id) {
  629. $query2
  630. ->has('activities')
  631. ->whereNotNull('outcomes_attempted')
  632. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  633. ->whereIn('semester_id', Session::get('semesters_ids'))
  634. ->groupBy(array('code', 'number'));
  635. }));
  636. }))
  637. ->get();
  638. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  639. }
  640. // TODO: Change later
  641. public function newAssessmentReport($outcome_id)
  642. {
  643. $outcome = Outcome::find($outcome_id);
  644. if (!$outcome)
  645. App::abort('404');
  646. $title = "Assessment Report: " . $outcome->name;
  647. $schools = School::has('courses')
  648. ->with(array('programs' => function ($query) use ($outcome_id) {
  649. $query
  650. ->has('courses')
  651. ->with(array('courses' => function ($query2) use ($outcome_id) {
  652. $query2
  653. ->has('activities')
  654. ->whereNotNull('outcomes_attempted')
  655. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  656. ->whereIn('semester_id', Session::get('semesters_ids'))
  657. ->groupBy(array('code', 'number'));
  658. }));
  659. }))
  660. ->get();
  661. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  662. }
  663. /**
  664. * School Assessment Reports
  665. */
  666. public function schoolAssessmentReport($outcome_id)
  667. {
  668. $outcome = Outcome::find($outcome_id);
  669. if (!$outcome)
  670. App::abort('404');
  671. $title = "Assessment Report: " . $outcome->name;
  672. $school = School::where('id', Auth::user()->school_id)
  673. ->has('courses')
  674. ->with(array('programs' => function ($query) {
  675. $query
  676. ->has('courses')
  677. ->with(array('courses' => function ($query2) {
  678. $query2
  679. ->has('activities')
  680. //->whereNotNull('outcomes_attempted')
  681. ->join('activities', 'activities.course_id', '=', 'courses.id')
  682. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  683. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  684. ->where('activities.draft', 0)
  685. ->select('courses.*')->distinct()
  686. ->whereIn('semester_id', Session::get('semesters_ids'))
  687. ->groupBy(array('code', 'number'));
  688. }));
  689. }))
  690. ->first();
  691. return View::make('local.managers.sCoords.assessment_report', compact('title', 'outcome', 'school'));
  692. }
  693. /**
  694. * Program Assessment Reports
  695. */
  696. public function programAssessmentReport($outcome_id, $program_id)
  697. {
  698. $outcome = Outcome::find($outcome_id);
  699. if (!$outcome)
  700. App::abort('404');
  701. $title = "Assessment Report: " . $outcome->name;
  702. $program = Program::where('id', $program_id)
  703. ->has('courses')
  704. ->with(array('courses' => function ($query) {
  705. $query
  706. ->has('activities')
  707. //->whereNotNull('outcomes_attempted')
  708. ->whereIn('semester_id', Session::get('semesters_ids'))
  709. ->groupBy(array('code', 'number'));
  710. }))
  711. ->first();
  712. Log::info($program);
  713. return View::make('local.managers.pCoords.assessment_report', compact('title', 'outcome', 'program'));
  714. }
  715. public function professorAssessmentReports()
  716. {
  717. $semesters = Session::get('semesters_ids');
  718. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  719. Log::info($semesters->start);
  720. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  721. ->whereNull('deleted_at')
  722. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  723. ->orderBy('name', 'ASC')->get();
  724. Log::info($outcomes);
  725. $title = "My Courses' Assessment Reports";
  726. return View::make('local.professors.assessment_reports', compact('title', 'outcomes'));
  727. }
  728. // Report for a single professor with a single learning outcome
  729. public function professorAssessmentReport($outcome_id)
  730. {
  731. $outcome = Outcome::find($outcome_id);
  732. if (!$outcome)
  733. App::abort('404');
  734. $title = "My Courses' Assessment Report: " . $outcome->name;
  735. $activity_criterion = DB::table('assessments')->lists('activity_criterion_id');
  736. $courses = DB::table("courses")
  737. ->join('activities', 'activities.course_id', '=', 'courses.id')
  738. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  739. ->whereIn('activity_criterion.id', $activity_criterion)
  740. ->where('courses.user_id', '=', Auth::user()->id)
  741. ->where('activities.draft', '=', 0)
  742. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  743. ->groupBy(array('code', 'number'))
  744. ->get();
  745. /*$courses = Course::has('activites')
  746. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  747. ->where('user_id', Auth::user()->id)
  748. ->where('activities.draft', '=', 0)
  749. ->whereIn('semester_id', Semester::get('semester_ids'))
  750. ->whereIn('activity_criterion.id', $activity_criterion)
  751. ->groupBy(array('code', 'number'))
  752. ->get();*/
  753. /*$courses = Course::where('user_id', Auth::user()->id)
  754. ->has('activities')
  755. //->whereNotNull('outcomes_attempted')
  756. ->whereIn('semester_id', Session::get('semesters_ids'))
  757. ->groupBy(array('code', 'number'))
  758. ->get();*/
  759. return View::make('local.professors.assessment_report', compact('title', 'outcome', 'courses'));
  760. }
  761. }