Sin descripción

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // TODO: Remove
  18. public function activities()
  19. {
  20. return $this->hasMany('Activity')->orderBy('date', 'asc');
  21. }
  22. public function activity()
  23. {
  24. return $this->belongsTo('Activity');
  25. }
  26. public function assessedActivities()
  27. {
  28. return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->orderBy('date', 'asc');
  29. }
  30. public function publishedActivities()
  31. {
  32. return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->where('activities.draft', 0)->orderBy('date', 'asc');
  33. }
  34. public function semester()
  35. {
  36. return $this->belongsTo('Semester');
  37. }
  38. public function sectionsWithOutcome($outcome_id)
  39. {
  40. return Course::has('activities')->with(array('activities'=>function($query) use (&$outcome_id){
  41. $query->where('outcomes_attempted', 'not like', '\'%"'.$outcome_id.'":0%\'');
  42. }))->where('code',$this->code)->where('number',$this->number)->get();
  43. }
  44. }