설명 없음

OutcomesController.php 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  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. $diferent_levels = DB::table('criterion_objective_outcome')
  584. ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  585. ->where('criterion_objective_outcome.outcome_id', $id)
  586. ->distinct('criteria.num_scales')
  587. ->select('criteria.num_scales as levels')
  588. ->orderBy('criteria.num_scales', 'asc')
  589. ->get();
  590. $criteria_array = array();
  591. // switch para el query, dependiendo del usuario
  592. $role = Auth::user()['role'];
  593. $semesters = Session::get('sesemster_ids');
  594. switch ($role) {
  595. case 1:
  596. $program_ids = DB::table('programs')->lists('id');
  597. break;
  598. case 2:
  599. $school_id = Auth::user()['school_id'];
  600. $program_ids = DB::table('programs')->where('school_id', $school_id)->lists('id');
  601. break;
  602. case 3:
  603. $program_ids = DB::table('program_user')->where('user_id', Auth::user()['id'])->lists('program_id');
  604. break;
  605. case 4:
  606. $program_ids = DB::table('program_user')->where('user_id', Auth::user()['id'])->lists('program_id');
  607. break;
  608. }
  609. $outcome->criteria = array();
  610. foreach ($diferent_levels as $level) {
  611. $level = $level->levels;
  612. // buscar todos los criterios con el level y ponerlos en un array
  613. // $outcome_criterias = DB::table('criterion_objective_outcome')
  614. // ->join('new_criteria', 'new_criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  615. // ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  616. // ->where('criterion_objective_outcome.outcome_id', $id)
  617. // ->where('new_criteria.number_of_scales', $level)
  618. // ->whereNull('new_criteria.deleted_at')
  619. // ->select('new_criteria.id', 'new_criteria.name')
  620. // ->orderBy('new_criteria.name', 'asc')
  621. // ->get();
  622. $outcome_criterias = DB::table('criterion_objective_outcome')
  623. ->join('criteria', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  624. ->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
  625. ->whereIn('program_criterion.program_id', $program_ids)
  626. ->where('criterion_objective_outcome.outcome_id', $id)
  627. ->where('criteria.num_scales', $level)
  628. ->select('criteria.id', 'criteria.name', 'criteria.deleted_at')
  629. ->distinct()
  630. ->orderBy('criteria.name', 'asc')
  631. ->get();
  632. // $outcome_criterias = $outcome_criterias;
  633. foreach ($outcome_criterias as $criteria_id) {
  634. $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");
  635. $programs = DB::table('programs')
  636. ->join('program_criterion', 'program_criterion.program_id', '=', 'programs.id')
  637. ->where('criterion_id', $criteria_id->id)
  638. ->lists('programs.name');
  639. Log::info($scales);
  640. /* $scales =
  641. DB::select(
  642. DB::raw("
  643. SELECT *
  644. FROM (
  645. SELECT criteria.id as criterion_id,
  646. ROW_NUMBER() OVER(PARTITION BY scales.id) rn,
  647. scales.position,
  648. scales.title, scales.description,
  649. criterion_objective_outcome.outcome_id,criterion_objective_outcome.objective_id,
  650. criterion_scale.scale_id
  651. FROM criteria,criterion_scale,scales, criterion_objective_outcome, objectives
  652. where criteria.id=criterion_scale.criterion_id
  653. and scales.id = criterion_scale.scale_id
  654. and criteria.id = criterion_objective_outcome.criterion_id
  655. and objectives.id = criterion_objective_outcome.objective_id
  656. and criterion_objective_outcome.outcome_id = $id
  657. and criteria.id = $criteria_id->id
  658. ORDER BY criteria.name ASC) a
  659. WHERE rn = 1
  660. ORDER BY `a`.`position` ASC
  661. ")
  662. );*/
  663. $criteria_id->programs = $programs;
  664. // insertar la informacion de los criterios con N niveles en el arreglo de arreglos
  665. $criteria_id->scales = $scales;
  666. // $i++;
  667. } //ends foreach criteria_id
  668. array_push($outcome->criteria, array($outcome_criterias, 'amount_of_levels' => $level));
  669. } //ends foreach level
  670. return array(
  671. 'outcome' => $outcome,
  672. );
  673. }
  674. public function managerAssessmentReports()
  675. {
  676. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))->orderBy('name', 'ASC')->get();
  677. switch (Auth::user()->role) {
  678. case 1:
  679. $title = "Campus Assessment Reports";
  680. return View::make('local.managers.admins.assessment_reports', compact('title', 'outcomes'));
  681. break;
  682. case 2:
  683. $title = "School Assessment Reports";
  684. return View::make('local.managers.sCoords.assessment_reports', compact('title', 'outcomes'));
  685. break;
  686. case 3:
  687. $title = "Program Assessment Reports";
  688. $programs = Auth::user()->programs;
  689. return View::make('local.managers.pCoords.assessment_reports', compact('title', 'outcomes', 'programs'));
  690. break;
  691. default:
  692. App::abort('404');
  693. break;
  694. }
  695. }
  696. /**
  697. * Campus Assessment Reports
  698. */
  699. public function assessmentReport()
  700. {
  701. //$outcome = Outcome::find($outcome_id);
  702. set_time_limit(0);
  703. //if (!$outcome)
  704. // App::abort('404');
  705. $title = "Campus Assessment Report "; //. $outcome->name;
  706. $schools = School::has('courses')
  707. ->with(array('programs' => function ($query) /*use ($outcome_id)*/ {
  708. $query
  709. ->has('courses')
  710. ->with(array('courses' => function ($query2) /*use ($outcome_id)*/ {
  711. $query2
  712. /*->has('activities')
  713. // ->whereNotNull('outcomes_attempted')
  714. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  715. ->whereIn('semester_id', Session::get('semesters_ids'))
  716. ->groupBy(array('code', 'number'));*/
  717. ->has('activities')
  718. ->join('activities', 'activities.course_id', '=', 'courses.id')
  719. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  720. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  721. ->where('activities.draft', 0)
  722. ->where('activities.diagnostic', 0)
  723. ->select('courses.*')->distinct()
  724. //->whereNotNull('outcomes_attempted')
  725. ->whereIn('semester_id', Session::get('semesters_ids'))
  726. ->groupBy(array('code', 'number'));
  727. }));
  728. }))
  729. ->get();
  730. return View::make('local.managers.admins.new_assessment_report', compact('title', 'schools'));
  731. }
  732. public function totalAssessmentReport()
  733. {
  734. //SELECT sm.name, s.name, p.name, p.code, a.outcomes_attempted, stu.number, ass.scores, c.code, c.number, r.expected_points
  735. // FROM students stu, schools s, programs p, courses c, activities a, assessments ass, rubrics r, semesters sm
  736. // 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
  737. // and c.semester_id in (12,13) and a.outcomes_attempted is not null
  738. ini_set('memory_limit', -1);
  739. ini_set('max_execution_time', 300);
  740. // $total_assessments_temp = DB::table('assessments')
  741. // ->join('students', 'students.id', '=', 'assessments.student_id')
  742. // ->join('activities', 'activities.id', '=', 'assessments.activity_id')
  743. // ->join('rubrics', 'rubrics.id', '=', 'activities.rubric_id')
  744. // ->join('courses', 'courses.id', '=', 'activities.course_id')
  745. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  746. // ->join('schools', 'schools.id', '=', 'programs.school_id')
  747. // ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  748. // ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  749. // ->whereRaw('activities.outcomes_attempted is not null')
  750. // ->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')
  751. // ->orderBy('semesters.id','school','program','course','student_number')
  752. // ->distinct()
  753. // ->get();
  754. //
  755. // $total_assessments=array();
  756. // foreach($total_assessments_temp as $total_assessment)
  757. // {
  758. // $results=json_decode($total_assessment->results, TRUE);
  759. // $total_assessment->course=$total_assessment->course_code.$total_assessment->course_number." ".$total_assessment->course;
  760. // foreach($results as $criterion_id => $result)
  761. // {
  762. // if($result and $result!="N/A")
  763. // {
  764. // $trans_temp=clone $total_assessment;
  765. // $criterion=Criterion::find($criterion_id);
  766. // if($criterion)
  767. // {
  768. // // var_dump($total_assessment->activity_id);
  769. // // var_dump($criterion_id);
  770. // if($criterion_id==1398)var_dump($criterion);
  771. // // exit();
  772. // $trans_temp->result=$result;
  773. // $trans_temp->criterion=$criterion->name;
  774. // $trans_temp->outcome=Outcome::find($criterion->outcome_id)->name;
  775. // $total_assessments[]=$trans_temp;
  776. // }
  777. // }
  778. // }
  779. //
  780. // }
  781. $total_assessments = DB::table('assessments')
  782. ->join('students', 'students.id', '=', 'assessments.student_id')
  783. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  784. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  785. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  786. ->join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  787. ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  788. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  789. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  790. ->join('courses', 'courses.id', '=', 'activities.course_id')
  791. ->join('programs', 'programs.id', '=', 'courses.program_id')
  792. ->join('schools', 'schools.id', '=', 'programs.school_id')
  793. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  794. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  795. ->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')
  796. ->orderBy('semesters.id', 'school', 'program', 'course', 'student_number')
  797. ->distinct()
  798. ->get();
  799. $title = "Total Assessment Report";
  800. return View::make('local.managers.admins.total_assessment', compact('title', 'total_assessments'));
  801. }
  802. // TODO: Change later
  803. public function newAssessmentReport($outcome_id)
  804. {
  805. $outcome = Outcome::find($outcome_id);
  806. if (!$outcome)
  807. App::abort('404');
  808. $title = "Assessment Report: " . $outcome->name;
  809. $schools = School::has('courses')
  810. ->with(array('programs' => function ($query) use ($outcome_id) {
  811. $query
  812. ->has('courses')
  813. ->with(array('courses' => function ($query2) use ($outcome_id) {
  814. $query2
  815. ->has('activities')
  816. // ->whereNotNull('outcomes_attempted')
  817. // ->where('outcomes_attempted', 'NOT LIKE', '%"'.$outcome_id.'":0%')
  818. ->join('activities', 'activities.course_id', '=', 'courses.id')
  819. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  820. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  821. ->where('activities.draft', 0)
  822. ->where('activities.diagnostic', 0)
  823. ->select('courses.*')->distinct()
  824. ->whereIn('semester_id', Session::get('semesters_ids'))
  825. ->groupBy(array('code', 'number'));
  826. }));
  827. }))
  828. ->get();
  829. return View::make('local.managers.admins.assessment_report', compact('title', 'outcome', 'schools'));
  830. }
  831. /**
  832. * School Assessment Reports
  833. */
  834. private function cmp($a, $b)
  835. {
  836. return strcmp($a->name, $b->name);
  837. }
  838. public function schoolAssessmentReport()
  839. {
  840. //$outcome = Outcome::find($outcome_id);
  841. //if (!$outcome)
  842. // App::abort('404');
  843. $title = "School Assessment Reports";
  844. set_time_limit(0);
  845. $school = School::where('id', Auth::user()->school_id)
  846. ->has('courses')
  847. ->with(array('programs' => function ($query) {
  848. $query
  849. ->has('courses')
  850. ->with(array('courses' => function ($query2) {
  851. $query2
  852. ->has('activities')
  853. ->join('activities', 'activities.course_id', '=', 'courses.id')
  854. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  855. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  856. ->where('activities.draft', 0)
  857. ->where('activities.diagnostic', 0)
  858. ->select('courses.*')->distinct()
  859. //->whereNotNull('outcomes_attempted')
  860. ->whereIn('semester_id', Session::get('semesters_ids'))
  861. ->groupBy(array('code', 'number'));
  862. }));
  863. }))
  864. ->first();
  865. return View::make('local.managers.sCoords.new_assessment_report', compact('title', 'school'));
  866. }
  867. /**
  868. * Program Assessment Reports
  869. */
  870. public function programAssessmentReport($program_id)
  871. {
  872. //$outcome = Outcome::find($outcome_id);
  873. //if (!$outcome)
  874. // App::abort('404');
  875. $title = "Program Courses Report";
  876. set_time_limit(0);
  877. $program = Program::where('id', $program_id)
  878. ->has('courses')
  879. ->with(array('courses' => function ($query) {
  880. $query
  881. ->has('activities')
  882. //->whereNotNull('outcomes_attempted')
  883. ->join('activities', 'activities.course_id', '=', 'courses.id')
  884. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  885. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  886. ->where('activities.draft', 0)
  887. ->where('activities.diagnostic', 0)
  888. ->select('courses.*')->distinct()
  889. ->whereIn('semester_id', Session::get('semesters_ids'))
  890. ->groupBy(array('code', 'number'));
  891. }))
  892. ->first();
  893. Log::info($program);
  894. return View::make('local.managers.pCoords.new_assessment_report', compact('title', 'program'));
  895. }
  896. /*public function professorAssessmentReports()
  897. {
  898. $semesters = Session::get('semesters_ids');
  899. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  900. Log::info($semesters->start);
  901. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  902. ->whereNull('deleted_at')
  903. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  904. ->orderBy('name', 'ASC')->get();
  905. Log::info($outcomes);
  906. $title = "My Courses' Assessment Reports";
  907. return View::make('local.professors.assessment_reports', compact('title', 'outcomes'));
  908. }*/
  909. // Report for a single professor //with a single learning outcome
  910. public function professorAssessmentReport()
  911. {
  912. //$outcome = Outcome::find($outcome_id);
  913. //if (!$outcome)
  914. set_time_limit(0);
  915. // App::abort('404');
  916. $title = "My Courses' Assessment Report";
  917. //$activity_criterion = DB::table('assessments')->lists('activity_criterion_id');
  918. $courses = DB::table("courses")
  919. ->join('activities', 'activities.course_id', '=', 'courses.id')
  920. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  921. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  922. //->whereIn('activity_criterion.id', $activity_criterion)
  923. ->where('courses.user_id', '=', Auth::user()->id)
  924. ->where('activities.draft', '=', 0)
  925. ->where('activities.diagnostic', 0)
  926. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  927. ->groupBy(array('code', 'number'))
  928. ->get();
  929. /*$courses = Course::has('activites')
  930. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  931. ->where('user_id', Auth::user()->id)
  932. ->where('activities.draft', '=', 0)
  933. ->whereIn('semester_id', Semester::get('semester_ids'))
  934. ->whereIn('activity_criterion.id', $activity_criterion)
  935. ->groupBy(array('code', 'number'))
  936. ->get();*/
  937. /*$courses = Course::where('user_id', Auth::user()->id)
  938. ->has('activities')
  939. //->whereNotNull('outcomes_attempted')
  940. ->whereIn('semester_id', Session::get('semesters_ids'))
  941. ->groupBy(array('code', 'number'))
  942. ->get();*/
  943. return View::make('local.professors.new_assessment_report', compact('title', 'courses'));
  944. }
  945. public function annualReport($program_id)
  946. {
  947. $title = "Program Annual Report";
  948. $annual_plans = DB::select("
  949. select
  950. academic_year,
  951. semester_start,
  952. semester_end,
  953. program_id,
  954. annual_plans.id as annual_id,
  955. annual_cycle.*
  956. from annual_plans
  957. join annual_cycle on annual_cycle_id = annual_cycle.id
  958. where program_id = {$program_id}
  959. order by semester_start desc");
  960. $program = DB::table('programs')
  961. ->where('id', $program_id)
  962. ->first();
  963. return View::make('local.managers.shared.annual_report', compact('title', 'program_id', 'annual_plans', 'program'));
  964. }
  965. }