Ei kuvausta

OutcomesController.php 49KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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('id', 'ASC')->get();
  13. // $outcomes = Outcome::withTrashed()->orderBy('name', 'ASC')->get();
  14. $schools = School::orderBy('name', 'ASC')->get();
  15. // $semesters_ids = Session::get('semesters_ids');
  16. // $semesters = Semester::whereIn('id',$semesters_ids)->get();
  17. return View::make('local.managers.admins.learning-outcomes', compact('title', 'outcomes', 'schools'));
  18. //return View::make('local.managers.admins.learning-outcomes', compact('title', 'outcomes', 'schools','semesters'));
  19. }
  20. public function adminProgramIndex()
  21. {
  22. }
  23. // TODO: Change to home page
  24. public function newIndex()
  25. {
  26. $title = "Learning Outcomes";
  27. // TODO: Check when semester doesnt exist or session is empty
  28. $selected_semester = Semester::find(Session::get('semesters_ids')[0]);
  29. $outcomes = Outcome::withTrashed()->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null)->orderBy('name', 'ASC')->get();
  30. $schools = School::orderBy('name', 'ASC')->get();
  31. return View::make('local.managers.admins.new-learning-outcomes', compact('title', 'outcomes', 'schools'));
  32. }
  33. public function show($id)
  34. {
  35. $outcome = Outcome::find($id);
  36. $selected_semesters = Semester::find(Session::get('semesters_ids'));
  37. $programs = $outcome->programs_attempted($selected_semesters);
  38. $undergradResults = array("names" => array(), "schools" => array(), "achieved" => array(), "attempted" => array(), "successRate" => array());
  39. $gradResults = array("names" => array(), "schools" => array(), "achieved" => array(), "attempted" => array(), "successRate" => array());
  40. foreach ($programs as $program_id) {
  41. // var_dump($program_id);
  42. // exit();
  43. $program = Program::where('id', '=', $program_id->id)->first();
  44. $school = School::where('id', '=', $program->school_id)->first();
  45. if ($program->is_graduate) {
  46. $gradResults['names'][] = $program->name;
  47. $gradResults['schools'][] = $school->name;
  48. $attempted = $program->attempted_criteria_by_outcome($id, $selected_semesters);
  49. $gradResults['attempted'][] = $attempted;
  50. $achieved = $program->achieved_criteria_by_outcome($id, $selected_semesters);
  51. $gradResults['achieved'][] = $achieved;
  52. $gradResults['successRate'][] = sprintf("%.2f", 100 * $achieved / $attempted);
  53. } else {
  54. $undergradResults['names'][] = $program->name;
  55. $undergradResults['schools'][] = $school->name;
  56. $attempted = $program->attempted_criteria_by_outcome($id, $selected_semesters);
  57. $undergradResults['attempted'][] = $attempted;
  58. $achieved = $program->achieved_criteria_by_outcome($id, $selected_semesters);
  59. $undergradResults['achieved'][] = $achieved;
  60. $undergradResults['successRate'][] = sprintf("%.2f", 100 * $achieved / $attempted);
  61. }
  62. }
  63. $title = "Outcome Results: " . $outcome->name;
  64. // $undergradResults["successRate"]
  65. return View::make('local.managers.admins.learning-outcome', compact('title', 'outcome', 'undergradResults', 'gradResults'));
  66. }
  67. // public function showOri($id)
  68. // {
  69. // DB::disableQueryLog();
  70. // $outcome = Outcome::find($id);
  71. //
  72. // $undergradResults=array("names"=>array(), "schools"=>array(), "achieved"=>array(), "attempted"=>array(), "successRate"=>array());
  73. // $gradResults = array("names"=>array(), "schools"=>array(), "achieved"=>array(), "attempted"=>array(), "successRate"=>array());
  74. //
  75. // //Calculate performance for this outcome for each undergrad program
  76. // $undergradPrograms = Program::where('is_graduate','=', 0)
  77. // ->where(function($query)
  78. // {
  79. // if(Auth::user()->school_id)
  80. // {
  81. // $query->where('school_id', Auth::user()->school_id);
  82. // }
  83. // })
  84. // ->with('courses')
  85. // ->orderBy('name', 'asc')->get();
  86. //
  87. // foreach($undergradPrograms as $program)
  88. // {
  89. // $undergradResults["names"][$program->id]=$program->name;
  90. // $undergradResults["schools"][$program->id]=$program->school->name;
  91. // $programAssessed=false;
  92. //
  93. // $undergradResults["attempted"][$program->id]=0;
  94. // $undergradResults["achieved"][$program->id]=0;
  95. //
  96. // foreach($program->courses as $course)
  97. // {
  98. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  99. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  100. //
  101. // $attemptedCriteriaCount=0;
  102. // $achievedCriteriaCount=0;
  103. //
  104. // // If this outcome was evaluated
  105. // if(
  106. // $course_outcomes_attempted
  107. // && array_key_exists($outcome->id, $course_outcomes_attempted)
  108. // && $course_outcomes_attempted[$outcome->id]!=0)
  109. // {
  110. // // Count +1 for attempted and achieved in the program
  111. // $attemptedCriteriaCount+=$course_outcomes_attempted[$outcome->id];
  112. // $achievedCriteriaCount+=$course_outcomes_achieved[$outcome->id];
  113. // $programAssessed=true;
  114. //
  115. // if($attemptedCriteriaCount>0 &&(float)$achievedCriteriaCount/$attemptedCriteriaCount*100 > $outcome->expected_outcome)
  116. // {
  117. // $undergradResults["achieved"][$program->id]+=1;
  118. // }
  119. // $undergradResults["attempted"][$program->id]+=1;
  120. // }
  121. // }
  122. //
  123. // // Calculate success rate for this program
  124. // if($programAssessed && $undergradResults["attempted"][$program->id]>0)
  125. // $undergradResults["successRate"][$program->id]= round((float)$undergradResults["achieved"][$program->id]/$undergradResults["attempted"][$program->id]*100, 2).'%';
  126. // else
  127. // $undergradResults["successRate"][$program->id]= 'N/M';
  128. // }
  129. //
  130. //
  131. // //Calculate performance for this outcome for each grad program
  132. // $gradPrograms = Program::where('is_graduate','=', 1)
  133. // ->where(function($query)
  134. // {
  135. // if(Auth::user()->school_id)
  136. // {
  137. // $query->where('school_id', Auth::user()->school_id);
  138. // }
  139. // })
  140. // ->with(array('courses'=>function($query)
  141. // {
  142. // $query->whereNotNull('outcomes_attempted');
  143. // }))
  144. // ->orderBy('name', 'asc')->get();
  145. //
  146. // foreach($gradPrograms as $program)
  147. // {
  148. // $gradResults["names"][$program->id]=$program->name;
  149. // $gradResults["schools"][$program->id]=$program->school->name;
  150. //
  151. // $programAssessed=false;
  152. //
  153. // $gradResults["attempted"][$program->id]=0;
  154. // $gradResults["achieved"][$program->id]=0;
  155. //
  156. // foreach($program->courses as $course)
  157. // {
  158. // $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  159. // $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  160. //
  161. // $attemptedCriteriaCount=0;
  162. // $achievedCriteriaCount=0;
  163. //
  164. // // If this outcome was evaluated
  165. // if(
  166. // $course_outcomes_attempted
  167. // && array_key_exists($outcome->id, $course_outcomes_attempted)
  168. // && $course_outcomes_attempted[$outcome->id]!=0)
  169. // {
  170. // // Count +1 for attempted and achieved in the program
  171. // $attemptedCriteriaCount+=$course_outcomes_attempted[$outcome->id];
  172. // $achievedCriteriaCount+=$course_outcomes_achieved[$outcome->id];
  173. // $programAssessed=true;
  174. //
  175. // if($attemptedCriteriaCount>0 &&(float)$achievedCriteriaCount/$attemptedCriteriaCount*100 > $outcome->expected_outcome)
  176. // {
  177. // $gradResults["achieved"][$program->id]+=1;
  178. // }
  179. // $gradResults["attempted"][$program->id]+=1;
  180. // }
  181. // }
  182. //
  183. // // Calculate success rate for this program
  184. // if($programAssessed && $gradResults["attempted"][$program->id]>0)
  185. // $gradResults["successRate"][$program->id]= round((float)$gradResults["achieved"][$program->id]/$gradResults["attempted"][$program->id]*100, 2).'%';
  186. // else
  187. // $gradResults["successRate"][$program->id]= 'N/M';
  188. // }
  189. //
  190. // $title = "Outcome Results: ".$outcome->name;
  191. //
  192. // return View::make('local.managers.admins.learning-outcome', compact('title', 'outcome', 'undergradResults', 'gradResults'));
  193. // }
  194. // TODO: Clean up and verify relationships are correct
  195. public function newShow($id)
  196. {
  197. // DB::disableQueryLog();
  198. // $outcome = null;
  199. if ($id === 'all') {
  200. $outcome = Outcome::with('objectives.criteria')->get();
  201. $title = 'All Outcomes';
  202. $criteria = $outcome->reduce(function ($carry, $outcome) {
  203. return $carry->merge($outcome->criteria);
  204. }, Collection::make([]));
  205. $report_link = URL::action('OutcomesController@newReportAll');
  206. } else {
  207. $outcome = Outcome::with(['objectives.criteria'])->find($id);
  208. $title = $outcome->name;
  209. $criteria = $outcome->criteria->load('rubrics');
  210. $report_link = URL::action('OutcomesController@newReport', ['id' => $outcome->id]);
  211. }
  212. // $objectives = $outcome->objectives;
  213. // var_dump(get_class_methods($criteria));
  214. // var_dump($criteria);
  215. $rubrics = $criteria->reduce(function ($carry, $crit) {
  216. return $carry->merge($crit->rubrics);
  217. }, Collection::make([]))->load('activities');
  218. $activities = $rubrics->reduce(function ($carry, $rubric) {
  219. return $carry->merge($rubric->activities);
  220. }, Collection::make([]));
  221. $courses = $activities->reduce(function ($carry, $activity) {
  222. if ($activity->course !== null) {
  223. $carry->push($activity->course);
  224. }
  225. return $carry;
  226. }, Collection::make([]));
  227. $activities = $activities->filter(function ($activity) {
  228. return ($activity->course === null);
  229. });
  230. // var_dump(DB::getQueryLog());
  231. return View::make('local.managers.admins.new-learning-outcome', compact('title', 'outcome', 'courses', 'activities', 'report_link'));
  232. }
  233. public function newReport($id)
  234. {
  235. $outcome = Outcome::find($id);
  236. $objectives = $outcome->objectives;
  237. $criteria = $outcome->criteria;
  238. $programs = $objectives->map(function ($objective) {
  239. return $objective->program;
  240. })
  241. ->merge($criteria->map(function ($criteria) {
  242. return $criteria->program;
  243. }))
  244. ->filter(function ($program) {
  245. return $program->users->contains(Auth::user());
  246. });
  247. $title = $outcome->name . ' Report';
  248. return View::make('local.managers.admins.new-report', compact('title', 'outcome', 'objectives'));
  249. }
  250. public function newReportAll()
  251. {
  252. $outcomes = Outcome::with('objectives')->get();
  253. $title = 'All Outcomes Report';
  254. return View::make('local.managers.admins.new-report-all', compact('title', 'outcomes'));
  255. }
  256. public function update()
  257. {
  258. $outcomeArray = json_decode(Input::get('outcomeArray'), true);
  259. Session::flash('status', 'success');
  260. Session::flash('message', 'Learning Outcomes updated.');
  261. foreach ($outcomeArray as $outcomeObject) {
  262. $validator = Validator::make(
  263. array(
  264. 'name' => $outcomeObject['name'],
  265. 'definition' => $outcomeObject['definition'],
  266. 'expected_outcome' => $outcomeObject['expected_outcome']
  267. ),
  268. array(
  269. 'name' => 'required',
  270. 'definition' => 'required',
  271. 'expected_outcome' => 'required|numeric'
  272. )
  273. );
  274. if (!$validator->fails()) {
  275. try {
  276. $outcome = Outcome::withTrashed()
  277. ->where('id', '=', $outcomeObject['id'])
  278. ->firstOrFail();
  279. $outcome->name = $outcomeObject['name'];
  280. $outcome->definition = $outcomeObject['definition'];
  281. $outcome->expected_outcome = $outcomeObject['expected_outcome'];
  282. $outcome->save();
  283. // If delete is 1, and outcome isn't already trashed, delete
  284. if ($outcomeObject['delete'] == 1 && !$outcome->trashed())
  285. $outcome->delete();
  286. // If delete is 0, and outcome is already trashed, restore
  287. elseif ($outcomeObject['delete'] == 0 && $outcome->trashed())
  288. $outcome->restore();
  289. } catch (Exception $e) {
  290. Session::flash('message', $e->getMessage());
  291. }
  292. } else {
  293. /** Prepare error message */
  294. $message = 'Error(s) updating the Learning Outcomes: <ul>';
  295. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  296. $message .= $validationError;
  297. }
  298. $message .= '</ul>';
  299. /** Send error message and old data */
  300. Session::flash('status', 'danger');
  301. Session::flash('message', $message);
  302. return;
  303. }
  304. }
  305. return;
  306. }
  307. /**
  308. *Copy of update(), but also updates activation_date, deactivation_date and level
  309. */
  310. public function delete()
  311. {
  312. $outcomeArray = json_decode(Input::get('outcomeArray'), true);
  313. // Log::info("delete".json_encode($outcomeArray));
  314. $outcome = Outcome::withTrashed()
  315. ->where('id', '=', $outcomeArray['id'])
  316. ->firstOrFail();
  317. // Log::info("delete2".json_encode($outcome));
  318. $outcome->forceDelete();
  319. // Log::info("sal".json_encode($sal));
  320. // if($sal)
  321. {
  322. Session::flash('status', 'success');
  323. Session::flash('message', 'Learning Outcome deleted.');
  324. }
  325. }
  326. public function updateMore()
  327. {
  328. $outcomeArray = json_decode(Input::get('outcomeArray'), true);
  329. Session::flash('status', 'success');
  330. Session::flash('message', 'Learning Outcomes updated.');
  331. Log::info("Ahora1" . json_encode($outcomeArray));
  332. foreach ($outcomeArray as $outcomeObject) {
  333. $validator = Validator::make(
  334. array(
  335. 'name' => $outcomeObject['name'],
  336. 'definition' => $outcomeObject['definition'],
  337. 'expected_outcome' => $outcomeObject['expected_outcome'],
  338. 'activation_date' => $outcomeObject['activation_date'],
  339. // 'deactivation_date' => (isset($outcomeObject['deactivation_date'])?$outcomeObject['deactivation_date']:NULL),
  340. 'level' => $outcomeObject['level'],
  341. // 'new_outcome_id'=>$outcomeObject['new_outcome_id']
  342. // TODO- validar los otros 3 valores
  343. ),
  344. array(
  345. 'name' => 'required',
  346. 'definition' => 'required',
  347. 'expected_outcome' => 'required|numeric',
  348. 'activation_date' => 'required|date',
  349. // 'deactivation_date' => 'sometimes|required|date',
  350. 'level' => 'required|numeric'
  351. // 'new_outcome_id' => 'required|numeric'
  352. // TODO- los requisitos de los otros 3 valores
  353. )
  354. );
  355. if (!$validator->fails()) {
  356. try {
  357. $outcome = Outcome::withTrashed()
  358. ->where('id', '=', $outcomeObject['id'])
  359. ->firstOrFail();
  360. $outcome->name = $outcomeObject['name'];
  361. $outcome->definition = $outcomeObject['definition'];
  362. $outcome->expected_outcome = $outcomeObject['expected_outcome'];
  363. $outcome->activation_date = $outcomeObject['activation_date'];
  364. if ($outcomeObject['deactivation_date'] != "") {
  365. $outcome->deactivation_date = $outcomeObject['deactivation_date'];
  366. if (isset($outcomeObject['new_outcome_id'])) $outcome->new_outcome_id = $outcomeObject['new_outcome_id'];
  367. } else {
  368. $outcome->deactivation_date = NULL;
  369. $outcome->new_outcome_id = NULL;
  370. }
  371. $outcome->level = $outcomeObject['level'];
  372. Log::info("Ahora2" . json_encode($outcome));
  373. $outcome->save();
  374. // If delete is 1, and outcome isn't already trashed, delete
  375. if ($outcomeObject['delete'] == 1 && !$outcome->trashed())
  376. $outcome->delete();
  377. // If delete is 0, and outcome is already trashed, restore
  378. elseif ($outcomeObject['delete'] == 0 && $outcome->trashed())
  379. $outcome->restore();
  380. } catch (Exception $e) {
  381. Session::flash('message', $e->getMessage());
  382. }
  383. } else {
  384. /** Prepare error message */
  385. $message = 'Error(s) updating the Learning Outcomes: <ul>';
  386. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  387. $message .= $validationError;
  388. }
  389. $message .= '</ul>';
  390. /** Send error message and old data */
  391. Session::flash('status', 'danger');
  392. Session::flash('message', $message);
  393. return;
  394. }
  395. }
  396. return;
  397. }
  398. public function fetchCriteria()
  399. {
  400. $criteria_not_available = DB::table('criterion_objective_outcome')
  401. ->where('objective_id', '=', 0)
  402. ->lists('criterion_id');
  403. $criteria = DB::table('criteria')
  404. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id');
  405. if (Input::get('filter')) {
  406. switch (Input::get('filter')) {
  407. case 'all':
  408. /*$criteria = DB::table('criteria')
  409. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  410. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  411. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  412. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  413. ->where('criteria.max_score', '=', Input::get('maximum'))*/
  414. /*foreach ($criteria as $criterion) {
  415. $criterion->program_ids = json_encode(DB::table('program_criterion')
  416. ->where('criterion_id', $criterion->id)
  417. ->lists('program_id'));
  418. $criterion->objectives = DB::table('criterion_objective_outcome')
  419. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  420. ->where('criterion_id', $criterion->id)
  421. ->select('objectives.*')
  422. ->distinct()
  423. ->lists('text');
  424. }
  425. return $criteria;
  426. break;*/
  427. break;
  428. case 'school':
  429. // If scoord
  430. if (Auth::user()->role == '2') {
  431. // Fetch all the programs whose school is the user's
  432. $program_ids = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
  433. } else {
  434. $program_ids = DB::table('programs')->where('school_id', Auth::user()->programs[0]->school->id)->lists('id');
  435. }
  436. $criteria = $criteria
  437. ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
  438. ->whereIn('poco.program_id', $program_ids);
  439. /*
  440. foreach ($criteria as $criterion) {
  441. $criterion->program_ids = json_encode(DB::table('program_criterion')
  442. ->where('criterion_id', $criterion->id)
  443. ->lists('program_id'));
  444. $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
  445. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  446. ->where('criterion_id', $criterion->id)
  447. ->select('objectives.*')
  448. ->distinct()
  449. ->lists('text'));
  450. }
  451. // Return all criteria belonging to any of those programs
  452. return $criteria;*/
  453. break;
  454. case 'program':
  455. $criteria = $criteria
  456. ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
  457. ->whereIn('poco.program_id', Auth::user()->programs->lists('id'));
  458. /*foreach ($criteria as $criterion) {
  459. $criterion->program_ids = json_encode(DB::table('program_criterion')
  460. ->where('criterion_id', $criterion->id)
  461. ->lists('program_id'));
  462. $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
  463. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  464. ->where('criterion_id', $criterion->id)
  465. ->select('objectives.*')
  466. ->distinct()
  467. ->lists('text'));
  468. }
  469. return $criteria;*/
  470. break;
  471. default:
  472. /*foreach ($criteria as $criterion) {
  473. $criterion->program_ids = json_encode(DB::table('program_criterion')
  474. ->where('criterion_id', $criterion->id)
  475. ->lists('program_id'));
  476. $criterion->objectives = json_encode(DB::table('criterion_objective_outcome')
  477. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  478. ->where('criterion_id', $criterion->id)
  479. ->select('objectives.*')
  480. ->distinct()
  481. ->lists('text'));
  482. }
  483. return $criteria;*/
  484. break;
  485. }
  486. }
  487. $criteria = $criteria
  488. ->where('criterion_objective_outcome.outcome_id', '=', Input::get('outcome_id'))
  489. ->where('criterion_objective_outcome.objective_id', '=', Input::get('objective_id'))
  490. ->where('criteria.num_scales', '=', Input::get('num_scales'))
  491. ->where('criteria.max_score', '=', Input::get('maximum'))
  492. ->whereNotIn('criteria.id', $criteria_not_available)
  493. ->select('criterion_id as id', 'name')
  494. ->orderBy('name', 'ASC')
  495. ->get();
  496. return $criteria;
  497. }
  498. /**
  499. * Create a new learning outcome.
  500. */
  501. public function create()
  502. {
  503. /** Validation rules */
  504. $validator = Validator::make(
  505. array(
  506. 'name' => Input::get('name'),
  507. 'definition' => Input::get('definition')
  508. ),
  509. array(
  510. 'name' => 'required|unique:outcomes',
  511. 'definition' => 'required|min:10'
  512. )
  513. );
  514. /** If validation fails */
  515. if ($validator->fails()) {
  516. /** Prepare error message */
  517. $message = '<p>Error(s) creating a new Learning Outcome</p><ul>';
  518. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  519. $message .= $validationError;
  520. }
  521. $message .= '</ul>';
  522. /** Send error message and old data */
  523. Session::flash('status', 'warning');
  524. Session::flash('message', $message);
  525. return Redirect::to('learning-outcomes')->withInput();
  526. } else {
  527. /** Instantiate new outcome */
  528. $outcome = new Outcome;
  529. $outcome->name = Input::get('name');
  530. $outcome->definition = Input::get('definition');
  531. /** If outcome is saved, send success message */
  532. if ($outcome->save()) {
  533. Session::flash('status', 'success');
  534. Session::flash('message', '<p>Learning Outcome added.</p>');
  535. return Redirect::to('learning-outcomes');
  536. }
  537. /** If saving fails, send error message and old data */
  538. else {
  539. Session::flash('status', 'warning');
  540. Session::flash('message', '<p>Error adding Learning Outcome. Please try again later.</p>');
  541. return Redirect::to('learning-outcomes')->withInput();
  542. }
  543. }
  544. }
  545. public function fetchOutcome()
  546. {
  547. // original code using models
  548. // TODO: models have to be updated because of the database update
  549. $id = Input::get('id');
  550. $outcome_info = DB::table('outcomes')
  551. ->where('outcomes.id', $id)
  552. ->get();
  553. $outcome = $outcome_info[0];
  554. $criteria_array = array();
  555. // switch para el query, dependiendo del usuario
  556. $role = Auth::user()['role'];
  557. $semesters = Session::get('sesemster_ids');
  558. switch ($role) {
  559. case 1:
  560. $program_ids = DB::table('programs')->lists('id');
  561. break;
  562. case 2:
  563. $school_id = Auth::user()['school_id'];
  564. $program_ids = DB::table('programs')->where('school_id', $school_id)->lists('id');
  565. break;
  566. case 3:
  567. $program_ids = DB::table('program_user')->where('user_id', Auth::user()['id'])->lists('program_id');
  568. break;
  569. case 4:
  570. $program_ids = DB::table('program_user')->where('user_id', Auth::user()['id'])->lists('program_id');
  571. break;
  572. }
  573. $diferent_levels = DB::table('criterion_objective_outcome')
  574. ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  575. // GASP, añadí programa, para que solo muestre niveles de criterios del programa
  576. ->join('program_criterion_objective_outcome', 'criterion_objective_outcome.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
  577. ->whereIn('program_id', $program_ids)
  578. ->where('criterion_objective_outcome.outcome_id', $id)
  579. ->distinct('criteria.num_scales')
  580. ->select('criteria.num_scales as levels')
  581. ->orderBy('criteria.num_scales', 'asc')
  582. ->get();
  583. $outcome->criteria = array();
  584. foreach ($diferent_levels as $level) {
  585. $level = $level->levels;
  586. // buscar todos los criterios con el level y ponerlos en un array
  587. // $outcome_criterias = DB::table('criterion_objective_outcome')
  588. // ->join('new_criteria', 'new_criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  589. // ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  590. // ->where('criterion_objective_outcome.outcome_id', $id)
  591. // ->where('new_criteria.number_of_scales', $level)
  592. // ->whereNull('new_criteria.deleted_at')
  593. // ->select('new_criteria.id', 'new_criteria.name')
  594. // ->orderBy('new_criteria.name', 'asc')
  595. // ->get();
  596. $outcome_criterias = DB::table('criterion_objective_outcome')
  597. ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  598. ->join('program_criterion_objective_outcome', 'criterion_objective_outcome.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
  599. ->whereIn('program_criterion_objective_outcome.program_id', $program_ids)
  600. ->where('criterion_objective_outcome.outcome_id', $id)
  601. ->where('criteria.num_scales', $level)
  602. ->select('criteria.id', 'criteria.name', 'criteria.deleted_at')
  603. ->distinct()
  604. ->orderBy('criteria.name', 'asc')
  605. ->get();
  606. // $outcome_criterias = $outcome_criterias;
  607. foreach ($outcome_criterias as $criteria_id) {
  608. $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");
  609. $programs = DB::table('programs')
  610. ->join('program_criterion_objective_outcome', 'programs.id', '=', 'program_criterion_objective_outcome.program_id')
  611. ->join('criterion_objective_outcome as cobo', 'cobo.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
  612. //->join('program_criterion', 'program_criterion.program_id', '=', 'programs.id')
  613. ->where('criterion_id', $criteria_id->id)
  614. ->select('programs.*')
  615. ->distinct()
  616. ->lists('programs.name');
  617. // Log::info($scales);
  618. /* $scales =
  619. DB::select(
  620. DB::raw("
  621. SELECT *
  622. FROM (
  623. SELECT criteria.id as criterion_id,
  624. ROW_NUMBER() OVER(PARTITION BY scales.id) rn,
  625. scales.position,
  626. scales.title, scales.description,
  627. criterion_objective_outcome.outcome_id,criterion_objective_outcome.objective_id,
  628. criterion_scale.scale_id
  629. FROM criteria,criterion_scale,scales, criterion_objective_outcome, objectives
  630. where criteria.id=criterion_scale.criterion_id
  631. and scales.id = criterion_scale.scale_id
  632. and criteria.id = criterion_objective_outcome.criterion_id
  633. and objectives.id = criterion_objective_outcome.objective_id
  634. and criterion_objective_outcome.outcome_id = $id
  635. and criteria.id = $criteria_id->id
  636. ORDER BY criteria.name ASC) a
  637. WHERE rn = 1
  638. ORDER BY `a`.`position` ASC
  639. ")
  640. );*/
  641. $criteria_id->programs = $programs;
  642. // insertar la informacion de los criterios con N niveles en el arreglo de arreglos
  643. $criteria_id->scales = $scales;
  644. // $i++;
  645. } //ends foreach criteria_id
  646. array_push($outcome->criteria, array($outcome_criterias, 'amount_of_levels' => $level));
  647. } //ends foreach level
  648. return array(
  649. 'outcome' => $outcome,
  650. );
  651. }
  652. public function managerAssessmentReports()
  653. {
  654. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  655. switch (Auth::user()->role) {
  656. case 1:
  657. $title = "Campus Assessment Reports";
  658. return View::make('local.managers.admins.assessment_reports', compact('title', 'outcomes'));
  659. break;
  660. case 2:
  661. $title = "School Assessment Reports";
  662. return View::make('local.managers.sCoords.assessment_reports', compact('title', 'outcomes'));
  663. break;
  664. case 3:
  665. $title = "Program Assessment Reports";
  666. $programs = Auth::user()->programs;
  667. return View::make('local.managers.pCoords.assessment_reports', compact('title', 'outcomes', 'programs'));
  668. break;
  669. default:
  670. App::abort('404');
  671. break;
  672. }
  673. }
  674. /**
  675. * Campus Assessment Reports
  676. */
  677. public function assessmentReport()
  678. {
  679. //$outcome = Outcome::find($outcome_id);
  680. set_time_limit(0);
  681. //if (!$outcome)
  682. // App::abort('404');
  683. $title = "Campus Assessment Report "; //. $outcome->name;
  684. $schools = School::has('courses')
  685. ->with(array('programs' => function ($query) /*use ($outcome_id)*/ {
  686. $query
  687. ->has('courses')
  688. ->with(array('courses' => function ($query2) /*use ($outcome_id)*/ {
  689. $query2
  690. /*->has('activities')
  691. // ->whereNotNull('outcomes_attempted')
  692. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  693. ->whereIn('semester_id', Session::get('semesters_ids'))
  694. ->groupBy(array('code', 'number'));*/
  695. ->has('activities')
  696. ->join('activities', 'activities.course_id', '=', 'courses.id')
  697. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  698. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  699. ->where('activities.draft', 0)
  700. ->where('activities.diagnostic', 0)
  701. ->select('courses.*')->distinct()
  702. //->whereNotNull('outcomes_attempted')
  703. ->whereIn('semester_id', Session::get('semesters_ids'))
  704. ->groupBy(array('code', 'number'));
  705. }));
  706. }))
  707. ->get();
  708. return View::make('local.managers.admins.new_assessment_report', compact('title', 'schools'));
  709. }
  710. public function totalAssessmentReport()
  711. {
  712. //SELECT sm.name, s.name, p.name, p.code, a.outcomes_attempted, stu.number, ass.scores, c.code, c.number, r.expected_points
  713. // FROM students stu, schools s, programs p, courses c, activities a, assessments ass, rubrics r, semesters sm
  714. // 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
  715. // and c.semester_id in (12,13) and a.outcomes_attempted is not null
  716. ini_set('memory_limit', -1);
  717. ini_set('max_execution_time', 300);
  718. // $total_assessments_temp = DB::table('assessments')
  719. // ->join('students', 'students.id', '=', 'assessments.student_id')
  720. // ->join('activities', 'activities.id', '=', 'assessments.activity_id')
  721. // ->join('rubrics', 'rubrics.id', '=', 'activities.rubric_id')
  722. // ->join('courses', 'courses.id', '=', 'activities.course_id')
  723. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  724. // ->join('schools', 'schools.id', '=', 'programs.school_id')
  725. // ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  726. // ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  727. // ->whereRaw('activities.outcomes_attempted is not null')
  728. // ->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')
  729. // ->orderBy('semesters.id','school','program','course','student_number')
  730. // ->distinct()
  731. // ->get();
  732. //
  733. // $total_assessments=array();
  734. // foreach($total_assessments_temp as $total_assessment)
  735. // {
  736. // $results=json_decode($total_assessment->results, TRUE);
  737. // $total_assessment->course=$total_assessment->course_code.$total_assessment->course_number." ".$total_assessment->course;
  738. // foreach($results as $criterion_id => $result)
  739. // {
  740. // if($result and $result!="N/A")
  741. // {
  742. // $trans_temp=clone $total_assessment;
  743. // $criterion=Criterion::find($criterion_id);
  744. // if($criterion)
  745. // {
  746. // // var_dump($total_assessment->activity_id);
  747. // // var_dump($criterion_id);
  748. // if($criterion_id==1398)var_dump($criterion);
  749. // // exit();
  750. // $trans_temp->result=$result;
  751. // $trans_temp->criterion=$criterion->name;
  752. // $trans_temp->outcome=Outcome::find($criterion->outcome_id)->name;
  753. // $total_assessments[]=$trans_temp;
  754. // }
  755. // }
  756. // }
  757. //
  758. // }
  759. $total_assessments = DB::table('assessments')
  760. ->join('students', 'students.id', '=', 'assessments.student_id')
  761. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  762. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  763. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  764. ->join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  765. ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  766. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  767. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  768. ->join('courses', 'courses.id', '=', 'activities.course_id')
  769. ->join('programs', 'programs.id', '=', 'courses.program_id')
  770. ->join('schools', 'schools.id', '=', 'programs.school_id')
  771. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  772. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  773. ->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')
  774. ->orderBy('semesters.id', 'school', 'program', 'course', 'student_number')
  775. ->distinct()
  776. ->get();
  777. $title = "Total Assessment Report";
  778. return View::make('local.managers.admins.total_assessment', compact('title', 'total_assessments'));
  779. }
  780. // TODO: Change later
  781. public function newAssessmentReport($outcome_id)
  782. {
  783. $outcome = Outcome::find($outcome_id);
  784. if (!$outcome)
  785. App::abort('404');
  786. $title = "Assessment Report: " . $outcome->name;
  787. $schools = School::has('courses')
  788. ->with(array('programs' => function ($query) use ($outcome_id) {
  789. $query
  790. ->has('courses')
  791. ->with(array('courses' => function ($query2) use ($outcome_id) {
  792. $query2
  793. ->has('activities')
  794. // ->whereNotNull('outcomes_attempted')
  795. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  796. ->join('activities', 'activities.course_id', '=', 'courses.id')
  797. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  798. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  799. ->where('activities.draft', 0)
  800. ->where('activities.diagnostic', 0)
  801. ->select('courses.*')->distinct()
  802. ->whereIn('semester_id', Session::get('semesters_ids'))
  803. ->groupBy(array('code', 'number'));
  804. }));
  805. }))
  806. ->get();
  807. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  808. }
  809. /**
  810. * School Assessment Reports
  811. */
  812. private function cmp($a, $b)
  813. {
  814. return strcmp($a->name, $b->name);
  815. }
  816. public function schoolAssessmentReport()
  817. {
  818. //$outcome = Outcome::find($outcome_id);
  819. //if (!$outcome)
  820. // App::abort('404');
  821. $title = "School Assessment Reports";
  822. set_time_limit(0);
  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. ->join('activities', 'activities.course_id', '=', 'courses.id')
  832. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  833. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  834. ->where('activities.draft', 0)
  835. ->where('activities.diagnostic', 0)
  836. ->select('courses.*')->distinct()
  837. //->whereNotNull('outcomes_attempted')
  838. ->whereIn('semester_id', Session::get('semesters_ids'))
  839. ->groupBy(array('code', 'number'));
  840. }));
  841. }))
  842. ->first();
  843. return View::make('local.managers.sCoords.new_assessment_report', compact('title', 'school'));
  844. }
  845. /**
  846. * Program Assessment Reports
  847. */
  848. public function programAssessmentReport($program_id)
  849. {
  850. //$outcome = Outcome::find($outcome_id);
  851. //if (!$outcome)
  852. // App::abort('404');
  853. $title = "Program Courses Report";
  854. set_time_limit(0);
  855. $program = Program::where('id', $program_id)
  856. ->has('courses')
  857. ->with(array('courses' => function ($query) {
  858. $query
  859. ->has('activities')
  860. //->whereNotNull('outcomes_attempted')
  861. ->join('activities', 'activities.course_id', '=', 'courses.id')
  862. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  863. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  864. ->where('activities.draft', 0)
  865. ->where('activities.diagnostic', 0)
  866. ->select('courses.*')->distinct()
  867. ->whereIn('semester_id', Session::get('semesters_ids'))
  868. ->groupBy(array('code', 'number'));
  869. }))
  870. ->first();
  871. Log::info($program);
  872. return View::make('local.managers.pCoords.new_assessment_report', compact('title', 'program'));
  873. }
  874. /*public function professorAssessmentReports()
  875. {
  876. $semesters = Session::get('semesters_ids');
  877. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  878. Log::info($semesters->start);
  879. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  880. ->whereNull('deleted_at')
  881. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  882. ->orderBy('name', 'ASC')->get();
  883. Log::info($outcomes);
  884. $title = "My Courses' Assessment Reports";
  885. return View::make('local.professors.assessment_reports', compact('title', 'outcomes'));
  886. }*/
  887. // Report for a single professor //with a single learning outcome
  888. public function professorAssessmentReport()
  889. {
  890. //$outcome = Outcome::find($outcome_id);
  891. //if (!$outcome)
  892. set_time_limit(0);
  893. // App::abort('404');
  894. $title = "My Courses' Assessment Report";
  895. //$activity_criterion = DB::table('assessments')->lists('activity_criterion_id');
  896. $courses = DB::table("courses")
  897. ->join('activities', 'activities.course_id', '=', 'courses.id')
  898. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  899. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  900. //->whereIn('activity_criterion.id', $activity_criterion)
  901. ->where('courses.user_id', '=', Auth::user()->id)
  902. ->where('activities.draft', '=', 0)
  903. ->where('activities.diagnostic', 0)
  904. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  905. ->groupBy(array('code', 'number'))
  906. ->get();
  907. /*$courses = Course::has('activites')
  908. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  909. ->where('user_id', Auth::user()->id)
  910. ->where('activities.draft', '=', 0)
  911. ->whereIn('semester_id', Semester::get('semester_ids'))
  912. ->whereIn('activity_criterion.id', $activity_criterion)
  913. ->groupBy(array('code', 'number'))
  914. ->get();*/
  915. /*$courses = Course::where('user_id', Auth::user()->id)
  916. ->has('activities')
  917. //->whereNotNull('outcomes_attempted')
  918. ->whereIn('semester_id', Session::get('semesters_ids'))
  919. ->groupBy(array('code', 'number'))
  920. ->get();*/
  921. return View::make('local.professors.new_assessment_report', compact('title', 'courses'));
  922. }
  923. public function annualReport($program_id)
  924. {
  925. $title = "Program Annual Report";
  926. $annual_plans = DB::select("
  927. select
  928. academic_year,
  929. semester_start,
  930. semester_end,
  931. program_id,
  932. annual_plans.id as annual_id,
  933. annual_cycle.*
  934. from annual_plans
  935. join annual_cycle on annual_cycle_id = annual_cycle.id
  936. where program_id = {$program_id}
  937. order by semester_start desc");
  938. $program = DB::table('programs')
  939. ->where('id', $program_id)
  940. ->first();
  941. return View::make('local.managers.shared.annual_report', compact('title', 'program_id', 'annual_plans', 'program'));
  942. }
  943. }