Aucune description

OutcomesController.php 51KB

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