Нет описания

StudentsController.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. class StudentsController extends \BaseController {
  3. public function show($semester_id, $course_identifier, $number)
  4. {
  5. $student = Student::where('number', '=', $number)->first();
  6. $code = substr($course_identifier, 0, 4);
  7. $number = substr($course_identifier, 4, 4);
  8. $section = substr($course_identifier, 9, 4);
  9. $course = Course::where('code', $code)->where('number', $number)->where('section', $section)->where('semester_id', $semester_id)->first();
  10. $title = $student->name;
  11. $activities = $course->assessedActivities;
  12. $activitiesArray = array();
  13. foreach ($activities as $activity)
  14. {
  15. $activitiesArray[]=$activity->id;
  16. }
  17. // If the student has be assessed
  18. if(!$activities->isEmpty())
  19. {
  20. // Get the assessments
  21. $assessments = DB::table('assessments')->whereIn('activity_id', $activitiesArray)->where('student_id', '=', $student->id)->orderBy('created_at')->get();
  22. // foreach ($assessments as $assessed_activity)
  23. // {
  24. // $outcomes_achieved = array_fill(1, Outcome::all()->count(), 0);
  25. // $outcomes_attempted = array_fill(1, Outcome::all()->count(), 0);
  26. // $single_activity_scores = json_decode($assessed_activity->scores);
  27. // foreach($single_activity_scores as $criterion_id => $criterion_score)
  28. // {
  29. // // Find corresponding learning outcome;
  30. // $criterion = Criterion::withTrashed()->find($criterion_id);
  31. // $outcome = Outcome::find($criterion->outcome_id);
  32. // // If criterion is achieved (1), add 1 to all arrays
  33. // if($criterion_score >= Rubric::find($activity->rubric_id)->expected_points)
  34. // {
  35. // $outcomes_attempted[$outcome->id]+=1;
  36. // $outcomes_achieved[$outcome->id]+=1;;
  37. // }
  38. // // Else, only add to the attempted outcomes array
  39. // else
  40. // {
  41. // $outcomes_attempted[$outcome->id]+=1;
  42. // }
  43. // }
  44. // $outcomes_per_activity = array_fill(1, Outcome::all()->count(), 0);
  45. // foreach ($outcomes_attempted as $index=>$outcome_attempted)
  46. // {
  47. // if($outcomes_attempted[$index]!=0)
  48. // {
  49. // // For each outcome in the activity, calculate and save the percentage
  50. // $outcomes_per_activity[$index] = (float)$outcomes_achieved[$index]/$outcomes_attempted[$index]*100;
  51. // }
  52. // }
  53. // //Save to activity array
  54. // $activitiesArray[]=$outcomes_per_activity;
  55. // }
  56. }
  57. else
  58. $assessments = NULL;
  59. return View::make('local.professors.student', compact('student', 'course', 'title', 'assessments'));
  60. }
  61. public function printStudentReport($semester_id, $course_identifier, $number)
  62. {
  63. $student = Student::where('number', '=', $number)->first();
  64. $code = substr($course_identifier, 0, 4);
  65. $number = substr($course_identifier, 4, 4);
  66. $section = substr($course_identifier, 9, 4);
  67. $course = Course::where('code', $code)->where('number', $number)->where('section', $section)->where('semester_id', $semester_id)->first();
  68. $title = $student->name;
  69. $activities = $course->assessedActivities;
  70. $activitiesArray = array();
  71. foreach ($activities as $activity)
  72. {
  73. $activitiesArray[]=$activity->id;
  74. }
  75. if(!$activities->isEmpty())
  76. {
  77. $assessments = DB::table('assessments')->whereIn('activity_id', $activitiesArray)->where('student_id', '=', $student->id)->get();
  78. foreach ($assessments as $assessed_activity)
  79. {
  80. $outcomes_achieved = array_fill(1, Outcome::all()->count(), 0);
  81. $outcomes_attempted = array_fill(1, Outcome::all()->count(), 0);
  82. $single_activity_scores = json_decode($assessed_activity->scores);
  83. foreach($single_activity_scores as $criterion_id=>$criterion_score)
  84. {
  85. // Find corresponding learning outcome;
  86. $criterion = Criterion::withTrashed()->find($criterion_id);
  87. $outcome = Outcome::find($criterion->outcome_id);
  88. // If criterion is achieved (1), add 1 to all arrays
  89. if($criterion_score >= Rubric::find($activity->rubric_id)->expected_points)
  90. {
  91. $outcomes_attempted[$outcome->id]+=1;
  92. $outcomes_achieved[$outcome->id]+=1;;
  93. }
  94. // Else, only add to the attempted outcomes array
  95. else
  96. {
  97. $outcomes_attempted[$outcome->id]+=1;
  98. }
  99. }
  100. $outcomes_per_activity = array_fill(1, Outcome::all()->count(), 0);
  101. foreach ($outcomes_attempted as $index=>$outcome_attempted)
  102. {
  103. if($outcomes_attempted[$index]!=0)
  104. {
  105. // For each outcome in the activity, calculate and save the percentage
  106. $outcomes_per_activity[$index] = (float)$outcomes_achieved[$index]/$outcomes_attempted[$index]*100;
  107. }
  108. }
  109. //Save to activity array
  110. $activitiesArray[]=$outcomes_per_activity;
  111. }
  112. }
  113. else
  114. $assessments = NULL;
  115. return View::make('local.professors.print_student_report', compact('student', 'course', 'title', 'assessments', 'activitiesArray'));
  116. }
  117. }