Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. class Course extends Eloquent
  3. {
  4. protected $fillable = array('name', 'code', 'number', 'section', 'program_id', 'user_id', 'semester_id');
  5. public function program()
  6. {
  7. return $this->belongsTo('Program');
  8. }
  9. public function students()
  10. {
  11. return $this->belongsToMany('Student')->orderBy('name', 'asc')->withTimestamps();
  12. }
  13. public function user()
  14. {
  15. return $this->belongsTo('User')->orderBy('surnames', 'asc')->orderBy('first_name', 'asc');
  16. }
  17. public function activities()
  18. {
  19. return $this->hasMany('Activity')->orderBy('date', 'asc');
  20. }
  21. public function assessedActivities()
  22. {
  23. return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->orderBy('date', 'asc');
  24. }
  25. public function publishedActivities()
  26. {
  27. return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->where('activities.draft', 0)->orderBy('date', 'asc');
  28. }
  29. public function semester()
  30. {
  31. return $this->belongsTo('Semester');
  32. }
  33. public function sectionsWithOutcome($outcome_id)
  34. {
  35. return Course::has('activities')->with(array('activities'=>function($query) use (&$outcome_id){
  36. $query->where('outcomes_attempted', 'not like', '\'%"'.$outcome_id.'":0%\'');
  37. }))->where('code',$this->code)->where('number',$this->number)->get();
  38. }
  39. }