123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
-
- class StudentsController extends \BaseController
- {
-
- public function show($semester_id, $course_identifier, $number)
- {
-
- $student = Student::where('number', '=', $number)->first();
- $code = substr($course_identifier, 0, 4);
- $number = substr($course_identifier, 4, 4);
- $section = substr($course_identifier, 9, 4);
- $course = Course::where('code', $code)->where('number', $number)->where('section', $section)->where('semester_id', $semester_id)->first();
- $title = $student->name;
-
-
- $activities = $course->assessedActivities;
- //$activitiesArray = array();
- // foreach ($activities as $activity)
- // {
- // $activitiesArray[]=$activity->id;
- // }
-
- // If the student has be assessed
- if (!$activities->isEmpty()) {
-
- // Get the assessments
- $assessments = [];
-
- foreach ($activities as $activity) {
-
- if ($activity->isStudentAssessed($student->id) == 0)
- continue;
- $assessments[$activity->id]['activity'] = $activity->name;
- $activity_criterion = DB::table('activity_criterion')
- ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
- ->where('activity_id', $activity->id)
- ->select('activity_criterion.id as ac_id', 'activity_criterion.weight')
- ->addSelect('criteria.*')
- ->get();
-
-
- $activity_comments = DB::table('activity_student')
- ->where('student_id', $student->id)
- ->where('activity_id', $activity->id)
- ->first()->comments;
- $sum_of_score = 0;
- $sum_of_weight = 0;
- $max_score = $activity->rubric[0]->max_score;
- foreach ($activity_criterion as $ac) {
-
- $assessment_score = DB::table('assessments')
- ->where('activity_criterion_id', $ac->ac_id)
- ->where('student_id', $student->id)
- ->first();
-
-
- if ($assessment_score) {
- Log::info($assessment_score->student_id);
-
- $assessments[$activity->id]["criteria"][$ac->id] = $ac;
- $sum_of_score += $ac->weight * $assessment_score->score;
- $sum_of_weight += $ac->weight;
-
- $assessments[$activity->id]["score"][$ac->id] = $assessment_score->score;
- $assessments[$activity->id]['comments'] = $activity_comments;
-
- $index_scale = ceil($assessment_score->score * $ac->num_scales / $ac->max_score) - 1;
- if ($index_scale == -1) $index_scale = 0;
-
- $assessments[$activity->id]["explication"][$ac->id] = DB::table('criterion_scale')
- ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
- ->where("criterion_id", $ac->id)
- ->where("position", $index_scale)
- ->first()
- ->description;
- } else {
- $assessments[$activity->id]["criteria"][$ac->id] = $ac;
- $assessments[$activity->id]["score"][$ac->id] = "N/A";
- $assessments[$activity->id]["explication"][$ac->id] = '';
- $assessments[$activity->id]['comments'] = '';
- }
- }
- if ($sum_of_weight != 0)
- $assessments[$activity->id]['percentage'] = round((100 * ($sum_of_score / ($max_score * $sum_of_weight))), 2);
- else
- $assessments[$activity->id]['percentage'] = 0;
- }
-
-
- //$assessments = DB::table('assessments')->whereIn('activity_id', $activitiesArray)->where('student_id', '=', $student->id)->orderBy('created_at')->get();
-
- // foreach ($assessments as $assessed_activity)
- // {
- // $outcomes_achieved = array_fill(1, Outcome::all()->count(), 0);
- // $outcomes_attempted = array_fill(1, Outcome::all()->count(), 0);
-
- // $single_activity_scores = json_decode($assessed_activity->scores);
- // foreach($single_activity_scores as $criterion_id => $criterion_score)
- // {
- // // Find corresponding learning outcome;
- // $criterion = Criterion::withTrashed()->find($criterion_id);
- // $outcome = Outcome::find($criterion->outcome_id);
-
- // // If criterion is achieved (1), add 1 to all arrays
- // if($criterion_score >= Rubric::find($activity->rubric_id)->expected_points)
- // {
- // $outcomes_attempted[$outcome->id]+=1;
- // $outcomes_achieved[$outcome->id]+=1;;
- // }
- // // Else, only add to the attempted outcomes array
- // else
- // {
- // $outcomes_attempted[$outcome->id]+=1;
- // }
- // }
-
- // $outcomes_per_activity = array_fill(1, Outcome::all()->count(), 0);
- // foreach ($outcomes_attempted as $index=>$outcome_attempted)
- // {
- // if($outcomes_attempted[$index]!=0)
- // {
- // // For each outcome in the activity, calculate and save the percentage
- // $outcomes_per_activity[$index] = (float)$outcomes_achieved[$index]/$outcomes_attempted[$index]*100;
- // }
- // }
-
- // //Save to activity array
- // $activitiesArray[]=$outcomes_per_activity;
- // }
- } else
- $assessments = NULL;
- Log::info($assessments);
-
- return View::make('local.professors.student', compact('student', 'course', 'title', 'assessments'));
- }
-
- public function printStudentReport($semester_id, $course_identifier, $number)
- {
-
- /*$student = Student::where('number', '=', $number)->first();
- $code = substr($course_identifier, 0, 4);
- $number = substr($course_identifier, 4, 4);
- $section = substr($course_identifier, 9, 4);
- $course = Course::where('code', $code)->where('number', $number)->where('section', $section)->where('semester_id', $semester_id)->first();
- $title = $student->name;
-
- $activities = $course->assessedActivities;
- $activitiesArray = array();
- foreach ($activities as $activity) {
- $activitiesArray[] = $activity->id;
- }
-
- if (!$activities->isEmpty()) {
- $assessments = DB::table('assessments')->whereIn('activity_id', $activitiesArray)->where('student_id', '=', $student->id)->get();
-
- foreach ($assessments as $assessed_activity) {
- $outcomes_achieved = array_fill(1, Outcome::all()->count(), 0);
- $outcomes_attempted = array_fill(1, Outcome::all()->count(), 0);
-
- $single_activity_scores = json_decode($assessed_activity->scores);
- foreach ($single_activity_scores as $criterion_id => $criterion_score) {
- // Find corresponding learning outcome;
- $criterion = Criterion::withTrashed()->find($criterion_id);
- $outcome = Outcome::find($criterion->outcome_id);
-
- // If criterion is achieved (1), add 1 to all arrays
- if ($criterion_score >= Rubric::find($activity->rubric_id)->expected_points) {
- $outcomes_attempted[$outcome->id] += 1;
- $outcomes_achieved[$outcome->id] += 1;;
- }
- // Else, only add to the attempted outcomes array
- else {
- $outcomes_attempted[$outcome->id] += 1;
- }
- }
-
- $outcomes_per_activity = array_fill(1, Outcome::all()->count(), 0);
- foreach ($outcomes_attempted as $index => $outcome_attempted) {
- if ($outcomes_attempted[$index] != 0) {
- // For each outcome in the activity, calculate and save the percentage
- $outcomes_per_activity[$index] = (float)$outcomes_achieved[$index] / $outcomes_attempted[$index] * 100;
- }
- }
-
- //Save to activity array
- $activitiesArray[] = $outcomes_per_activity;
- }
- } else
- $assessments = NULL;
- */
- $student = Student::where('number', '=', $number)->first();
- $code = substr($course_identifier, 0, 4);
- $number = substr($course_identifier, 4, 4);
- $section = substr($course_identifier, 9, 4);
- $course = Course::where('code', $code)->where('number', $number)->where('section', $section)->where('semester_id', $semester_id)->first();
- $title = $student->name;
-
-
- $activities = $course->assessedActivities;
- //$activitiesArray = array();
- // foreach ($activities as $activity)
- // {
- // $activitiesArray[]=$activity->id;
- // }
-
- // If the student has be assessed
- if (!$activities->isEmpty()) {
-
- // Get the assessments
- $assessments = [];
-
- foreach ($activities as $activity) {
-
- if ($activity->isStudentAssessed($student->id) == 0)
- continue;
- $assessments[$activity->id]['activity'] = $activity->name;
- $activity_criterion = DB::table('activity_criterion')
- ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
- ->where('activity_id', $activity->id)
- ->select('activity_criterion.id as ac_id', 'activity_criterion.weight')
- ->addSelect('criteria.*')
- ->get();
-
-
- $activity_comments = DB::table('activity_student')
- ->where('student_id', $student->id)
- ->where('activity_id', $activity->id)
- ->first()->comments;
- $sum_of_score = 0;
- $sum_of_weight = 0;
- $max_score = $activity->rubric[0]->max_score;
- foreach ($activity_criterion as $ac) {
-
- $assessment_score = DB::table('assessments')
- ->where('activity_criterion_id', $ac->ac_id)
- ->where('student_id', $student->id)
- ->first();
-
-
- if ($assessment_score) {
- Log::info($assessment_score->student_id);
-
- $assessments[$activity->id]["criteria"][$ac->id] = $ac;
- $sum_of_score += $ac->weight * $assessment_score->score;
- $sum_of_weight += $ac->weight;
-
- $assessments[$activity->id]["score"][$ac->id] = $assessment_score->score;
- $assessments[$activity->id]['comments'] = $activity_comments;
-
- $index_scale = ceil($assessment_score->score * $ac->num_scales / $ac->max_score) - 1;
- if ($index_scale == -1) $index_scale = 0;
-
- $assessments[$activity->id]["explication"][$ac->id] = DB::table('criterion_scale')
- ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
- ->where("criterion_id", $ac->id)
- ->where("position", $index_scale)
- ->first()
- ->description;
- } else {
- $assessments[$activity->id]["criteria"][$ac->id] = $ac;
- $assessments[$activity->id]["score"][$ac->id] = "N/A";
- $assessments[$activity->id]["explication"][$ac->id] = '';
- $assessments[$activity->id]['comments'] = '';
- }
- }
- if ($sum_of_weight != 0)
- $assessments[$activity->id]['percentage'] = round((100 * ($sum_of_score / ($max_score * $sum_of_weight))), 2);
- else
- $assessments[$activity->id]['percentage'] = 0;
- }
- } else
- $assessments = NULL;
-
-
- return View::make(
- 'local.professors.print_student_report',
- // compact('student', 'course', 'title', 'assessments', 'activitiesArray'))
- compact('student', 'course', 'title', 'assessments')
- );
- }
- }
|