Event::getStartDate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * Storgman - Student Organizations Management
5
 * Copyright (C) 2014-2016, Dejan Angelov <[email protected]>
6
 *
7
 * This file is part of Storgman.
8
 *
9
 * Storgman is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * Storgman is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with Storgman.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 * @package Storgman
23
 * @copyright Copyright (C) 2014-2016, Dejan Angelov <[email protected]>
24
 * @license https://github.com/angelov/storgman/blob/master/LICENSE
25
 * @author Dejan Angelov <[email protected]>
26
 */
27
28
namespace Angelov\Storgman\Events;
29
30
use Angelov\Storgman\Events\Comments\Comment;
31
use Angelov\Storgman\LocalCommittees\LocalCommittee;
32
use Carbon\Carbon;
33
use Illuminate\Database\Eloquent\Model;
34
35
class Event extends Model
36
{
37
    protected $table = "eestec_events";
38
    protected $dates = ['start_date', 'end_date', 'deadline'];
39
40
    public function getId()
41
    {
42
        return $this->getAttribute('id');
43
    }
44
45
    public function getTitle()
46
    {
47
        return $this->getAttribute('title');
48
    }
49
50
    public function setTitle($title)
51
    {
52
        $this->setAttribute('title', $title);
53
    }
54
55
    public function getDescription()
56
    {
57
        return $this->getAttribute('description');
58
    }
59
60
    public function setDescription($desc)
61
    {
62
        $this->setAttribute('description', $desc);
63
    }
64
65
    public function host()
66
    {
67
        return $this->belongsTo(LocalCommittee::class, 'host_id');
68
    }
69
70
    public function setHost(LocalCommittee $localCommittee)
71
    {
72
        $this->host()->associate($localCommittee);
73
    }
74
75
    /**
76
     * @return LocalCommittee
77
     */
78
    public function getHost()
79
    {
80
        return $this->getAttribute('host');
81
    }
82
83
    /**
84
     * @return Carbon
85
     */
86
    public function getStartDate()
87
    {
88
        return $this->getAttribute('start_date');
89
    }
90
91
    public function setStartDate(Carbon $date)
92
    {
93
        $this->setAttribute('start_date', $date);
94
    }
95
96
    /**
97
     * @return Carbon
98
     */
99
    public function getEndDate()
100
    {
101
        return $this->getAttribute('end_date');
102
    }
103
104
    public function setEndDate(Carbon $date)
105
    {
106
        $this->setAttribute('end_date', $date);
107
    }
108
109
    /**
110
     * @return Carbon
111
     */
112
    public function getDeadline()
113
    {
114
        return $this->getAttribute('deadline');
115
    }
116
117
    public function setDeadline(Carbon $date)
118
    {
119
        $this->setAttribute('deadline', $date);
120
    }
121
122
    public function isReceivingApplications()
123
    {
124
        return Carbon::now() < $this->getDeadline();
125
    }
126
127
    public function getUrl()
128
    {
129
        return $this->getAttribute('url');
130
    }
131
132
    public function setUrl($url)
133
    {
134
        $this->setAttribute('url', $url);
135
    }
136
137
    public function getImage()
138
    {
139
        return $this->getAttribute('image');
140
    }
141
142
    public function setImage($filename)
143
    {
144
        $this->setAttribute('image', $filename);
145
    }
146
147
    public function comments()
148
    {
149
        return $this->hasMany(Comment::class);
150
    }
151
152
    /**
153
     * @return Comment[]
154
     */
155
    public function getComments()
156
    {
157
        return $this->comments()->orderBy('created_at', 'DESC')->get()->all();
158
    }
159
160
    public function countComments()
161
    {
162
        return $this->comments()->count();
163
    }
164
165
    public function hasComments()
166
    {
167
        return $this->countComments() > 0;
168
    }
169
170
    public function equals(Event $event)
171
    {
172
        return $event->getId() === $this->getId();
173
    }
174
}
175