Açıklama Yok

ActivitiesController.php 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. <?php
  2. class ActivitiesController extends \BaseController {
  3. /**
  4. * Save a new activity
  5. *
  6. * @param int $id The id of the parent course
  7. * @return Response Redirect to the parent course's page
  8. */
  9. public function create($id)
  10. {
  11. /** Validation rules */
  12. $validator = Validator::make(
  13. array(
  14. 'name' => Input::get('name'),
  15. 'description' => Input::get('description')
  16. ),
  17. array(
  18. 'name' => 'required|unique:activities,course_id,'.$id,
  19. 'description' => 'required|min:10'
  20. )
  21. );
  22. /** If validation fails */
  23. if ($validator->fails())
  24. {
  25. /** Prepare error message */
  26. $message = 'Error(s) creating a new Activity<ul>';
  27. foreach ($validator->messages()->all('<li>:message</li>') as $validationError)
  28. {
  29. $message.=$validationError;
  30. }
  31. $message.='</ul>';
  32. /** Send error message and old data */
  33. Session::flash('status', 'danger');
  34. Session::flash('message', $message);
  35. return Redirect::back()->withInput();
  36. }
  37. else
  38. {
  39. /** Instantiate new activity */
  40. $activity = new Activity;
  41. $activity->name= Input::get('name');
  42. $activity->description = Input::get('description');
  43. $activity->course_id = $id;
  44. $activity->date = date('Y-m-d');
  45. /** If activity is saved, send success message */
  46. if($activity->save())
  47. {
  48. Session::flash('status', 'success');
  49. Session::flash('message', 'Activity created.');
  50. return Redirect::action('ActivitiesController@show', array($activity->id));
  51. }
  52. /** If saving fails, send error message and old data */
  53. else
  54. {
  55. Session::flash('status', 'warning');
  56. Session::flash('message', 'Error adding Activity. Please try again later.');
  57. return Redirect::back()->withInput();
  58. }
  59. }
  60. }
  61. /**
  62. *
  63. */
  64. public function show($id)
  65. {
  66. $activity = Activity::find($id);
  67. // If activity does not exist, display 404
  68. if(!$activity)
  69. App::abort('404');
  70. // Get activity's course
  71. $course = Course::where('id', '=', $activity->course_id)->firstOrFail();
  72. // If activity does not belong to the requesting user, display 403
  73. if ($course->user_id != Auth::id())
  74. App::abort('403', 'Access Forbidden');
  75. // Get active semesters
  76. $active_semesters= array();
  77. $active_semesters_collection = Semester::select('id')->where('is_visible', 1)->where('start', '<=', date('Y-m-d H:i:s'))->where('end', '>=', date('Y-m-d H:i:s'))->get();
  78. foreach ($active_semesters_collection as $active_semester)
  79. {
  80. $active_semesters[]=$active_semester->id;
  81. }
  82. // Added the function htmlspecialchars to activity name string because it was corrupting Jquery code while using quotes on page rendering. - Carlos R Caraballo 1/18/2019
  83. $title = $course->code.$course->number.'-'.$course->section.': '.htmlspecialchars($activity->name, ENT_QUOTES).' <span class="small attention">('.$course->semester->code.')</span>';
  84. $outcomes = Outcome::orderBy('name', 'asc')->get();
  85. $outcomes_achieved = json_decode($activity->outcomes_achieved, true);
  86. $outcomes_attempted = json_decode($activity->outcomes_attempted, true);
  87. return View::make('local.professors.activity', compact('activity', 'title', 'outcomes', 'outcomes_achieved', 'outcomes_attempted', 'course', 'student_count', 'active_semesters'));
  88. }
  89. public function assess($id)
  90. {
  91. $activity = Activity::find($id);
  92. // If activity does not exist, display 404
  93. if(!$activity)
  94. App::abort('404');
  95. // Get activity's course
  96. $course = Course::where('id', '=', $activity->course_id)->firstOrFail();
  97. // If activity does not belong to the requesting user, display 403
  98. if ($course->user_id != Auth::id())
  99. App::abort('403', 'Access Forbidden');
  100. $title = 'Assessment Sheet';
  101. $students = $course->students;
  102. // Get rubric contents
  103. $rubric = Rubric::find($activity->rubric_id);
  104. $rubric_contents = json_decode($rubric->contents);
  105. // Get results
  106. $assessments = DB::table('assessments')->join('students', 'assessments.student_id','=','students.id')->where('activity_id', '=', $activity->id)->orderBy('assessments.id', 'asc')->get();
  107. // Decode the scores (blade workaround)
  108. $scores_array = array();
  109. foreach ($assessments as $index=>$assessment)
  110. {
  111. $scores_array[$assessment->id] = json_decode($assessment->scores, true);
  112. }
  113. return View::make('local.professors.assessment', compact('activity', 'title', 'students', 'course', 'rubric_contents', 'assessments', 'scores_array', 'rubric'));
  114. }
  115. public function saveAssessment()
  116. {
  117. try
  118. {
  119. $exception = DB::transaction(function()
  120. {
  121. DB::transaction(function()
  122. {
  123. // Student assessment data
  124. $student_data = json_decode(Input::get('student_scores'));
  125. // Outcome count
  126. $outcomeCount = Outcome::all()->count();
  127. // Activity
  128. $activity = Activity::find(Input::get('activity_id'));
  129. // Create or update student scores
  130. if($activity->outcomes_attempted==NULL)
  131. {
  132. // For each student, save her/his assessment in the db
  133. foreach ($student_data as $single_student_data)
  134. {
  135. // Find student by id
  136. $student = Student::find($single_student_data->student_id);
  137. $comments = trim($single_student_data->comments);
  138. if($comments=='')
  139. {
  140. $comments = NULL;
  141. }
  142. // Add the assessment to the pivot table
  143. $student->assessed_activities()->attach($activity->id, array(
  144. 'scores' => json_encode($single_student_data->scores),
  145. 'percentage'=>$single_student_data->percentage,
  146. 'comments' => $single_student_data->comments
  147. ));
  148. }
  149. }
  150. else
  151. {
  152. // For each student, save her/his assessment in the db
  153. foreach ($student_data as $single_student_data)
  154. {
  155. // Find student by id
  156. $student = Student::find($single_student_data->student_id);
  157. $comments = trim($single_student_data->comments);
  158. if($comments=='')
  159. {
  160. $comments = NULL;
  161. }
  162. // Update the assessment in the pivot table
  163. $student->assessed_activities()->updateExistingPivot($activity->id, array(
  164. 'scores' => json_encode($single_student_data->scores),
  165. 'percentage'=>$single_student_data->percentage,
  166. 'comments' => $single_student_data->comments
  167. ));
  168. }
  169. }
  170. // Prepare arrays for criteria achievement for this activity
  171. $criteria_achievement = json_decode(Input::get('criteria_achievement'));
  172. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  173. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  174. // Fetch parent course's criteria achievement by outcome, if it exists
  175. $course = $activity->course;
  176. $course_outcomes_attempted = NULL;
  177. $course_outcomes_achieved = NULL;
  178. if($course->outcomes_attempted==NULL)
  179. {
  180. $course_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  181. $course_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  182. }
  183. else
  184. {
  185. // the second argument is necessary to convert it into an array
  186. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  187. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  188. }
  189. foreach($criteria_achievement as $criterion_id=>$criterion_achieved)
  190. {
  191. // Find corresponding learning outcome
  192. $criterion = Criterion::withTrashed()->find($criterion_id);
  193. $outcome = Outcome::find($criterion->outcome_id);
  194. // If criterion is achieved (1), add 1 to all arrays
  195. if($criterion_achieved===1)
  196. {
  197. $outcomes_attempted[$outcome->id]+=1;
  198. $outcomes_achieved[$outcome->id]+=1;
  199. $course_outcomes_attempted[$outcome->id]+=1;
  200. $course_outcomes_achieved[$outcome->id]+=1;
  201. }
  202. // Else if it's 0, only add to the attempted outcomes arrays
  203. elseif($criterion_achieved===0)
  204. {
  205. $outcomes_attempted[$outcome->id]+=1;
  206. $course_outcomes_attempted[$outcome->id]+=1;
  207. }
  208. }
  209. // If all values are 0, throw exception
  210. if(count(array_unique($outcomes_attempted))==1 && $outcomes_attempted[1]==0)
  211. throw new Exception("Error Processing Request", 1);
  212. // Set activity fields
  213. $activity->criteria_achieved = Input::get('criteria_achievement');
  214. $activity->criteria_achieved_percentage = Input::get('criteria_achieved_percentage');
  215. $activity->outcomes_attempted = json_encode($outcomes_attempted);
  216. $activity->outcomes_achieved = json_encode($outcomes_achieved);
  217. // Publish results if not a draft. That is, update the activity's course.
  218. if(Input::get('draft')==false)
  219. {
  220. // Update course
  221. $course->outcomes_achieved = json_encode($course_outcomes_achieved);
  222. $course->outcomes_attempted = json_encode($course_outcomes_attempted);
  223. $course->save();
  224. $activity->draft = false;
  225. }
  226. else
  227. {
  228. // Set draft to true
  229. $activity->draft = true;
  230. }
  231. // Save activity
  232. $activity->save();
  233. // Recalculate course outcomes
  234. $activities = DB::table('activities')
  235. ->where('course_id', $activity->course->id)
  236. ->where('draft', 0)
  237. ->get();
  238. // Check if any assessed activities remain
  239. $remainingAssessed = false;
  240. foreach ($activities as $activity1)
  241. {
  242. if($activity1->outcomes_attempted!=NULL)
  243. {
  244. $remainingAssessed =true;
  245. break;
  246. }
  247. }
  248. //If there are still evaluated activities in the course, recalculate course outcomes
  249. if(count($activities) && $remainingAssessed)
  250. {
  251. $outcomeCount = Outcome::all()->count();
  252. // Variables to hold recalculated outcomes for the course
  253. $course_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  254. $course_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  255. // For each activity
  256. foreach ($activities as $activity2)
  257. {
  258. // If activity has been assessed
  259. if($activity2->outcomes_attempted!=NULL)
  260. {
  261. // Get the achieved criteria
  262. $criteria_achievement = json_decode($activity2->criteria_achieved, true);
  263. foreach($criteria_achievement as $criterion_id=>$criterion_achieved)
  264. {
  265. // Find corresponding learning outcome;
  266. $criterion = Criterion::withTrashed()->find($criterion_id);
  267. $outcome = Outcome::find($criterion->outcome_id);
  268. // If criterion is achieved (1), add 1 to both arrays
  269. if($criterion_achieved === 1)
  270. {
  271. $course_outcomes_attempted[$outcome->id]+=1;
  272. $course_outcomes_achieved[$outcome->id]+=1;
  273. }
  274. // Else, only add to the attempted outcomes arrays
  275. elseif($criterion_achieved === 0)
  276. {
  277. $course_outcomes_attempted[$outcome->id]+=1;
  278. }
  279. }
  280. }
  281. }
  282. // Update course
  283. DB::table('courses')
  284. ->where('id', $course->id)
  285. ->update(array(
  286. 'outcomes_attempted'=> json_encode($course_outcomes_attempted),
  287. 'outcomes_achieved'=> json_encode($course_outcomes_achieved),
  288. 'updated_at' => date('Y-m-d H:i:s'))
  289. );
  290. }
  291. // Otherwise, set them all to NULL
  292. else
  293. {
  294. DB::table('courses')
  295. ->where('id', $course->id)
  296. ->update(array(
  297. 'outcomes_attempted'=> NULL,
  298. 'outcomes_achieved'=> NULL,
  299. 'updated_at' => date('Y-m-d H:i:s'))
  300. );
  301. }
  302. });
  303. });
  304. if(is_null($exception))
  305. {
  306. Session::flash('status', 'success');
  307. Session::flash('message', 'Assessment Saved. To add transforming actions click "Transforming Actions".');
  308. return action('ActivitiesController@show', array(Input::get('activity_id')));
  309. }
  310. }
  311. catch(Exception $e)
  312. {
  313. Log::info('e:'.$e);
  314. Session::flash('status', 'danger');
  315. Session::flash('message', 'Error saving assessment. Try again later.');
  316. return action('ActivitiesController@show', array(Input::get('activity_id')));
  317. }
  318. }
  319. public function deleteAssessment()
  320. {
  321. try
  322. {
  323. $exception = DB::transaction(function()
  324. {
  325. $activity = DB::table('activities')->where('id', Input::get('id'))->first();
  326. $course = DB::table('courses')->where('id', $activity->course_id)->first();
  327. // Reset results in activity
  328. DB::table('activities')
  329. ->where('id', Input::get('id'))
  330. ->update(array(
  331. 'draft' => 0,
  332. 'outcomes_attempted'=> NULL,
  333. 'outcomes_achieved'=> NULL,
  334. 'criteria_achieved'=> NULL,
  335. 'transforming_actions'=> NULL,
  336. 'assessment_comments'=> NULL,
  337. 'criteria_achieved_percentage'=> NULL,
  338. 'updated_at' => date('Y-m-d H:i:s'))
  339. );
  340. // Delete students score
  341. DB::table('assessments')->where('activity_id', $activity->id)->delete();
  342. // Recalculate course outcomes
  343. $activities = DB::table('activities')
  344. ->where('course_id', $course->id)
  345. ->where('draft', 0)
  346. ->get();
  347. // Check if any assessed activties remain
  348. $remainingAssessed = false;
  349. foreach ($activities as $activity)
  350. {
  351. if($activity->outcomes_attempted!=NULL)
  352. {
  353. $remainingAssessed =true;
  354. break;
  355. }
  356. }
  357. //If there are still evaluated activities in the course, recalculate course outcomes
  358. if(count($activities) && $remainingAssessed)
  359. {
  360. $outcomeCount = Outcome::all()->count();
  361. // Variables to hold recalculated outcomes for the course
  362. $course_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  363. $course_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  364. // For each activity
  365. foreach ($activities as $activity)
  366. {
  367. // If activity has been assessed
  368. if($activity->outcomes_attempted!=NULL)
  369. {
  370. // Get the achieved criteria
  371. $criteria_achievement = json_decode($activity->criteria_achieved, true);
  372. foreach($criteria_achievement as $criterion_id=>$criterion_achieved)
  373. {
  374. // Find corresponding learning outcome;
  375. $criterion = Criterion::withTrashed()->find($criterion_id);
  376. $outcome = Outcome::find($criterion->outcome_id);
  377. // If criterion is achieved (1), add 1 to both arrays
  378. if($criterion_achieved === 1)
  379. {
  380. $course_outcomes_attempted[$outcome->id]+=1;
  381. $course_outcomes_achieved[$outcome->id]+=1;
  382. }
  383. // Else, only add to the attempted outcomes arrays
  384. elseif($criterion_achieved === 0)
  385. {
  386. $course_outcomes_attempted[$outcome->id]+=1;
  387. }
  388. }
  389. }
  390. }
  391. // Update course
  392. DB::table('courses')
  393. ->where('id', $course->id)
  394. ->update(array(
  395. 'outcomes_attempted'=> json_encode($course_outcomes_attempted),
  396. 'outcomes_achieved'=> json_encode($course_outcomes_achieved),
  397. 'updated_at' => date('Y-m-d H:i:s'))
  398. );
  399. }
  400. // Otherwise, set them all to NULL
  401. else
  402. {
  403. DB::table('courses')
  404. ->where('id', $course->id)
  405. ->update(array(
  406. 'outcomes_attempted'=> NULL,
  407. 'outcomes_achieved'=> NULL,
  408. 'updated_at' => date('Y-m-d H:i:s'))
  409. );
  410. }
  411. });
  412. if(is_null($exception))
  413. {
  414. Session::flash('status', 'success');
  415. Session::flash('message', 'Assessment deleted.');
  416. return Redirect::back();
  417. }
  418. }
  419. catch (Exception $e)
  420. {
  421. Session::flash('status', 'danger');
  422. Session::flash('message', 'Error saving assessment. Try again later.');
  423. return Redirect::back();
  424. }
  425. }
  426. public function destroy($id)
  427. {
  428. $course = Activity::find($id)->course;
  429. if(Activity::destroy($id))
  430. {
  431. // Recalculate course outcomes
  432. $activities = $course->activities;
  433. // Check if any assessed activties remain
  434. $remainingAssessed = false;
  435. foreach ($course->activities as $activity)
  436. {
  437. if($activity->outcomes_attempted!=NULL)
  438. {
  439. $remainingAssessed =true;
  440. break;
  441. }
  442. }
  443. //If there are still evaluated activities in the course, recalculate course outcomes
  444. if(!$course->activities->isEmpty() && $remainingAssessed )
  445. {
  446. $outcomeCount = Outcome::all()->count();
  447. // Variables to hold recalculated outcomes for the course
  448. $course_outcomes_attempted = array_fill(1, $outcomeCount, 0);
  449. $course_outcomes_achieved = array_fill(1, $outcomeCount, 0);
  450. // For each activity
  451. foreach ($activities as $activity)
  452. {
  453. // If activity has been assessed
  454. if($activity->outcomes_attempted!=NULL)
  455. {
  456. // Get the achieved criteria
  457. $criteria_achievement = json_decode($activity->criteria_achieved, true);
  458. foreach($criteria_achievement as $criterion_id=>$criterion_achieved)
  459. {
  460. // Find corresponding learning outcome;
  461. $criterion = Criterion::withTrashed()->find($criterion_id);
  462. $outcome = Outcome::find($criterion->outcome_id);
  463. // If criterion is achieved (1), add 1 to both arrays
  464. if($criterion_achieved === 1)
  465. {
  466. $course_outcomes_attempted[$outcome->id]+=1;
  467. $course_outcomes_achieved[$outcome->id]+=1;
  468. }
  469. // Else, only add to the attempted outcomes arrays
  470. elseif($criterion_achieved === 0)
  471. {
  472. $course_outcomes_attempted[$outcome->id]+=1;
  473. }
  474. }
  475. }
  476. }
  477. // Update course
  478. $course->outcomes_achieved = json_encode($course_outcomes_achieved);
  479. $course->outcomes_attempted = json_encode($course_outcomes_attempted);
  480. }
  481. else
  482. {
  483. $course->outcomes_achieved = NULL;
  484. $course->outcomes_attempted = NULL;
  485. }
  486. if($course->save())
  487. {
  488. Session::flash('status', 'success');
  489. Session::flash('message', 'Activity deleted.');
  490. }
  491. else
  492. {
  493. Session::flash('status', 'danger');
  494. Session::flash('message', 'Error deleting activity. Try again later.');
  495. return Redirect::back();
  496. }
  497. return Redirect::action('CoursesController@show', array($course->id));
  498. }
  499. else
  500. {
  501. Session::flash('status', 'danger');
  502. Session::flash('message', 'Error deleting activity. Try again later.');
  503. return Redirect::back();
  504. }
  505. }
  506. public function update($id)
  507. {
  508. try
  509. {
  510. $activity = Activity::find($id);
  511. if(Input::has('update_activity_information'))
  512. {
  513. /** Validation rules */
  514. $validator = Validator::make(
  515. array(
  516. 'name' => Input::get('name'),
  517. 'description' => Input::get('description'),
  518. 'date' => Input::get('date'),
  519. ),
  520. array(
  521. 'name' => 'required|unique:activities,course_id,'.$id,
  522. 'description' => 'required|min:10',
  523. 'date' => 'required|dateFormat:Y-m-d'
  524. ),
  525. array(
  526. 'date.dateFormat'=>'The date does not match the correct format: yyyy-mm-dd.'
  527. )
  528. );
  529. /** If validation fails */
  530. if ($validator->fails())
  531. {
  532. /** Prepare error message */
  533. $message = 'Error(s) updating the Activity<ul>';
  534. foreach ($validator->messages()->all('<li>:message</li>') as $validationError)
  535. {
  536. $message.=$validationError;
  537. }
  538. $message.='</ul>';
  539. /** Send error message and old data */
  540. Session::flash('status', 'warning');
  541. Session::flash('message', $message);
  542. return Redirect::back()->withInput();
  543. }
  544. /** Update activity info */
  545. $activity->name = Input::get('name');
  546. $activity->description = Input::get('description');
  547. $activity->date = Input::get('date');
  548. }
  549. elseif(Input::has('update_transforming_actions'))
  550. {
  551. if(trim(Input::get('transforming_actions')) !="")
  552. $activity->transforming_actions = Input::get('transforming_actions');
  553. else
  554. $activity->transforming_actions = NULL;
  555. }
  556. elseif(Input::has('update_assessment_comments'))
  557. {
  558. if(trim(Input::get('assessment_comments')) !="")
  559. $activity->assessment_comments = Input::get('assessment_comments');
  560. else
  561. $activity->assessment_comments = NULL;
  562. }
  563. else
  564. {
  565. Session::flash('status', 'danger');
  566. Session::flash('message', 'Error updating Activity. Please try again later.');
  567. return Redirect::action('ActivitiesController@show', array($activity->id));
  568. }
  569. $activity->save();
  570. /** If activity is saved, send success message */
  571. Session::flash('status', 'success');
  572. Session::flash('message', 'Activity succesfully updated.');
  573. return Redirect::action('ActivitiesController@show', array($activity->id));
  574. }
  575. catch(Exception $e)
  576. {
  577. Session::flash('status', 'warning');
  578. Session::flash('message', 'Error updating Activity. Please try again later.');
  579. return Redirect::action('ActivitiesController@show', array($activity->id));
  580. }
  581. }
  582. //TODO the code in the next 2 functions is the same as the assess function except for the view returned. try to refactor this to avoid copying code.
  583. public function viewAssessment($id)
  584. {
  585. $activity = Activity::find($id);
  586. // If activity does not exist, display 404
  587. if(!$activity)
  588. App::abort('404');
  589. // Get activity's course
  590. $course = Course::where('id', '=', $activity->course_id)->firstOrFail();
  591. // If activity does not belong to the requesting user, display 403
  592. if ($course->user_id != Auth::id())
  593. App::abort('403', 'Access Forbidden');
  594. $title = 'Assessment Sheet';
  595. $students = $course->students;
  596. // Get rubric contents
  597. $rubric_contents = Rubric::select('contents')->where('id', '=', $activity->rubric_id)->get();
  598. $rubric_contents = json_decode($rubric_contents['0']->contents);
  599. $rubric = Rubric::find($activity->rubric_id);
  600. // Get results
  601. $assessments = DB::table('assessments')->where('activity_id', '=', $activity->id)->orderBy('id', 'asc')->get();
  602. // Decode the scores (blade workaround)
  603. $scores_array = array();
  604. foreach ($assessments as $index=>$assessment)
  605. {
  606. $scores_array[$assessment->id] = json_decode($assessment->scores, true);
  607. }
  608. return View::make('local.professors.view_assessment', compact('activity', 'title', 'students', 'course', 'rubric_contents', 'assessments', 'scores_array', 'rubric'));
  609. }
  610. public function printAssessment($id)
  611. {
  612. $activity = Activity::find($id);
  613. // If activity does not exist, display 404
  614. if(!$activity)
  615. App::abort('404');
  616. // Get activity's course
  617. $course = Course::where('id', '=', $activity->course_id)->firstOrFail();
  618. // If activity does not belong to the requesting user, display 403
  619. if ($course->user_id != Auth::id())
  620. App::abort('403', 'Access Forbidden');
  621. $title = 'Assessment Sheet';
  622. $students = $course->students;
  623. // Get rubric contents
  624. $rubric_contents = Rubric::select('contents')->where('id', '=', $activity->rubric_id)->get();
  625. $rubric_contents = json_decode($rubric_contents['0']->contents);
  626. $rubric = Rubric::find($activity->rubric_id);
  627. // Get results
  628. $assessments = DB::table('assessments')->where('activity_id', '=', $activity->id)->orderBy('id', 'asc')->get();
  629. // Decode the scores (blade workaround)
  630. $scores_array = array();
  631. foreach ($assessments as $index=>$assessment)
  632. {
  633. $scores_array[$assessment->id] = json_decode($assessment->scores, true);
  634. }
  635. return View::make('local.professors.print_assessment', compact('activity', 'title', 'students', 'course', 'rubric_contents', 'assessments', 'scores_array', 'rubric'));
  636. }
  637. }