123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
-
- class Course extends Eloquent
- {
-
- protected $fillable = array('name', 'code', 'number', 'section', 'program_id', 'user_id', 'semester_id');
-
- public function program()
- {
- return $this->belongsTo('Program');
- }
-
- public function students()
- {
- return $this->belongsToMany('Student')->orderBy('name', 'asc')->withTimestamps();
- }
-
- public function user()
- {
- return $this->belongsTo('User')->orderBy('surnames', 'asc')->orderBy('first_name', 'asc');
- }
-
- // TODO: Remove
- public function activities()
- {
- return $this->hasMany('Activity')->orderBy('date', 'asc');
- }
-
- public function activity()
- {
- return $this->belongsTo('Activity');
- }
-
- public function assessedActivities()
- {
- return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->orderBy('date', 'asc');
- }
-
- public function publishedActivities()
- {
- return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->where('activities.draft', 0)->orderBy('date', 'asc');
- }
-
- public function outcomes_attempted()
- {
- return DB::table('courses')
- ->join('activities', 'activities.course_id', '=', 'courses.id')
- ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
- ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- ->where('courses.id', '=', $this->id)
- ->select('criterion_objective_outcome.outcome_id')
- ->distinct()
- ->orderBy('criterion_objective_outcome.outcome_id')
- ->get();
-
- // SELECT distinct cr.outcome_id FROM courses c, activities a, activity_criterion ac, criteria cr WHERE c.id=a.course_id and a.id=ac.activity_id and ac.criterion_id=cr.id and c.id=1
- // return $this->id;
- }
-
- public function outcomes_achieved()
- {
- $criteria = DB::table('criteria')
- ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
- ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
- ->join('courses', 'activities.course_id', '=', 'courses.id')
- ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- ->where('courses.id', '=', $this->id)
- ->select('criteria.id', 'expected_percentage_students_achieving', 'activity_criterion.activity_id')
- ->distinct()
- ->get();
-
- $conteo = 0;
- foreach ($criteria as $criterion) {
- $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
- $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
-
- if ($students_attempted) {
- $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
- } else {
- $percentage_students_who_achieved = 0;
- }
- if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
- $conteo++;
- }
- }
- return $conteo;
- }
-
- public function semester()
- {
- return $this->belongsTo('Semester');
- }
-
- public function sectionsWithOutcome($outcome_id)
- {
- return Course::has('activities')->with(array('activities' => function ($query) use (&$outcome_id) {
- $query->where('outcomes_attempted', 'not like', '\'%"' . $outcome_id . '":0%\'');
- }))->where('code', $this->code)->where('number', $this->number)->get();
- }
- }
|