Няма описание

StudentsController.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. class StudentsController extends \BaseController
  3. {
  4. public function show($semester_id, $course_identifier, $number)
  5. {
  6. $student = Student::where('number', '=', $number)->first();
  7. $code = substr($course_identifier, 0, 4);
  8. $number = substr($course_identifier, 4, 4);
  9. $section = substr($course_identifier, 9, 4);
  10. $course = Course::where('code', $code)->where('number', $number)->where('section', $section)->where('semester_id', $semester_id)->first();
  11. $title = $student->name;
  12. $activities = $course->assessedActivities;
  13. //$activitiesArray = array();
  14. // foreach ($activities as $activity)
  15. // {
  16. // $activitiesArray[]=$activity->id;
  17. // }
  18. // If the student has be assessed
  19. if (!$activities->isEmpty()) {
  20. // Get the assessments
  21. $assessments = [];
  22. foreach ($activities as $activity) {
  23. if ($activity->isStudentAssessed($student->id) == 0)
  24. continue;
  25. $assessments[$activity->id]['activity'] = $activity->name;
  26. $activity_criterion = DB::table('activity_criterion')
  27. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  28. ->where('activity_id', $activity->id)
  29. ->select('activity_criterion.id as ac_id', 'activity_criterion.weight')
  30. ->addSelect('criteria.*')
  31. ->get();
  32. $activity_comments = DB::table('activity_student')
  33. ->where('student_id', $student->id)
  34. ->where('activity_id', $activity->id)
  35. ->first()->comments;
  36. $sum_of_score = 0;
  37. $sum_of_weight = 0;
  38. $max_score = $activity->rubric[0]->max_score;
  39. foreach ($activity_criterion as $ac) {
  40. $assessment_score = DB::table('assessments')
  41. ->where('activity_criterion_id', $ac->ac_id)
  42. ->where('student_id', $student->id)
  43. ->first();
  44. if ($assessment_score) {
  45. Log::info($assessment_score->student_id);
  46. $assessments[$activity->id]["criteria"][$ac->id] = $ac;
  47. $sum_of_score += $ac->weight * $assessment_score->score;
  48. $sum_of_weight += $ac->weight;
  49. $assessments[$activity->id]["score"][$ac->id] = $assessment_score->score;
  50. $assessments[$activity->id]['comments'] = $activity_comments;
  51. $index_scale = ceil($assessment_score->score * $ac->num_scales / $ac->max_score) - 1;
  52. if ($index_scale == -1) $index_scale = 0;
  53. $assessments[$activity->id]["explication"][$ac->id] = DB::table('criterion_scale')
  54. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  55. ->where("criterion_id", $ac->id)
  56. ->where("position", $index_scale)
  57. ->first()
  58. ->description;
  59. } else {
  60. $assessments[$activity->id]["criteria"][$ac->id] = $ac;
  61. $assessments[$activity->id]["score"][$ac->id] = "N/A";
  62. $assessments[$activity->id]["explication"][$ac->id] = '';
  63. $assessments[$activity->id]['comments'] = '';
  64. }
  65. }
  66. if ($sum_of_weight != 0)
  67. $assessments[$activity->id]['percentage'] = round((100 * ($sum_of_score / ($max_score * $sum_of_weight))), 2);
  68. else
  69. $assessments[$activity->id]['percentage'] = 0;
  70. }
  71. //$assessments = DB::table('assessments')->whereIn('activity_id', $activitiesArray)->where('student_id', '=', $student->id)->orderBy('created_at')->get();
  72. // foreach ($assessments as $assessed_activity)
  73. // {
  74. // $outcomes_achieved = array_fill(1, Outcome::all()->count(), 0);
  75. // $outcomes_attempted = array_fill(1, Outcome::all()->count(), 0);
  76. // $single_activity_scores = json_decode($assessed_activity->scores);
  77. // foreach($single_activity_scores as $criterion_id => $criterion_score)
  78. // {
  79. // // Find corresponding learning outcome;
  80. // $criterion = Criterion::withTrashed()->find($criterion_id);
  81. // $outcome = Outcome::find($criterion->outcome_id);
  82. // // If criterion is achieved (1), add 1 to all arrays
  83. // if($criterion_score >= Rubric::find($activity->rubric_id)->expected_points)
  84. // {
  85. // $outcomes_attempted[$outcome->id]+=1;
  86. // $outcomes_achieved[$outcome->id]+=1;;
  87. // }
  88. // // Else, only add to the attempted outcomes array
  89. // else
  90. // {
  91. // $outcomes_attempted[$outcome->id]+=1;
  92. // }
  93. // }
  94. // $outcomes_per_activity = array_fill(1, Outcome::all()->count(), 0);
  95. // foreach ($outcomes_attempted as $index=>$outcome_attempted)
  96. // {
  97. // if($outcomes_attempted[$index]!=0)
  98. // {
  99. // // For each outcome in the activity, calculate and save the percentage
  100. // $outcomes_per_activity[$index] = (float)$outcomes_achieved[$index]/$outcomes_attempted[$index]*100;
  101. // }
  102. // }
  103. // //Save to activity array
  104. // $activitiesArray[]=$outcomes_per_activity;
  105. // }
  106. } else
  107. $assessments = NULL;
  108. Log::info($assessments);
  109. return View::make('local.professors.student', compact('student', 'course', 'title', 'assessments'));
  110. }
  111. public function printStudentReport($semester_id, $course_identifier, $number)
  112. {
  113. /*$student = Student::where('number', '=', $number)->first();
  114. $code = substr($course_identifier, 0, 4);
  115. $number = substr($course_identifier, 4, 4);
  116. $section = substr($course_identifier, 9, 4);
  117. $course = Course::where('code', $code)->where('number', $number)->where('section', $section)->where('semester_id', $semester_id)->first();
  118. $title = $student->name;
  119. $activities = $course->assessedActivities;
  120. $activitiesArray = array();
  121. foreach ($activities as $activity) {
  122. $activitiesArray[] = $activity->id;
  123. }
  124. if (!$activities->isEmpty()) {
  125. $assessments = DB::table('assessments')->whereIn('activity_id', $activitiesArray)->where('student_id', '=', $student->id)->get();
  126. foreach ($assessments as $assessed_activity) {
  127. $outcomes_achieved = array_fill(1, Outcome::all()->count(), 0);
  128. $outcomes_attempted = array_fill(1, Outcome::all()->count(), 0);
  129. $single_activity_scores = json_decode($assessed_activity->scores);
  130. foreach ($single_activity_scores as $criterion_id => $criterion_score) {
  131. // Find corresponding learning outcome;
  132. $criterion = Criterion::withTrashed()->find($criterion_id);
  133. $outcome = Outcome::find($criterion->outcome_id);
  134. // If criterion is achieved (1), add 1 to all arrays
  135. if ($criterion_score >= Rubric::find($activity->rubric_id)->expected_points) {
  136. $outcomes_attempted[$outcome->id] += 1;
  137. $outcomes_achieved[$outcome->id] += 1;;
  138. }
  139. // Else, only add to the attempted outcomes array
  140. else {
  141. $outcomes_attempted[$outcome->id] += 1;
  142. }
  143. }
  144. $outcomes_per_activity = array_fill(1, Outcome::all()->count(), 0);
  145. foreach ($outcomes_attempted as $index => $outcome_attempted) {
  146. if ($outcomes_attempted[$index] != 0) {
  147. // For each outcome in the activity, calculate and save the percentage
  148. $outcomes_per_activity[$index] = (float)$outcomes_achieved[$index] / $outcomes_attempted[$index] * 100;
  149. }
  150. }
  151. //Save to activity array
  152. $activitiesArray[] = $outcomes_per_activity;
  153. }
  154. } else
  155. $assessments = NULL;
  156. */
  157. $student = Student::where('number', '=', $number)->first();
  158. $code = substr($course_identifier, 0, 4);
  159. $number = substr($course_identifier, 4, 4);
  160. $section = substr($course_identifier, 9, 4);
  161. $course = Course::where('code', $code)->where('number', $number)->where('section', $section)->where('semester_id', $semester_id)->first();
  162. $title = $student->name;
  163. $activities = $course->assessedActivities;
  164. //$activitiesArray = array();
  165. // foreach ($activities as $activity)
  166. // {
  167. // $activitiesArray[]=$activity->id;
  168. // }
  169. // If the student has be assessed
  170. if (!$activities->isEmpty()) {
  171. // Get the assessments
  172. $assessments = [];
  173. foreach ($activities as $activity) {
  174. if ($activity->isStudentAssessed($student->id) == 0)
  175. continue;
  176. $assessments[$activity->id]['activity'] = $activity->name;
  177. $activity_criterion = DB::table('activity_criterion')
  178. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  179. ->where('activity_id', $activity->id)
  180. ->select('activity_criterion.id as ac_id', 'activity_criterion.weight')
  181. ->addSelect('criteria.*')
  182. ->get();
  183. $activity_comments = DB::table('activity_student')
  184. ->where('student_id', $student->id)
  185. ->where('activity_id', $activity->id)
  186. ->first()->comments;
  187. $sum_of_score = 0;
  188. $sum_of_weight = 0;
  189. $max_score = $activity->rubric[0]->max_score;
  190. foreach ($activity_criterion as $ac) {
  191. $assessment_score = DB::table('assessments')
  192. ->where('activity_criterion_id', $ac->ac_id)
  193. ->where('student_id', $student->id)
  194. ->first();
  195. if ($assessment_score) {
  196. Log::info($assessment_score->student_id);
  197. $assessments[$activity->id]["criteria"][$ac->id] = $ac;
  198. $sum_of_score += $ac->weight * $assessment_score->score;
  199. $sum_of_weight += $ac->weight;
  200. $assessments[$activity->id]["score"][$ac->id] = $assessment_score->score;
  201. $assessments[$activity->id]['comments'] = $activity_comments;
  202. $index_scale = ceil($assessment_score->score * $ac->num_scales / $ac->max_score) - 1;
  203. if ($index_scale == -1) $index_scale = 0;
  204. $assessments[$activity->id]["explication"][$ac->id] = DB::table('criterion_scale')
  205. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  206. ->where("criterion_id", $ac->id)
  207. ->where("position", $index_scale)
  208. ->first()
  209. ->description;
  210. } else {
  211. $assessments[$activity->id]["criteria"][$ac->id] = $ac;
  212. $assessments[$activity->id]["score"][$ac->id] = "N/A";
  213. $assessments[$activity->id]["explication"][$ac->id] = '';
  214. $assessments[$activity->id]['comments'] = '';
  215. }
  216. }
  217. if ($sum_of_weight != 0)
  218. $assessments[$activity->id]['percentage'] = round((100 * ($sum_of_score / ($max_score * $sum_of_weight))), 2);
  219. else
  220. $assessments[$activity->id]['percentage'] = 0;
  221. }
  222. } else
  223. $assessments = NULL;
  224. return View::make(
  225. 'local.professors.print_student_report',
  226. // compact('student', 'course', 'title', 'assessments', 'activitiesArray'))
  227. compact('student', 'course', 'title', 'assessments')
  228. );
  229. }
  230. }