Açıklama Yok

OutcomesController.php 51KB

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