1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2014-2016 Arnaud Bienvenu |
4
|
|
|
* |
5
|
|
|
* This file is part of Kyela. |
6
|
|
|
|
7
|
|
|
* Kyela is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
|
12
|
|
|
* Kyela is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with Kyela. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Abienvenu\KyelaBundle\Entity; |
23
|
|
|
|
24
|
|
|
use Doctrine\ORM\Mapping as ORM; |
25
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Event |
29
|
|
|
* |
30
|
|
|
* @ORM\Table() |
31
|
|
|
* @ORM\Entity(repositoryClass="Abienvenu\KyelaBundle\Entity\EventRepository") |
32
|
|
|
*/ |
33
|
|
|
class Event extends Entity |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var integer |
37
|
|
|
* |
38
|
|
|
* @ORM\Column(name="id", type="integer") |
39
|
|
|
* @ORM\Id |
40
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
41
|
|
|
*/ |
42
|
|
|
private $id; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
* |
47
|
|
|
* @ORM\Column(name="name", type="string", length=255, nullable=true) |
48
|
|
|
*/ |
49
|
|
|
private $name; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
* |
54
|
|
|
* @ORM\Column(name="place", type="string", length=255, nullable=true) |
55
|
|
|
*/ |
56
|
|
|
private $place; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var \DateTime |
60
|
|
|
* |
61
|
|
|
* @ORM\Column(name="date", type="date", nullable=true) |
62
|
|
|
*/ |
63
|
|
|
private $date; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var \DateTime |
67
|
|
|
* |
68
|
|
|
* @ORM\Column(name="time", type="time", nullable=true) |
69
|
|
|
*/ |
70
|
|
|
private $time; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var string |
74
|
|
|
* |
75
|
|
|
* @ORM\Column(name="subtitle", type="string", length=255, nullable=true) |
76
|
|
|
*/ |
77
|
|
|
private $subtitle; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @ORM\OneToMany(targetEntity="Participation", mappedBy="event", cascade={"remove"}) |
81
|
|
|
*/ |
82
|
|
|
private $participations; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @ORM\ManyToOne(targetEntity="Poll", inversedBy="events") |
86
|
|
|
*/ |
87
|
|
|
private $poll; |
88
|
|
|
|
89
|
|
|
public function __construct() |
90
|
|
|
{ |
91
|
|
|
$this->participations = new ArrayCollection(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function __toString() |
95
|
|
|
{ |
96
|
|
|
return $this->name; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get id |
101
|
|
|
* |
102
|
|
|
* @return integer |
103
|
|
|
*/ |
104
|
|
|
public function getId() |
105
|
|
|
{ |
106
|
|
|
return $this->id; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Set name |
111
|
|
|
* |
112
|
|
|
* @param string $name |
113
|
|
|
* @return Event |
114
|
|
|
*/ |
115
|
|
|
public function setName($name) |
116
|
|
|
{ |
117
|
|
|
$this->name = $name; |
118
|
|
|
|
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get name |
124
|
|
|
* |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function getName() |
128
|
|
|
{ |
129
|
|
|
return $this->name; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Set place |
134
|
|
|
* |
135
|
|
|
* @param string $place |
136
|
|
|
* @return Event |
137
|
|
|
*/ |
138
|
|
|
public function setPlace($place) |
139
|
|
|
{ |
140
|
|
|
$this->place = $place; |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Get place |
147
|
|
|
* |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
public function getPlace() |
151
|
|
|
{ |
152
|
|
|
return $this->place; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Add participations |
158
|
|
|
* |
159
|
|
|
* @param Participation $participations |
160
|
|
|
* @return Event |
161
|
|
|
*/ |
162
|
|
|
public function addParticipation(Participation $participations) |
163
|
|
|
{ |
164
|
|
|
$this->participations[] = $participations; |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Remove participations |
171
|
|
|
* |
172
|
|
|
* @param Participation $participations |
173
|
|
|
*/ |
174
|
|
|
public function removeParticipation(Participation $participations) |
175
|
|
|
{ |
176
|
|
|
$this->participations->removeElement($participations); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Get participations |
181
|
|
|
* |
182
|
|
|
* @return \Doctrine\Common\Collections\Collection |
183
|
|
|
*/ |
184
|
|
|
public function getParticipations() |
185
|
|
|
{ |
186
|
|
|
return $this->participations; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Get participations score |
191
|
|
|
*/ |
192
|
|
|
public function getParticipationsScore() |
193
|
|
|
{ |
194
|
|
|
$score = 0; |
195
|
|
|
foreach ($this->participations as $participation) |
196
|
|
|
{ |
197
|
|
|
$score += $participation->getChoice()->getValue(); |
198
|
|
|
} |
199
|
|
|
return $score; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Set poll |
204
|
|
|
* |
205
|
|
|
* @param Poll $poll |
206
|
|
|
* @return Event |
207
|
|
|
*/ |
208
|
|
|
public function setPoll(Poll $poll = null) |
209
|
|
|
{ |
210
|
|
|
$this->poll = $poll; |
211
|
|
|
|
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Get poll |
217
|
|
|
* |
218
|
|
|
* @return Poll |
219
|
|
|
*/ |
220
|
|
|
public function getPoll() |
221
|
|
|
{ |
222
|
|
|
return $this->poll; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Set date |
227
|
|
|
* |
228
|
|
|
* @param \DateTime $date |
229
|
|
|
* @return Event |
230
|
|
|
*/ |
231
|
|
|
public function setDate($date) |
232
|
|
|
{ |
233
|
|
|
$this->date = $date; |
234
|
|
|
|
235
|
|
|
return $this; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Get date |
240
|
|
|
* |
241
|
|
|
* @return \DateTime |
242
|
|
|
*/ |
243
|
|
|
public function getDate() |
244
|
|
|
{ |
245
|
|
|
return $this->date; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Set time |
250
|
|
|
* |
251
|
|
|
* @param \DateTime $time |
252
|
|
|
* @return Event |
253
|
|
|
*/ |
254
|
|
|
public function setTime($time) |
255
|
|
|
{ |
256
|
|
|
$this->time = $time; |
257
|
|
|
|
258
|
|
|
return $this; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Get time |
263
|
|
|
* |
264
|
|
|
* @return \DateTime |
265
|
|
|
*/ |
266
|
|
|
public function getTime() |
267
|
|
|
{ |
268
|
|
|
return $this->time; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @return string |
273
|
|
|
*/ |
274
|
|
|
public function getSubtitle() |
275
|
|
|
{ |
276
|
|
|
return $this->subtitle; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @param string $subtitle |
281
|
|
|
* @return Event |
282
|
|
|
*/ |
283
|
|
|
public function setSubtitle($subtitle) |
284
|
|
|
{ |
285
|
|
|
$this->subtitle = $subtitle; |
286
|
|
|
return $this; |
287
|
|
|
} |
288
|
|
|
} |
289
|
|
|
|