Няма описание

OutcomesController.php 51KB

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