123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?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 = 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;
-
- 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;
-
- return View::make('local.professors.print_student_report', compact('student', 'course', 'title', 'assessments', 'activitiesArray'));
- }
- }
|