Aucune description

OutcomesController.php 48KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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. $criteria = 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. foreach ($criteria as $criterion) {
  377. $criterion->program_ids = json_encode(DB::table('program_criterion')
  378. ->where('criterion_id', $criterion->id)
  379. ->lists('program_id'));
  380. $criterion->objectives = DB::table('criterion_objective_outcome')
  381. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  382. ->where('criterion_id', $criterion->id)
  383. ->select('objectives.*')
  384. ->distinct()
  385. ->lists('text');
  386. }
  387. return $criteria;
  388. break;
  389. case 'school':
  390. // If scoord
  391. if (Auth::user()->role == '2') {
  392. // Fetch all the programs whose school is the user's
  393. $program_ids = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
  394. $criteria = 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('outcome_id'))
  398. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  399. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  400. ->where('criteria.max_score', '=', Input::get('maximum'))
  401. ->whereIn('program_criterion.program_id', $program_ids)
  402. ->select('criterion_id as id', 'name')
  403. ->orderBy('name', 'ASC')
  404. ->get();
  405. foreach ($criteria as $criterion) {
  406. $criterion->program_ids = json_encode(DB::table('program_criterion')
  407. ->where('criterion_id', $criterion->id)
  408. ->lists('program_id'));
  409. $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
  410. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  411. ->where('criterion_id', $criterion->id)
  412. ->select('objectives.*')
  413. ->distinct()
  414. ->lists('text'));
  415. }
  416. // Return all criteria belonging to any of those programs
  417. return $criteria;
  418. }
  419. // If pcoord
  420. else {
  421. // Fetch all the programs from the user's school;
  422. // Fetch all the programs from the user's school;
  423. $program_ids = DB::table('programs')->where('school_id', Auth::user()->programs[0]->school->id)->lists('id');
  424. $criteria = DB::table('criteria')
  425. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  426. ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
  427. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  428. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  429. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  430. ->where('criteria.max_score', '=', Input::get('maximum'))
  431. ->whereIn('program_criterion.program_id', $program_ids)
  432. ->select('criterion_id as id', 'name')
  433. ->orderBy('name', 'ASC')
  434. ->get();
  435. foreach ($criteria as $criterion) {
  436. $criterion->program_ids = json_encode(DB::table('program_criterion')
  437. ->where('criterion_id', $criterion->id)
  438. ->lists('program_id'));
  439. $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
  440. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  441. ->where('criterion_id', $criterion->id)
  442. ->select('objectives.*')
  443. ->distinct()
  444. ->lists('text'));
  445. }
  446. return $criteria;
  447. }
  448. break;
  449. case 'program':
  450. $criteria = DB::table('criteria')
  451. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  452. ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
  453. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  454. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  455. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  456. ->where('criteria.max_score', '=', Input::get('maximum'))
  457. ->whereIn('program_criterion.program_id', Auth::user()->programs->lists('id'))
  458. ->select('criterion_id as id', 'name')
  459. ->orderBy('name', 'ASC')
  460. ->get();
  461. foreach ($criteria as $criterion) {
  462. $criterion->program_ids = json_encode(DB::table('program_criterion')
  463. ->where('criterion_id', $criterion->id)
  464. ->lists('program_id'));
  465. $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
  466. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  467. ->where('criterion_id', $criterion->id)
  468. ->select('objectives.*')
  469. ->distinct()
  470. ->lists('text'));
  471. }
  472. return $criteria;
  473. break;
  474. default:
  475. $criteria = DB::table('criteria')
  476. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  477. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  478. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  479. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  480. ->where('criteria.max_score', '=', Input::get('maximum'))
  481. ->select('criterion_id as id', 'name')
  482. ->orderBy('name', 'ASC')
  483. ->get();
  484. foreach ($criteria as $criterion) {
  485. $criterion->program_ids = json_encode(DB::table('program_criterion')
  486. ->where('criterion_id', $criterion->id)
  487. ->lists('program_id'));
  488. $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
  489. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  490. ->where('criterion_id', $criterion->id)
  491. ->select('objectives.*')
  492. ->distinct()
  493. ->lists('text'));
  494. }
  495. return $criteria;
  496. break;
  497. }
  498. } else {
  499. $criteria = DB::table('criteria')
  500. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  501. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  502. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  503. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  504. ->where('criteria.max_score', '=', Input::get('maximum'))
  505. ->select('criterion_id as id', 'name')
  506. ->orderBy('name', 'ASC')
  507. ->get();
  508. foreach ($criteria as $criterion) {
  509. $criterion->program_ids = json_encode(DB::table('program_criterion')
  510. ->where('criterion_id', $criterion->id)
  511. ->lists('program_id'));
  512. $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
  513. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  514. ->where('criterion_id', $criterion->id)
  515. ->select('objectives.*')
  516. ->distinct()
  517. ->lists('text'));
  518. }
  519. return $criteria;
  520. }
  521. }
  522. /**
  523. * Create a new learning outcome.
  524. */
  525. public function create()
  526. {
  527. /** Validation rules */
  528. $validator = Validator::make(
  529. array(
  530. 'name' => Input::get('name'),
  531. 'definition' => Input::get('definition')
  532. ),
  533. array(
  534. 'name' => 'required|unique:outcomes',
  535. 'definition' => 'required|min:10'
  536. )
  537. );
  538. /** If validation fails */
  539. if ($validator->fails()) {
  540. /** Prepare error message */
  541. $message = '<p>Error(s) creating a new Learning Outcome</p><ul>';
  542. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  543. $message .= $validationError;
  544. }
  545. $message .= '</ul>';
  546. /** Send error message and old data */
  547. Session::flash('status', 'warning');
  548. Session::flash('message', $message);
  549. return Redirect::to('learning-outcomes')->withInput();
  550. } else {
  551. /** Instantiate new outcome */
  552. $outcome = new Outcome;
  553. $outcome->name = Input::get('name');
  554. $outcome->definition = Input::get('definition');
  555. /** If outcome is saved, send success message */
  556. if ($outcome->save()) {
  557. Session::flash('status', 'success');
  558. Session::flash('message', '<p>Learning Outcome added.</p>');
  559. return Redirect::to('learning-outcomes');
  560. }
  561. /** If saving fails, send error message and old data */
  562. else {
  563. Session::flash('status', 'warning');
  564. Session::flash('message', '<p>Error adding Learning Outcome. Please try again later.</p>');
  565. return Redirect::to('learning-outcomes')->withInput();
  566. }
  567. }
  568. }
  569. public function fetchOutcome()
  570. {
  571. // original code using models
  572. // TODO: models have to be updated because of the database update
  573. $id = Input::get('id');
  574. $outcome_info = DB::table('outcomes')
  575. ->where('outcomes.id', $id)
  576. ->get();
  577. $outcome = $outcome_info[0];
  578. $diferent_levels = DB::table('criterion_objective_outcome')
  579. ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  580. ->where('criterion_objective_outcome.outcome_id', $id)
  581. ->distinct('criteria.num_scales')
  582. ->select('criteria.num_scales as levels')
  583. ->orderBy('criteria.num_scales', 'asc')
  584. ->get();
  585. $criteria_array = array();
  586. // switch para el query, dependiendo del usuario
  587. $role = Auth::user()['role'];
  588. $semesters = Session::get('sesemster_ids');
  589. switch ($role) {
  590. case 1:
  591. $program_ids = DB::table('programs')->lists('id');
  592. break;
  593. case 2:
  594. $school_id = Auth::user()['school_id'];
  595. $program_ids = DB::table('programs')->where('school_id', $school_id)->lists('id');
  596. break;
  597. case 3:
  598. $program_ids = DB::table('program_user')->where('user_id', Auth::user()['id'])->lists('program_id');
  599. break;
  600. case 4:
  601. $program_ids = DB::table('program_user')->where('user_id', Auth::user()['id'])->lists('program_id');
  602. break;
  603. }
  604. $outcome->criteria = array();
  605. foreach ($diferent_levels as $level) {
  606. $level = $level->levels;
  607. // buscar todos los criterios con el level y ponerlos en un array
  608. // $outcome_criterias = DB::table('criterion_objective_outcome')
  609. // ->join('new_criteria', 'new_criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  610. // ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  611. // ->where('criterion_objective_outcome.outcome_id', $id)
  612. // ->where('new_criteria.number_of_scales', $level)
  613. // ->whereNull('new_criteria.deleted_at')
  614. // ->select('new_criteria.id', 'new_criteria.name')
  615. // ->orderBy('new_criteria.name', 'asc')
  616. // ->get();
  617. $outcome_criterias = DB::table('criterion_objective_outcome')
  618. ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  619. ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
  620. ->whereIn('program_criterion.program_id', $program_ids)
  621. ->where('criterion_objective_outcome.outcome_id', $id)
  622. ->where('criteria.num_scales', $level)
  623. ->select('criteria.id', 'criteria.name', 'criteria.deleted_at')
  624. ->distinct()
  625. ->orderBy('criteria.name', 'asc')
  626. ->get();
  627. // $outcome_criterias = $outcome_criterias;
  628. foreach ($outcome_criterias as $criteria_id) {
  629. $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");
  630. $programs = DB::table('programs')
  631. ->join('program_criterion', 'program_criterion.program_id', '=', 'programs.id')
  632. ->where('criterion_id', $criteria_id->id)
  633. ->lists('programs.name');
  634. Log::info($scales);
  635. /* $scales =
  636. DB::select(
  637. DB::raw("
  638. SELECT *
  639. FROM (
  640. SELECT criteria.id as criterion_id,
  641. ROW_NUMBER() OVER(PARTITION BY scales.id) rn,
  642. scales.position,
  643. scales.title, scales.description,
  644. criterion_objective_outcome.outcome_id,criterion_objective_outcome.objective_id,
  645. criterion_scale.scale_id
  646. FROM criteria,criterion_scale,scales, criterion_objective_outcome, objectives
  647. where criteria.id=criterion_scale.criterion_id
  648. and scales.id = criterion_scale.scale_id
  649. and criteria.id = criterion_objective_outcome.criterion_id
  650. and objectives.id = criterion_objective_outcome.objective_id
  651. and criterion_objective_outcome.outcome_id = $id
  652. and criteria.id = $criteria_id->id
  653. ORDER BY criteria.name ASC) a
  654. WHERE rn = 1
  655. ORDER BY `a`.`position` ASC
  656. ")
  657. );*/
  658. $criteria_id->programs = $programs;
  659. // insertar la informacion de los criterios con N niveles en el arreglo de arreglos
  660. $criteria_id->scales = $scales;
  661. // $i++;
  662. } //ends foreach criteria_id
  663. array_push($outcome->criteria, array($outcome_criterias, 'amount_of_levels' => $level));
  664. } //ends foreach level
  665. return array(
  666. 'outcome' => $outcome,
  667. );
  668. }
  669. public function managerAssessmentReports()
  670. {
  671. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  672. switch (Auth::user()->role) {
  673. case 1:
  674. $title = "Campus Assessment Reports";
  675. return View::make('local.managers.admins.assessment_reports', compact('title', 'outcomes'));
  676. break;
  677. case 2:
  678. $title = "School Assessment Reports";
  679. return View::make('local.managers.sCoords.assessment_reports', compact('title', 'outcomes'));
  680. break;
  681. case 3:
  682. $title = "Program Assessment Reports";
  683. $programs = Auth::user()->programs;
  684. return View::make('local.managers.pCoords.assessment_reports', compact('title', 'outcomes', 'programs'));
  685. break;
  686. default:
  687. App::abort('404');
  688. break;
  689. }
  690. }
  691. /**
  692. * Campus Assessment Reports
  693. */
  694. public function assessmentReport($outcome_id)
  695. {
  696. $outcome = Outcome::find($outcome_id);
  697. if (!$outcome)
  698. App::abort('404');
  699. $title = "Assessment Report: " . $outcome->name;
  700. $schools = School::has('courses')
  701. ->with(array('programs' => function ($query) use ($outcome_id) {
  702. $query
  703. ->has('courses')
  704. ->with(array('courses' => function ($query2) use ($outcome_id) {
  705. $query2
  706. ->has('activities')
  707. // ->whereNotNull('outcomes_attempted')
  708. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  709. ->whereIn('semester_id', Session::get('semesters_ids'))
  710. ->groupBy(array('code', 'number'));
  711. }));
  712. }))
  713. ->get();
  714. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  715. }
  716. public function totalAssessmentReport()
  717. {
  718. //SELECT sm.name, s.name, p.name, p.code, a.outcomes_attempted, stu.number, ass.scores, c.code, c.number, r.expected_points
  719. // FROM students stu, schools s, programs p, courses c, activities a, assessments ass, rubrics r, semesters sm
  720. // where stu.id=ass.student_id and sm.id=c.semester_id and s.id=p.school_id and p.id=c.program_id and a.course_id=c.id and ass.activity_id=a.id and a.rubric_id=r.id
  721. // and c.semester_id in (12,13) and a.outcomes_attempted is not null
  722. ini_set('memory_limit', -1);
  723. ini_set('max_execution_time', 300);
  724. // $total_assessments_temp = DB::table('assessments')
  725. // ->join('students', 'students.id', '=', 'assessments.student_id')
  726. // ->join('activities', 'activities.id', '=', 'assessments.activity_id')
  727. // ->join('rubrics', 'rubrics.id', '=', 'activities.rubric_id')
  728. // ->join('courses', 'courses.id', '=', 'activities.course_id')
  729. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  730. // ->join('schools', 'schools.id', '=', 'programs.school_id')
  731. // ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  732. // ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  733. // ->whereRaw('activities.outcomes_attempted is not null')
  734. // ->select('activities.id as activity_id','semesters.name as semester','schools.name as school','programs.name as program','programs.id as program_id','programs.code as program_code','students.number as student_number','students.conc_code as student_conc_code','assessments.scores as results','courses.name as course','courses.code as course_code','courses.number as course_number','rubrics.expected_points as expected_result')
  735. // ->orderBy('semesters.id','school','program','course','student_number')
  736. // ->distinct()
  737. // ->get();
  738. //
  739. // $total_assessments=array();
  740. // foreach($total_assessments_temp as $total_assessment)
  741. // {
  742. // $results=json_decode($total_assessment->results, TRUE);
  743. // $total_assessment->course=$total_assessment->course_code.$total_assessment->course_number." ".$total_assessment->course;
  744. // foreach($results as $criterion_id => $result)
  745. // {
  746. // if($result and $result!="N/A")
  747. // {
  748. // $trans_temp=clone $total_assessment;
  749. // $criterion=Criterion::find($criterion_id);
  750. // if($criterion)
  751. // {
  752. // // var_dump($total_assessment->activity_id);
  753. // // var_dump($criterion_id);
  754. // if($criterion_id==1398)var_dump($criterion);
  755. // // exit();
  756. // $trans_temp->result=$result;
  757. // $trans_temp->criterion=$criterion->name;
  758. // $trans_temp->outcome=Outcome::find($criterion->outcome_id)->name;
  759. // $total_assessments[]=$trans_temp;
  760. // }
  761. // }
  762. // }
  763. //
  764. // }
  765. $total_assessments = DB::table('assessments')
  766. ->join('students', 'students.id', '=', 'assessments.student_id')
  767. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  768. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  769. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  770. ->join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  771. ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  772. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  773. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  774. ->join('courses', 'courses.id', '=', 'activities.course_id')
  775. ->join('programs', 'programs.id', '=', 'courses.program_id')
  776. ->join('schools', 'schools.id', '=', 'programs.school_id')
  777. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  778. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  779. ->select('criteria.name as criterion', 'outcomes.name as outcome', 'activities.id as activity_id', 'semesters.name as semester', 'schools.name as school', 'programs.name as program', 'programs.id as program_id', 'programs.code as program_code', 'students.number as student_number', 'students.conc_code as student_conc_code', 'assessments.score as result', 'courses.name as course', 'courses.code as course_code', 'courses.number as course_number', 'rubrics.expected_points as expected_result')
  780. ->orderBy('semesters.id', 'school', 'program', 'course', 'student_number')
  781. ->distinct()
  782. ->get();
  783. $title = "Total Assessment Report";
  784. return View::make('local.managers.admins.total_assessment', compact('title', 'total_assessments'));
  785. }
  786. // TODO: Change later
  787. public function newAssessmentReport($outcome_id)
  788. {
  789. $outcome = Outcome::find($outcome_id);
  790. if (!$outcome)
  791. App::abort('404');
  792. $title = "Assessment Report: " . $outcome->name;
  793. $schools = School::has('courses')
  794. ->with(array('programs' => function ($query) use ($outcome_id) {
  795. $query
  796. ->has('courses')
  797. ->with(array('courses' => function ($query2) use ($outcome_id) {
  798. $query2
  799. ->has('activities')
  800. // ->whereNotNull('outcomes_attempted')
  801. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  802. ->join('activities', 'activities.course_id', '=', 'courses.id')
  803. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  804. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  805. ->where('activities.draft', 0)
  806. ->select('courses.*')->distinct()
  807. ->whereIn('semester_id', Session::get('semesters_ids'))
  808. ->groupBy(array('code', 'number'));
  809. }));
  810. }))
  811. ->get();
  812. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  813. }
  814. /**
  815. * School Assessment Reports
  816. */
  817. public function schoolAssessmentReport($outcome_id)
  818. {
  819. $outcome = Outcome::find($outcome_id);
  820. if (!$outcome)
  821. App::abort('404');
  822. $title = "Assessment Report: " . $outcome->name;
  823. $school = School::where('id', Auth::user()->school_id)
  824. ->has('courses')
  825. ->with(array('programs' => function ($query) {
  826. $query
  827. ->has('courses')
  828. ->with(array('courses' => function ($query2) {
  829. $query2
  830. ->has('activities')
  831. //->whereNotNull('outcomes_attempted')
  832. ->join('activities', 'activities.course_id', '=', 'courses.id')
  833. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  834. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  835. ->where('activities.draft', 0)
  836. ->select('courses.*')->distinct()
  837. ->whereIn('semester_id', Session::get('semesters_ids'))
  838. ->groupBy(array('code', 'number'));
  839. }));
  840. }))
  841. ->first();
  842. return View::make('local.managers.sCoords.assessment_report', compact('title', 'outcome', 'school'));
  843. }
  844. /**
  845. * Program Assessment Reports
  846. */
  847. public function programAssessmentReport($outcome_id, $program_id)
  848. {
  849. $outcome = Outcome::find($outcome_id);
  850. if (!$outcome)
  851. App::abort('404');
  852. $title = "Assessment Report: " . $outcome->name;
  853. $program = Program::where('id', $program_id)
  854. ->has('courses')
  855. ->with(array('courses' => function ($query) {
  856. $query
  857. ->has('activities')
  858. //->whereNotNull('outcomes_attempted')
  859. ->whereIn('semester_id', Session::get('semesters_ids'))
  860. ->groupBy(array('code', 'number'));
  861. }))
  862. ->first();
  863. Log::info($program);
  864. return View::make('local.managers.pCoords.assessment_report', compact('title', 'outcome', 'program'));
  865. }
  866. public function professorAssessmentReports()
  867. {
  868. $semesters = Session::get('semesters_ids');
  869. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  870. Log::info($semesters->start);
  871. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  872. ->whereNull('deleted_at')
  873. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  874. ->orderBy('name', 'ASC')->get();
  875. Log::info($outcomes);
  876. $title = "My Courses' Assessment Reports";
  877. return View::make('local.professors.assessment_reports', compact('title', 'outcomes'));
  878. }
  879. // Report for a single professor with a single learning outcome
  880. public function professorAssessmentReport($outcome_id)
  881. {
  882. $outcome = Outcome::find($outcome_id);
  883. if (!$outcome)
  884. App::abort('404');
  885. $title = "My Courses' Assessment Report: " . $outcome->name;
  886. $activity_criterion = DB::table('assessments')->lists('activity_criterion_id');
  887. $courses = DB::table("courses")
  888. ->join('activities', 'activities.course_id', '=', 'courses.id')
  889. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  890. ->whereIn('activity_criterion.id', $activity_criterion)
  891. ->where('courses.user_id', '=', Auth::user()->id)
  892. ->where('activities.draft', '=', 0)
  893. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  894. ->groupBy(array('code', 'number'))
  895. ->get();
  896. /*$courses = Course::has('activites')
  897. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  898. ->where('user_id', Auth::user()->id)
  899. ->where('activities.draft', '=', 0)
  900. ->whereIn('semester_id', Semester::get('semester_ids'))
  901. ->whereIn('activity_criterion.id', $activity_criterion)
  902. ->groupBy(array('code', 'number'))
  903. ->get();*/
  904. /*$courses = Course::where('user_id', Auth::user()->id)
  905. ->has('activities')
  906. //->whereNotNull('outcomes_attempted')
  907. ->whereIn('semester_id', Session::get('semesters_ids'))
  908. ->groupBy(array('code', 'number'))
  909. ->get();*/
  910. return View::make('local.professors.assessment_report', compact('title', 'outcome', 'courses'));
  911. }
  912. }