Hackathonners /
swap
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Judite\Models; |
||
| 4 | |||
| 5 | use Illuminate\Database\Eloquent\Model; |
||
| 6 | use Laracasts\Presenter\PresentableTrait; |
||
| 7 | use App\Judite\Presenters\CoursePresenter; |
||
| 8 | |||
| 9 | class Course extends Model |
||
| 10 | { |
||
| 11 | use PresentableTrait; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * The presenter for this entity. |
||
| 15 | * |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | protected $presenter = CoursePresenter::class; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Scope a query to order courses by year, semester and name. |
||
| 22 | * |
||
| 23 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
| 24 | * |
||
| 25 | * @return \Illuminate\Database\Eloquent\Builder |
||
| 26 | */ |
||
| 27 | public function scopeOrderedList($query) |
||
| 28 | { |
||
| 29 | return $query->orderBy('year', 'asc') |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 30 | ->orderBy('semester', 'asc') |
||
| 31 | ->orderBy('name', 'asc'); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Get shifts of this course. |
||
| 36 | * |
||
| 37 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
| 38 | */ |
||
| 39 | public function shifts() |
||
| 40 | { |
||
| 41 | return $this->hasMany(Shift::class); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Get enrollments on this course. |
||
| 46 | * |
||
| 47 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
| 48 | */ |
||
| 49 | public function enrollments() |
||
| 50 | { |
||
| 51 | return $this->hasMany(Enrollment::class); |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Add shift to this course. |
||
| 56 | * |
||
| 57 | * @param \App\Judite\Models\Shift $shift |
||
| 58 | * |
||
| 59 | * @return $this |
||
| 60 | */ |
||
| 61 | public function addShift(Shift $shift): self |
||
| 62 | { |
||
| 63 | $this->shifts()->save($shift); |
||
| 64 | |||
| 65 | return $this; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Get shift of this course by tag. |
||
| 70 | * |
||
| 71 | * @param string $tag |
||
| 72 | * |
||
| 73 | * @return \App\Judite\Models\Shift|null |
||
| 74 | */ |
||
| 75 | public function getShiftByTag($tag): ?Shift |
||
| 76 | { |
||
| 77 | return $this->shifts()->where('tag', $tag)->first(); |
||
| 78 | } |
||
| 79 | } |
||
| 80 |