No Description

OutcomesController.php 51KB

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