Completed
Push — master ( 56789c...8cf686 )
by Sam
08:52
created

Association::activeSchedules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
class Association extends Model
9
{
10
    use SoftDeletes;
11
12
    protected $fillable = array('name', 'user_id', 'subdomain', 'home_image_path', 'about');
13
14
    public function user() {
15
        return $this->hasOne('User');
16
    }
17
18
    public function divisions() {
19
        return $this->hasMany('App\Division');
20
    }
21
22
    public function teams() {
23
        return $this->hasMany('App\Team');
24
    }
25
26
    public function venues() {
27
        return $this->hasMany('App\Venue');
28
    }
29
30
    public function series() {
31
        return $this->hasMany('App\Series');
32
    }
33
34
    public function schedules() {
35
        return $this->hasMany('App\Schedule');
36
    }
37
38
    public function activeSchedules() {
39
        return $this->schedules()
40
            ->where('archived', '!=', 1)
41
            ->orWhereNull('archived');
42
    }
43
44
    public function resultSubmissions() {
45
        return $this->hasMany('App\ResultSubmission');
46
    }
47
48
    public function rounds() {
49
        return $this->hasManyThrough('App\Round', 'App\Schedule', 'association_id', 'schedule_id', 'id', 'id');
50
    }
51
52
    public function activeRounds() {
53
        return $this->rounds()
54
            ->where('rounds.start_date', '>=', date('Y-m-d', strtotime('today -7 days')))
55
            ->where('rounds.start_date', '<=', date('Y-m-d', strtotime('now +7 days')) );
56
    }
57
58
    public function users() {
59
        return $this->hasManyThrough('App\User', 'App\AssociationUser', 'association_id', 'id', 'id', 'user_id');
60
    }
61
62
    public function contactSubmissions() {
63
        return $this->hasMany('App\ContactSubmission');
64
    }
65
66
    public function activeContactSubmissions() {
67
        return $this->contactSubmissions()
68
            ->where('archived', '!=', 1)
69
            ->orWhereNull('archived');
70
    }
71
72
}
73