暂无描述

TemplatesController.php 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <?php
  2. class TemplatesController extends \BaseController
  3. {
  4. /**
  5. * List all templates, grouped by program
  6. */
  7. public function profShow(Template $template)
  8. {
  9. return $this->show($template);
  10. }
  11. public function ProfIndex()
  12. {
  13. $title = 'Rubric List';
  14. $role = Auth::user()->role;
  15. $program_id = DB::table("program_user")
  16. ->where('user_id', Auth::user()->id)
  17. ->lists('program_id')[0];
  18. $school_id = DB::table('programs')
  19. ->where('id', $program_id)
  20. ->lists('school_id')[0];
  21. $templates = Template::orderBy('name')
  22. ->whereNull("school_id")
  23. ->orWhere(function ($query) use (&$school_id) {
  24. $query->where('school_id', $school_id)
  25. ->whereNull('program_id');
  26. })
  27. ->orWhere(function ($query) use (&$program_id, &$school_id) {
  28. $query->where('school_id', $school_id)
  29. ->where('program_id', $program_id);
  30. })
  31. ->get();
  32. return View::make('local.managers.shared.rubric_list', compact('title', 'global_templates', 'schools', 'templates', 'role'));
  33. }
  34. public function index()
  35. {
  36. $title = 'Rubric List';
  37. $global_templates = Template::whereNull('school_id')->whereNull('program_id')->get();
  38. $schools = School::with('programs.templates')
  39. ->orderBy('name')
  40. ->get();
  41. $role = Auth::user()->role;
  42. switch ($role) {
  43. case 1:
  44. $templates = Template::orderBy('name')->get();
  45. break;
  46. case 2:
  47. $templates = Template::orderBy('name')
  48. ->whereNull("school_id")
  49. ->orWhere('school_id', Auth::user()->school_id)
  50. ->get();
  51. break;
  52. case 3:
  53. case 4:
  54. $program_ids = DB::table("program_user")
  55. ->where('user_id', Auth::user()->id)
  56. ->lists('program_id');
  57. $school_ids = DB::table('programs')
  58. ->whereIn('id', $program_ids)
  59. ->lists('school_id');
  60. $templates = Template::orderBy('name')
  61. ->whereNull("school_id")
  62. ->orWhere(function ($query) use (&$school_ids) {
  63. $query->whereIn('school_id', $school_ids)
  64. ->whereNull('program_id');
  65. })
  66. ->orWhere(function ($query) use (&$program_ids, &$school_ids) {
  67. $query->whereIn('school_id', $school_ids)
  68. ->whereIn('program_id', $program_ids);
  69. });
  70. Log::info($templates->toSql());
  71. Log::info($program_ids);
  72. $templates = $templates->get();
  73. break;
  74. }
  75. Log::info($templates);
  76. //$templates = Template::orderBy('name')->get();
  77. return View::make('local.managers.shared.rubric_list', compact('title', 'global_templates', 'schools', 'templates', 'role'));
  78. }
  79. /*public function schoolCoordinatorIndex()
  80. {
  81. $title = 'Rubric List';
  82. $global_templates = Template::whereNull('school_id')->whereNull('program_id')->get();
  83. $schools = School::with('programs.templates')
  84. ->orderBy('name')
  85. ->get();
  86. $templates = Template::orderBy('name')->get();
  87. return View::make('local.managers.admins.rubric_list', compact('title', 'global_templates', 'schools', 'templates'));
  88. }*/
  89. public function show(Template $template)
  90. {
  91. $title = $template->name;
  92. $template->titles = DB::table('titles')
  93. ->join('template_title', 'template_title.title_id', '=', "titles.id")
  94. ->where('template_id', $template->id)
  95. ->orderBy('position', 'ASC')
  96. ->lists('text');
  97. $template->criteria = DB::table('criteria')
  98. ->join('template_criterion', 'template_criterion.criterion_id', '=', 'criteria.id')
  99. ->where('template_id', $template->id)
  100. ->select('criteria.*', 'criteria.id as criterion_id', 'template_criterion.id as template_criterion_id')
  101. ->orderBy('position')
  102. ->get();
  103. foreach ($template->criteria as $criterion) {
  104. $criterion->scales = DB::table('criterion_scale')
  105. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  106. ->where('criterion_id', $criterion->criterion_id)
  107. ->orderBy('position')
  108. ->lists('description');
  109. $criterion->outcomes = DB::table('criterion_objective_outcome as cobo')
  110. ->join('outcomes', 'outcomes.id', '=', 'cobo.outcome_id')
  111. ->where('cobo.criterion_id', $criterion->criterion_id)
  112. ->select('outcomes.*')
  113. ->distinct()
  114. ->get();
  115. }
  116. return View::make('local.managers.admins.view_template', compact('template', 'title'));
  117. }
  118. public function onLoadFetch()
  119. {
  120. $json_to_send = [];
  121. $template_id = Input::get('id');
  122. $json_to_send["criteria"] = DB::table("criteria")->join('template_criterion', 'template_criterion.criterion_id', '=', 'criteria.id')
  123. ->where("template_criterion.template_id", '=', $template_id)
  124. ->get();
  125. Log::info($json_to_send["criteria"]);
  126. foreach ($json_to_send['criteria'] as $criteria) {
  127. $json_to_send['scales'][$criteria->criterion_id] = DB::table("scales")
  128. ->join('criterion_scale', 'criterion_scale.scale_id', '=', 'scales.id')
  129. ->where("criterion_scale.criterion_id", '=', $criteria->criterion_id)->orderBy('position', 'ASC')->get();
  130. }
  131. return json_encode($json_to_send);
  132. }
  133. /**
  134. * Show the form for creating a new rubric
  135. *
  136. * @return Response
  137. */
  138. public function newTemplate()
  139. {
  140. $title = "Rubric Builder";
  141. $templates = Template::orderBy('name', 'ASC')->get();
  142. $outcomes = Outcome::where("deactivation_date", '=', null)->orderBy('name', 'ASC')->get();
  143. $criteria = Criterion::orderBy('name', 'ASC')->get();
  144. $schools = School::orderBy('name', 'ASC')->get();
  145. $role = Auth::user()->role;
  146. $templates = NULL;
  147. $programs = NULL;
  148. // Returns templates depending on the type of user
  149. if ($role == 1) {
  150. $templates = Template::orderBy('name', 'ASC')->get();
  151. $programs = Program::orderBy('name', 'ASC')->get();
  152. } elseif ($role == 2) {
  153. $templates = Template::where('school_id', '=', Auth::user()->school->id)->orWhere('school_id', '=', NULL)->orderBy('name', 'ASC')->get();
  154. $programs = Auth::user()->school->programs;
  155. } elseif ($role == 3) {
  156. $templates = Template::where('school_id', '=', Auth::user()->programs[0]->school->id)->orWhere('school_id', '=', NULL)->orderBy('name', 'ASC')->get();
  157. $programs = Auth::user()->programs()->get();
  158. }
  159. return View::make('local.managers.shared.rubrics', compact('title', 'templates', 'outcomes', 'criteria', 'schools', 'programs'));
  160. }
  161. public function newTemplateProf()
  162. {
  163. return $this->newTemplate_new();
  164. }
  165. public function newTemplate_new()
  166. {
  167. $title = "Rubric Builder";
  168. $templates = Template::orderBy('name', 'ASC')->get();
  169. $outcomes = Outcome::where("deactivation_date", '=', null)->orderBy('name', 'ASC')->get();
  170. $schools = School::orderBy('name', 'ASC')->get();
  171. $role = Auth::user()->role;
  172. $templates = NULL;
  173. $programs = NULL;
  174. // Returns templates depending on the type of user
  175. if ($role == 1) {
  176. $templates = Template::orderBy('name', 'ASC')->get();
  177. $programs = Program::orderBy('name', 'ASC')->get();
  178. $criteria = Criterion::orderBy('name', 'ASC')->get();
  179. $school_id_user = NULL;
  180. } else {
  181. if ($role == 2) {
  182. $programs = Auth::user()->school->programs;
  183. $school_id_user = Auth::user()->school_id;
  184. }
  185. if ($role == 3) {
  186. $programs = Auth::user()->programs()->get();
  187. $school_id_user = Auth::user()->programs[0]->school->id;
  188. }
  189. if ($role == 4) {
  190. $programs = Auth::user()->programs()->get();
  191. $school_id_user = Auth::user()->programs[0]->school->id;
  192. }
  193. Log::info(json_encode($school_id_user));
  194. $program_ids = array();
  195. foreach ($programs as $program) {
  196. $program_ids[] = $program->id;
  197. }
  198. $criteria = Criterion::whereHas(
  199. 'programs',
  200. function ($q) use ($program_ids) {
  201. $q->whereIn('program_id', $program_ids);
  202. }
  203. )
  204. ->whereHas(
  205. 'getObjectivesAttribute',
  206. function ($q) {
  207. $q->where('objective_id', '!=', 0);
  208. }
  209. )
  210. ->orderBy('name', 'ASC')->get();
  211. }
  212. // Log::info("aqui".(count($criteria)));
  213. Log::info(json_encode(($criteria)));
  214. $templates = Template::where('school_id', '=', $school_id_user)->orWhere('school_id', '=', NULL)
  215. ->orderBy('name', 'ASC')->get();
  216. $criteria_ids = array();
  217. foreach ($criteria as $criterion) {
  218. $criteria_ids[] = $criterion->id;
  219. }
  220. $templates_fuera = Template::whereHas('criteria', function ($q) use ($criteria_ids) {
  221. $q->whereNotIn('criterion_id', $criteria_ids);
  222. })
  223. ->orderBy('name', 'ASC')->get();
  224. $templates_fuera_ids = array();
  225. foreach ($templates_fuera as $tf) {
  226. $templates_fuera_ids[] = $tf->id;
  227. }
  228. // Log::info(json_encode($templates_fuera_ids));
  229. // exit();
  230. $templates_dentro = Template::whereNotIn('id', $templates_fuera_ids)
  231. ->orderBy('name', 'ASC')->get();
  232. /*$templates_dentro = Template::join('template_criterion', 'template_criterion.template_id', '=', 'templates.id')
  233. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'template_criterion.criterion_id')
  234. ->where('objective_id', '<>', '0')
  235. ->where(function ($query) use ($school_id_user) {
  236. $query->where('school_id', $school_id_user)
  237. ->orWhere('school_id', '=', NULL);
  238. })
  239. // ->orWhere('school_id', '=', NULL)
  240. ->orderBy('name', 'ASC')
  241. ->groupBy('templates.id')
  242. ->select("templates.*")
  243. ->get();*/
  244. // if(!isset($templates_dentro))$templates_dentro=
  245. // var_dump(json_encode($templates_dentro));
  246. // }
  247. $templates_fuera = array();
  248. return View::make('local.managers.shared.rubrics_new', compact('title', 'templates_dentro', 'templates_fuera', 'outcomes', 'criteria', 'schools', 'programs', 'criteria_ids'));
  249. }
  250. public function fetchObjectivesForTemplate()
  251. {
  252. $criteria_ids = Input::get("allCriteria");
  253. $criteria = [];
  254. //Acho im sorry pero no tengo idea porque sale un error que haría eso más eficiente.
  255. foreach ($criteria_ids as $crit_id) {
  256. $crit = Criterion::where('id', $crit_id)->first();
  257. if (!isset($crit)) {
  258. return "NO pa";
  259. }
  260. $crit->all_objectives = DB::table("objectives")->join("criterion_objective_outcome", 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  261. ->where('criterion_id', $crit->id)
  262. ->select('objectives.*')
  263. ->groupBy('objectives.id')
  264. ->get();
  265. $criteria[] = $crit;
  266. }
  267. return $criteria;
  268. }
  269. /**
  270. * Save a new rubric
  271. *
  272. * @return Response
  273. */
  274. public function create()
  275. {
  276. DB::beginTransaction();
  277. $template = new Template;
  278. $template->name = Input::get('name');
  279. $template->is_visible = Input::get('is_visible');
  280. $template->expected_percentage = Input::get('expected_percentage');
  281. $template->expected_points = Input::get('expected_points');
  282. // If user can set the school (that is, if school_id is not undefined)
  283. // set the school id or set to null
  284. if (is_numeric(Input::get('school_id'))) {
  285. if (Input::get('school_id') != 0)
  286. $template->school_id = Input::get('school_id');
  287. elseif (Input::get('school_id') == 0)
  288. $template->school_id = NULL;
  289. }
  290. // If user can set the program (that is, if program_id is not undefined)
  291. // set the program id or set to null
  292. if (is_numeric(Input::get('program_id'))) {
  293. if (Input::get('program_id') != 0)
  294. $template->program_id = Input::get('program_id');
  295. elseif (Input::get('program_id') == 0)
  296. $template->program_id = NULL;
  297. }
  298. // If the user is any coordinator, set the school id
  299. // If the user is a program coordinator, also set program id
  300. switch (Auth::user()->role) {
  301. case 2:
  302. $template->school_id = Auth::user()->school->id;
  303. break;
  304. //TODO esto yo no lo hice
  305. case 3:
  306. $template->school_id = Auth::user()->programs[0]->school->id;
  307. //Comenté esto porque siempre va a estar el program_id
  308. //TODO
  309. if ($template->program_id == NULL)
  310. $template->program_id = Auth::user()->programs[0]->id;
  311. break;
  312. }
  313. $criteria = Input::get('criteria');
  314. $max_score = Input::get('max_score');
  315. $titles = Input::get('titles');
  316. $template->num_scales = count($titles);
  317. $template->max_score = $max_score;
  318. if ($template->save()) {
  319. $templateId = $template->id;
  320. foreach ($criteria as $index => $criterion_id) {
  321. if (!(DB::insert("insert into template_criterion (`template_id`,`criterion_id`, `position`) values ({$templateId},{$criterion_id}, '{$index}')"))) {
  322. Session::flash('status', 'danger');
  323. Session::flash('message', 'Rubric could not be created.');
  324. DB::rollback();
  325. return;
  326. }
  327. }
  328. foreach ($titles as $index => $text) {
  329. $query = DB::table('titles')
  330. ->where('text', $text)->first();
  331. if ($query) {
  332. $result = DB::insert("insert into `template_title` (`template_id`, `title_id`, `position`) values ({$templateId}, {$query->id}, {$index})");
  333. if (!$result) {
  334. Session::flash('status', 'danger');
  335. Session::flash('message', 'Rubric could not be created.');
  336. DB::rollback();
  337. return;
  338. }
  339. } else {
  340. $result1 = DB::insert("insert into `titles` (`text`) values ('{$text}')");
  341. if (!$result1) {
  342. Session::flash('status', 'danger');
  343. Session::flash('message', 'Rubric could not be created.');
  344. DB::rollback();
  345. return;
  346. }
  347. $query = DB::table('titles')
  348. ->where('text', $text)->first();
  349. $result = DB::insert("insert into `template_title` (`template_id`, `title_id`, `position`) values ({$templateId}, {$query->id}, {$index})");
  350. if (!$result) {
  351. Session::flash('status', 'danger');
  352. Session::flash('message', 'Rubric could not be created.');
  353. DB::rollback();
  354. return;
  355. }
  356. }
  357. }
  358. Session::flash('status', 'success');
  359. Session::flash('message', 'Rubric created. You can now select it from the list.');
  360. DB::commit();
  361. return;
  362. } else {
  363. Session::flash('status', 'danger');
  364. Session::flash('message', 'Rubric could not be created.');
  365. DB::rollback();
  366. return;
  367. }
  368. }
  369. /**
  370. * Return a specific template
  371. *
  372. * @return Template
  373. */
  374. public function fetch()
  375. {
  376. $template_info = [];
  377. $template_info['template'] = Template::find(Input::get('id'));
  378. $template_info['criterion'] = DB::table('criteria')
  379. ->join('template_criterion', 'template_criterion.criterion_id', '=', 'criteria.id')
  380. ->where("template_criterion.template_id", '=', Input::get('id'))
  381. ->get();
  382. Log::info(json_encode($template_info['criterion']));
  383. // Log::info(($temp_crit->program_ids));
  384. foreach ($template_info['criterion'] as $temp_crit) {
  385. $temp_crit->scales = DB::table('scales')
  386. ->join('criterion_scale', 'criterion_scale.scale_id', '=', 'scales.id')
  387. ->where('criterion_scale.criterion_id', '=', $temp_crit->criterion_id)
  388. ->orderBy('position', 'ASC')
  389. ->get();
  390. $temp_crit->program_ids = json_encode(DB::table('program_criterion_objective_outcome')
  391. ->join('criterion_objective_outcome', 'criterion_objective_outcome.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
  392. ->where('criterion_objective_outcome.criterion_id', $temp_crit->id)
  393. ->select('program_criterion_objective_outcome.program_id')
  394. ->distinct()
  395. ->lists('program_criterion_objective_outcome.program_id'));
  396. Log::info("ee" . json_encode($temp_crit->program_ids));
  397. $temp_crit->objectives = DB::table('criterion_objective_outcome')
  398. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  399. ->where('criterion_id', $temp_crit->id)
  400. ->select('objectives.*')
  401. ->distinct()
  402. ->lists('text');
  403. $outcomeID = DB::table('criterion_objective_outcome')->where('criterion_id', '=', $temp_crit->criterion_id)
  404. ->lists('outcome_id');
  405. $outcomes = DB::table('outcomes')->whereIn('id', $outcomeID)->get();
  406. $outcomeStr = '';
  407. foreach ($outcomes as $key => $outcome) {
  408. $outcomeStr .= $outcome->name . ', ';
  409. }
  410. $outcomeStr = rtrim($outcomeStr, ',');
  411. $temp_crit->outcomes = $outcomeStr;
  412. }
  413. Log::info("ee2" . json_encode($template_info));
  414. $template_info['titles'] = DB::table('titles')
  415. ->join('template_title', 'template_title.title_id', '=', 'titles.id')
  416. ->where('template_id', Input::get('id'))
  417. ->orderBy('position')
  418. ->get();
  419. // Log::info(json_encode($template_info));
  420. return json_encode($template_info);
  421. }
  422. /**
  423. * Update the specified resource in storage.
  424. *
  425. * @return Response
  426. */
  427. public function update()
  428. {
  429. DB::beginTransaction();
  430. $template = Template::find(Input::get('id'));
  431. Log::info(Input::all());
  432. $template->name = Input::get('name');
  433. $template->is_visible = Input::get('is_visible');
  434. $template->expected_percentage = Input::get('expected_percentage');
  435. $template->expected_points = Input::get('expected_points');
  436. // If user can set the school (that is, if school_id is not undefined)
  437. // set the school id or set to null
  438. if (is_numeric(Input::get('school_id'))) {
  439. if (Input::get('school_id') != 0)
  440. $template->school_id = Input::get('school_id');
  441. elseif (Input::get('school_id') == 0)
  442. $template->school_id = NULL;
  443. }
  444. // If user can set the program (that is, if program_id is not undefined)
  445. // set the program id or set to null
  446. if (is_numeric(Input::get('program_id'))) {
  447. if (Input::get('program_id') != 0)
  448. $template->program_id = Input::get('program_id');
  449. elseif (Input::get('program_id') == 0)
  450. $template->program_id = NULL;
  451. }
  452. switch (Auth::user()->role) {
  453. case 2:
  454. $template->school_id = Auth::user()->school->id;
  455. break;
  456. case 3:
  457. $template->school_id = Auth::user()->programs[0]->school->id;
  458. if ($template->program_id == NULL)
  459. $template->program_id = Auth::user()->programs[0]->id;
  460. break;
  461. }
  462. $criteria = Input::get('criteria');
  463. $max_score = Input::get('max_score');
  464. $titles = Input::get('titles');
  465. $template->num_scales = count($titles);
  466. $template->max_score = $max_score;
  467. //$division = $max_score / count($scales[0]);
  468. if ($template->save()) {
  469. $templateId = $template->id;
  470. DB::delete("delete from template_criterion where template_id ={$template->id}");
  471. foreach ($criteria as $index => $criterion_id) {
  472. if (!DB::insert("insert into template_criterion (`template_id`,`criterion_id`, `position`) values ({$templateId},{$criterion_id}, {$index})")) {
  473. Session::flash('status', 'danger');
  474. Session::flash('message', 'Rubric could not be created.');
  475. DB::rollback();
  476. return;
  477. }
  478. }
  479. DB::delete("delete from template_title where template_id = {$template->id}");
  480. foreach ($titles as $index => $text) {
  481. $query = DB::table('titles')
  482. ->where('text', $text)->first();
  483. if ($query) {
  484. $result = DB::insert("insert into `template_title` (`template_id`, `title_id`, `position`) values ({$templateId}, {$query->id}, {$index})");
  485. if (!$result) {
  486. Session::flash('status', 'danger');
  487. Session::flash('message', 'Rubric could not be created.');
  488. DB::rollback();
  489. return;
  490. }
  491. } else {
  492. $result1 = DB::insert("insert into `titles` (`text`) values ('{$text}')");
  493. if (!$result1) {
  494. Session::flash('status', 'danger');
  495. Session::flash('message', 'Rubric could not be created.');
  496. DB::rollback();
  497. return;
  498. }
  499. $query = DB::table('titles')
  500. ->where('text', $text)->first();
  501. $result = DB::insert("insert into `template_title` (`template_id`, `title_id`, `position`) values ({$templateId}, {$query->id}, {$index})");
  502. if (!$result) {
  503. Session::flash('status', 'danger');
  504. Session::flash('message', 'Rubric could not be created.');
  505. DB::rollback();
  506. return;
  507. }
  508. }
  509. }
  510. Session::flash('status', 'success');
  511. Session::flash('message', 'Rubric updated (' . date('m/d/y, h:i:s a') . ').');
  512. DB::commit();
  513. } else {
  514. Session::flash('status', 'danger');
  515. Session::flash('message', 'Rubric could not be updated (' . date('m/d/y, h:i:s a') . ').');
  516. DB::commit();
  517. }
  518. }
  519. /**
  520. * Remove the specified resource from storage.
  521. *
  522. * @return Response
  523. */
  524. public function destroy()
  525. {
  526. $template = Template::find(Input::get('id'));
  527. if ($template->delete()) {
  528. Session::flash('status', 'success');
  529. Session::flash('message', 'Rubric deleted.');
  530. } else {
  531. Session::flash('status', 'danger');
  532. Session::flash('message', 'Rubric could not be deleted.');
  533. }
  534. return;
  535. }
  536. public function printview($id)
  537. {
  538. try {
  539. $template = Template::find($id);
  540. $template->titles = DB::table('titles')
  541. ->join('template_title', 'template_title.title_id', '=', 'titles.id')
  542. ->where("template_id", $template->id)
  543. ->orderBy('position', 'ASC')
  544. ->lists('text');
  545. $template_criterion = DB::table('template_criterion')
  546. ->join('criteria', 'criteria.id', '=', 'template_criterion.criterion_id')
  547. ->where('template_id', $template->id)
  548. ->orderBy('position', 'ASC')
  549. ->get();
  550. foreach ($template_criterion as $single_crit) {
  551. $single_crit->scales = DB::table('criterion_scale')
  552. ->join('scales', 'criterion_scale.scale_id', '=', 'scales.id')
  553. ->where('criterion_id', $single_crit->id)
  554. ->orderBy('position')
  555. ->lists('description');
  556. $single_crit->outcomes = DB::table('outcomes')
  557. ->join('criterion_objective_outcome', 'criterion_objective_outcome.outcome_id', '=', 'outcomes.id')
  558. ->where('criterion_id', $single_crit->id)
  559. ->select('name')
  560. ->distinct()
  561. ->lists('name');
  562. }
  563. $title = $template->name;
  564. if ($template->school_id != NULL)
  565. $school = $template->school->name;
  566. else
  567. $school = 'All Schools';
  568. if ($template->program_id != NULL)
  569. $program = $template->program->name;
  570. else
  571. $program = 'All Programs';
  572. return View::make('local.managers.shared.print_rubric', compact('title', 'template_criterion', 'template', 'school', 'program'));
  573. } catch (Exception $e) {
  574. Session::flash('status', 'danger');
  575. Session::flash('message', $e->getMessage());
  576. return Redirect::back();
  577. }
  578. }
  579. }