설명 없음

RubricsController.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <?php
  2. class RubricsController extends \BaseController
  3. {
  4. /**
  5. * Show the form for creating a new rubric
  6. *
  7. * @return Response
  8. */
  9. public function newRubric($activity_id)
  10. {
  11. $activity = Activity::find($activity_id);
  12. // If activity does not exist, display 404
  13. if (!$activity)
  14. App::abort('404');
  15. $title = 'Rubric for <em>' . $activity->name . '</em>';
  16. // Select templates that belong to everyone or belong to the activity's course's school
  17. $usable_templates = DB::table('templates')
  18. ->join('template_criterion', 'template_criterion.template_id', '=', 'templates.id')
  19. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'template_criterion.criterion_id')
  20. ->join('program_criterion_objective_outcome', 'criterion_objective_outcome.id', '=', 'program_criterion_objective_outcome.cri_obj_out_id')
  21. ->where('objective_id', '<>', 0)
  22. ->where('program_criterion_objective_outcome.program_id', $activity->course->program->id)
  23. ->groupBy('template_id')
  24. ->lists('template_id');
  25. $templates = Template::where('is_visible', '=', 1)
  26. ->where(function ($query) use ($activity) {
  27. if (Auth::user()->role != 1) {
  28. $query
  29. ->where('school_id', $activity->course->program->school->id)
  30. ->orWhere('school_id', '=', NULL)
  31. ->orWhere('program_id', '=', $activity->course->program->id);
  32. }
  33. })
  34. ->join('template_criterion', 'template_criterion.template_id', '=', 'templates.id')
  35. ->join('criterion_objective_outcome', 'template_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
  36. ->where('objective_id', '<>', 0)
  37. ->groupBy("templates.id")
  38. ->select('templates.*')
  39. //->join('program_criterion_objective_outcome_id','')
  40. //->whereIn('templates.id', $usable_templates)
  41. ->orderBy('name', 'ASC')->get();
  42. $rubrics = Auth::user()->rubrics;
  43. $outcomes = Outcome::orderBy('name', 'ASC')->get();
  44. $criteria = Criterion::orderBy('name', 'ASC')->get();
  45. $rubric = $activity->rubric;
  46. // $draft=$activity->draft;
  47. // Log::info("*****".$activity);
  48. return View::make('local.professors.rubrics', compact('title', 'templates', 'outcomes', 'criteria', 'rubrics', 'activity', 'rubric'));
  49. }
  50. public function newOtherMethod($activity_id)
  51. {
  52. $activity = Activity::find($activity_id);
  53. // If activity does not exist, display 404
  54. if (!$activity)
  55. App::abort('404');
  56. $title = 'Rubric for <em>' . $activity->name . '</em>';
  57. // Select templates that belong to everyone or belong to the activity's course's school
  58. $templates = Template::where('is_visible', '=', 1)
  59. ->where(function ($query) use ($activity) {
  60. if (Auth::user()->role != 1) {
  61. $query
  62. ->where('school_id', $activity->course->program->school->id)
  63. ->orWhere('school_id', '=', NULL);
  64. }
  65. })
  66. ->orderBy('name', 'ASC')->get();
  67. $rubrics = Auth::user()->rubrics;
  68. $outcomes = Outcome::orderBy('name', 'ASC')->get();
  69. $criteria = Criterion::orderBy('name', 'ASC')->get();
  70. $rubric = $activity->rubric;
  71. return View::make('local.professors.rubrics', compact('title', 'templates', 'outcomes', 'criteria', 'rubrics', 'activity', 'rubric'));
  72. }
  73. /**
  74. * Save a new rubric
  75. *
  76. * @return Response
  77. */
  78. public function create()
  79. {
  80. DB::beginTransaction();
  81. // Get rubric contents
  82. $titles = Input::get('titles');
  83. $criteria = Input::get('criteria');
  84. // Process rubric
  85. $rubric = new Rubric;
  86. $rubric->name = Input::get('name');
  87. $rubric->expected_percentage = Input::get('expected_percentage');
  88. $rubric->expected_points = Input::get('expected_points');
  89. $rubric->user_id = Auth::id();
  90. $rubric->num_scales = count($titles);
  91. $rubric->max_score = Input::get('max_score');
  92. $defaultWeight = round(100 / count($criteria), 2);
  93. if ($rubric->save()) {
  94. // Process activity
  95. // $activity = Activity::find(Input::get('activity_id'));
  96. // $activity->rubric_id = $rubric->id;
  97. // $activity->save();
  98. DB::table('rubric_activity')->insert(array('activity_id' => Input::get('activity_id'), 'rubric_id' => $rubric->id));
  99. DB::commit();
  100. $activity_id = Input::get("activity_id");
  101. $rubricId = $rubric->id;
  102. foreach ($criteria as $index => $criterion_id) {
  103. DB::insert("insert into rubric_criterion (`rubric_id`,`criterion_id`, `position`) values ({$rubricId},{$criterion_id}, {$index})");
  104. DB::commit();
  105. DB::insert("insert into `activity_criterion` (`activity_id`,`criterion_id`, `weight`) values ({$activity_id}, {$criterion_id}, {$defaultWeight})");
  106. DB::commit();
  107. }
  108. foreach ($titles as $index => $id) {
  109. DB::insert("insert into `rubric_title` (`rubric_id`, `title_id`, `position`) values ({$rubricId}, {$id}, {$index} )");
  110. DB::commit();
  111. }
  112. Session::flash('status', 'success');
  113. Session::flash('message', 'Rubric assigned.');
  114. return action('ActivitiesController@show', array(Input::get('activity_id')));
  115. } else {
  116. DB::rollBack();
  117. Session::flash('status', 'danger');
  118. Session::flash('message', 'Error creating Rubric. Try again later.' . $e);
  119. }
  120. }
  121. /**
  122. * Return a specific template
  123. *
  124. * @return Template
  125. */
  126. public function fetch()
  127. {
  128. return Rubric::find(Input::get('id'));
  129. }
  130. /**
  131. * Update a rubric
  132. *
  133. * @return Response
  134. */
  135. public function update()
  136. {
  137. $rubric = Rubric::find(Input::get('id'));
  138. $titles = Input::get('titles');
  139. $criteria = Input::get('criteria');
  140. // Process rubric
  141. $rubric->name = Input::get('name');
  142. $rubric->expected_percentage = Input::get('expected_percentage');
  143. $rubric->expected_points = Input::get('expected_points');
  144. $rubric->num_scales = count($titles);
  145. $rubric->max_score = Input::get('max_score');
  146. $defaultWeight = round(100 / count($criteria), 2);
  147. DB::beginTransaction();
  148. // Get associated activity
  149. //$activity = Activity::where('rubric_id', '=', $rubric->id)->first();
  150. $activity_id = DB::table('activities')
  151. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  152. ->where('rubric_id', '=', $rubric->id)
  153. ->first();
  154. $activity = Activity::where('id', '=', $activity_id->activity_id)->first();
  155. // If the associated activity has been assessed, delete the records
  156. /* if ($activity->outcomes_attempted != NULL) {
  157. DB::table('assessments')->where('activity_id', '=', $activity->id)->delete();
  158. $activity->criteria_achieved_percentage = NULL;
  159. $activity->criteria_achieved = NULL;
  160. $activity->outcomes_achieved = NULL;
  161. $activity->outcomes_attempted = NULL;
  162. }*/
  163. $rubric->save();
  164. $activity->save();
  165. // Get all the course's activities
  166. Log::info($activity->course);
  167. $course = Course::find($activity->course->id);
  168. $activities = $course->activities;
  169. // Check if any assessed activities remain
  170. $remainingAssessed = false;
  171. foreach ($course->activities as $activity) {
  172. if ($activity->outcomes_attempted != NULL) {
  173. $remainingAssessed = true;
  174. break;
  175. }
  176. }
  177. Log::info('entré4???');
  178. //If there are still evaluated activities in the course, recalculate course outcomes
  179. /*
  180. if (!$activities->isEmpty() && $remainingAssessed) {
  181. // Variables to hold recalculated outcomes for the course
  182. $course_outcomes_attempted = array_fill(1, Outcome::all()->count(), 0);
  183. $course_outcomes_achieved = array_fill(1, Outcome::all()->count(), 0);
  184. // For each activity
  185. foreach ($activities as $activity) {
  186. // If activity has been assessed
  187. if ($activity->outcomes_attempted != NULL) {
  188. // Get the achieved criteria
  189. $criteria_achievement = json_decode($activity->criteria_achieved, true);
  190. foreach ($criteria_achievement as $criterion_id => $criterion_achieved) {
  191. // Find corresponding learning outcome;
  192. $criterion = Criterion::find($criterion_id);
  193. $outcome = Outcome::find($criterion->outcome_id);
  194. // If criterion is achieved (1), add 1 to both arrays
  195. if ($criterion_achieved === 1) {
  196. $course_outcomes_attempted[$outcome->id] += 1;
  197. $course_outcomes_achieved[$outcome->id] += 1;
  198. }
  199. // Else, only add to the attempted outcomes arrays
  200. elseif ($criterion_achieved === 0) {
  201. $course_outcomes_attempted[$outcome->id] += 1;
  202. }
  203. }
  204. }
  205. }
  206. Log::info('entré5???');
  207. // Update course
  208. $course->outcomes_achieved = json_encode($course_outcomes_achieved);
  209. $course->outcomes_attempted = json_encode($course_outcomes_attempted);
  210. } else {
  211. // Update course
  212. $course->outcomes_achieved = NULL;
  213. $course->outcomes_attempted = NULL;
  214. }
  215. $course->save();
  216. */
  217. Log::info('entré6???');
  218. DB::delete("delete from rubric_criterion where rubric_id ={$rubric->id}");
  219. DB::delete("delete from activity_criterion where activity_id = {$activity->id}");
  220. DB::delete("delete from rubric_title where rubric_id = {$rubric->id}");
  221. foreach ($criteria as $index => $criterion_id) {
  222. $result = DB::insert("insert into rubric_criterion (`rubric_id`, `criterion_id`, `position`) values ({$rubric->id}, {$criterion_id}, {$index}) ");
  223. $result2 = DB::insert("insert into `activity_criterion` (`activity_id`,`criterion_id`, `weight`) values ({$activity->id}, {$criterion_id}, {$defaultWeight})");
  224. if (!($result || $result2)) {
  225. DB::rollBack();
  226. Session::flash('status', 'danger');
  227. Session::flash('message', 'Rubric could not be created.');
  228. return action('ActivitiesController@show', array($activity->id));
  229. }
  230. }
  231. foreach ($titles as $index => $id) {
  232. DB::insert("insert into rubric_title (`rubric_id`, `title_id`, `position`) values ({$rubric->id},{$id},{$index}) ");
  233. }
  234. Log::info('entré7???');
  235. DB::commit();
  236. Session::flash('status', 'success');
  237. Session::flash('message', 'Rubric updated.');
  238. return action('ActivitiesController@show', array($activity->id));
  239. }
  240. /**
  241. * Remove the specified resource from storage.
  242. *
  243. * @return Response
  244. */
  245. public function destroy()
  246. {
  247. $rubric = Rubric::find(Input::get('id'));
  248. if ($rubric->delete()) {
  249. Session::flash('status', 'success');
  250. Session::flash('message', 'Rubric deleted.');
  251. } else {
  252. Session::flash('status', 'danger');
  253. Session::flash('message', 'Error: The rubric could not be deleted. Try again later.');
  254. }
  255. return;
  256. }
  257. /**
  258. * Show a specific rubric
  259. *
  260. * @return Response
  261. */
  262. public function show($activity_id)
  263. {
  264. $activity = Activity::find($activity_id);
  265. // Get activity's course
  266. // Log::info("actv".$activity);
  267. $course = Course::where('id', '=', $activity->course_id)->firstOrFail();
  268. // Log::info("user".$course->user_id);
  269. // If activity does not belong to the requesting user, display 403
  270. if ($course->user_id != Auth::id())
  271. App::abort('403', 'Access Forbidden');
  272. // Log::info("rubric".$activity->rubric);
  273. // exit();
  274. $rubric = Rubric::where('id', '=', $activity->rubric[0]->id)->firstOrFail();
  275. $rubric_criterion = DB::table('criteria')
  276. ->join('rubric_criterion', 'rubric_criterion.criterion_id', '=', 'criteria.id')
  277. ->where('rubric_criterion.rubric_id', '=', $activity->rubric[0]->id)
  278. ->get();
  279. Log::info($rubric_criterion);
  280. $rubric->titles = DB::table('titles')
  281. ->join('rubric_title', 'rubric_title.title_id', '=', 'titles.id')
  282. ->where('rubric_title.rubric_id', $rubric->id)
  283. ->lists('text');
  284. foreach ($rubric_criterion as $single_cr) {
  285. $single_cr->scales = json_encode(DB::table('scales')
  286. ->join('criterion_scale', 'criterion_scale.scale_id', '=', 'scales.id')
  287. ->where('criterion_scale.criterion_id', '=', $single_cr->criterion_id)
  288. ->orderBy('position')
  289. ->lists('description'));
  290. $single_cr->outcomes = json_encode(DB::table('outcomes')
  291. ->join('criterion_objective_outcome', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  292. ->where('criterion_objective_outcome.criterion_id', '=', $single_cr->criterion_id)->lists('name'));
  293. }
  294. Log::info($rubric_criterion);
  295. $title = $activity->name . ': ' . $rubric->name;
  296. return View::make('local.professors.viewrubric', compact('rubric', 'activity', 'rubric_criterion', 'title', 'course'));
  297. }
  298. /**
  299. * Show a specific rubric without some course and user information
  300. *
  301. * @return Response
  302. */
  303. public function show_limited($rubric_id)
  304. {
  305. // If user is a professor, display 403.
  306. if (Auth::user()->role == 4)
  307. App::abort('403', 'Access Forbidden');
  308. $rubric = Rubric::where('id', '=', $rubric_id)->firstOrFail();
  309. $rubric_criterion = DB::table('criteria')
  310. ->join('rubric_criterion', 'rubric_criterion.criterion_id', '=', 'criteria.id')
  311. ->where('rubric_criterion.rubric_id', '=', $rubric->id)
  312. ->get();
  313. $rubric->titles = DB::table('titles')
  314. ->join('rubric_title', 'rubric_title.title_id', '=', 'titles.id')
  315. ->where('rubric_title.rubric_id', $rubric->id)
  316. ->orderBy('position')
  317. ->lists('text');
  318. foreach ($rubric_criterion as $single_cr) {
  319. $single_cr->scales = DB::table('scales')
  320. ->join('criterion_scale', 'criterion_scale.scale_id', '=', 'scales.id')
  321. ->where('criterion_scale.criterion_id', '=', $single_cr->criterion_id)
  322. ->orderBy('position')
  323. ->lists('description');
  324. $single_cr->outcomes = DB::table('outcomes')
  325. ->join('criterion_objective_outcome', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  326. ->where('criterion_objective_outcome.criterion_id', '=', $single_cr->criterion_id)->lists('name');
  327. }
  328. $title = $rubric->name;
  329. $role = Auth::user()->role;
  330. return View::make('local.managers.shared.view_rubric_limited', compact('rubric', 'rubric_criterion', 'title', 'role'));
  331. }
  332. public function download($activity_id, $rubric_id)
  333. {
  334. $activity = Activity::find($activity_id);
  335. // Get activity's course
  336. $course = Course::where('id', '=', $activity->course_id)->firstOrFail();
  337. // If activity does not belong to the requesting user, display 403
  338. if ($course->user_id != Auth::id())
  339. App::abort('403', 'Access Forbidden');
  340. $rubric = Rubric::where('id', '=', $activity->rubric_id)->firstOrFail();
  341. $rubric_criterion = DB::table('criteria')
  342. ->join('rubric_criterion', 'rubric_criterion.criterion_id', '=', 'criteria.id')
  343. ->where('rubric_criterion.rubric_id', '=', $activity->rubric[0]->id)
  344. ->get();
  345. $rubric->titles = DB::table('titles')
  346. ->join('rubric_title', 'rubric_title.title_id', '=', 'titles.id')
  347. ->where('rubric_title.rubric_id', $rubric->id)
  348. ->orderBy('position')
  349. ->lists('text');
  350. foreach ($rubric_criterion as $single_cr) {
  351. $single_cr->scales = json_encode(DB::table('scales')
  352. ->join('criterion_scale', 'criterion_scale.scale_id', '=', 'scales.id')
  353. ->where('criterion_scale.criterion_id', '=', $single_cr->criterion_id)
  354. ->orderBy('position')
  355. ->lists('description'));
  356. $single_cr->outcomes = json_encode(DB::table('outcomes')
  357. ->join('criterion_objective_outcome', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  358. ->where('criterion_objective_outcome.criterion_id', '=', $single_cr->criterion_id)->lists('name'));
  359. }
  360. $title = $activity->name . ': ' . $rubric->name;
  361. return View::make('local.professors.downloadrubric', compact('rubric', 'rubric_criterion', 'activity', 'title', 'course'));
  362. }
  363. public function printview($activity_id, $rubric_id)
  364. {
  365. $activity = Activity::find($activity_id);
  366. // Get activity's course
  367. $course = Course::where('id', '=', $activity->course_id)->firstOrFail();
  368. // If activity does not belong to the requesting user, display 403
  369. if ($course->user_id != Auth::id())
  370. App::abort('403', 'Access Forbidden');
  371. $rubric = Rubric::where('id', '=', $activity->rubric[0]->id)->firstOrFail();
  372. $rubric_criterion = DB::table('criteria')
  373. ->join('rubric_criterion', 'rubric_criterion.criterion_id', '=', 'criteria.id')
  374. ->where('rubric_criterion.rubric_id', '=', $activity->rubric[0]->id)
  375. ->get();
  376. $rubric->titles = DB::table('titles')
  377. ->join('rubric_title', 'rubric_title.title_id', '=', 'titles.id')
  378. ->where('rubric_title.rubric_id', $rubric->id)
  379. ->orderBy('position')
  380. ->lists('text');
  381. foreach ($rubric_criterion as $single_cr) {
  382. $single_cr->scales = json_encode(DB::table('scales')
  383. ->join('criterion_scale', 'criterion_scale.scale_id', '=', 'scales.id')
  384. ->where('criterion_scale.criterion_id', '=', $single_cr->criterion_id)
  385. ->orderBy('position')
  386. ->lists('description'));
  387. $single_cr->outcomes = json_encode(DB::table('outcomes')
  388. ->join('criterion_objective_outcome', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  389. ->where('criterion_objective_outcome.criterion_id', '=', $single_cr->criterion_id)->lists('name'));
  390. }
  391. $title = $activity->name . ': ' . $rubric->name;
  392. return View::make('local.professors.printrubric', compact('rubric', 'rubric_criterion', 'activity', 'title', 'course'));
  393. }
  394. public function fetchRubricCriterion()
  395. {
  396. Log::info(Input::all());
  397. $rubric = DB::table("criterion_scale")
  398. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  399. ->where("criterion_id", '=', Input::get('criterion_id'))
  400. ->orderBy('position')
  401. ->get();
  402. Log::info($rubric);
  403. $rubric["criteria"] = DB::table("criteria")
  404. ->where("criteria.id", '=', Input::get('criterion_id'))
  405. ->select('name', 'notes')
  406. ->first();
  407. return json_encode($rubric);
  408. //$rubric_contents = json_decode($rubric->contents);
  409. //foreach ($rubric_contents as $key => $criterion) {
  410. // if ($criterion->id == $criterion_id) {
  411. // return json_encode($criterion);
  412. // }
  413. }
  414. }