| 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 archivedSchedules() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         return $this->schedules() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ->where('archived', '=', 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function resultSubmissions() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         return $this->hasMany('App\ResultSubmission'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function rounds() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         return $this->hasManyThrough('App\Round', 'App\Schedule', 'association_id', 'schedule_id', 'id', 'id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     public function activeRounds() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         return $this->rounds() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             ->where('rounds.start_date', '>=', date('Y-m-d', strtotime('today -7 days'))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             ->where('rounds.start_date', '<=', date('Y-m-d', strtotime('now +7 days')) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     public function users() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         return $this->hasManyThrough('App\User', 'App\AssociationUser', 'association_id', 'id', 'id', 'user_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function contactSubmissions() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         return $this->hasMany('App\ContactSubmission'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public function activeContactSubmissions() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         return $this->contactSubmissions() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             ->where('archived', '!=', 1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             ->orWhereNull('archived'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |  |