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'); } public function activities() { return $this->hasMany('Activity')->orderBy('date', 'asc'); } 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 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(); } }