|
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\Common\Collections\ArrayCollection; |
|
25
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
|
26
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
27
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Poll |
|
31
|
|
|
* |
|
32
|
|
|
* @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="url_idx", columns={"url"})}) |
|
33
|
|
|
* @UniqueEntity(fields={"url"}) |
|
34
|
|
|
* @ORM\Entity |
|
35
|
|
|
*/ |
|
36
|
|
|
class Poll extends Entity |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @var integer |
|
40
|
|
|
* |
|
41
|
|
|
* @ORM\Column(name="id", type="integer") |
|
42
|
|
|
* @ORM\Id |
|
43
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
44
|
|
|
*/ |
|
45
|
|
|
private $id; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var string |
|
49
|
|
|
* |
|
50
|
|
|
* @ORM\Column(name="url", type="string", length=255) |
|
51
|
|
|
* @Assert\NotBlank() |
|
52
|
|
|
*/ |
|
53
|
|
|
private $url; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var string |
|
57
|
|
|
* |
|
58
|
|
|
* @ORM\Column(name="title", type="string", length=255) |
|
59
|
|
|
* @Assert\NotBlank() |
|
60
|
|
|
*/ |
|
61
|
|
|
private $title; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @var string |
|
65
|
|
|
* |
|
66
|
|
|
* @ORM\Column(name="headLines", type="text", nullable=true) |
|
67
|
|
|
*/ |
|
68
|
|
|
private $headLines; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var string |
|
72
|
|
|
* |
|
73
|
|
|
* @ORM\Column(name="bottomLines", type="text", nullable=true) |
|
74
|
|
|
*/ |
|
75
|
|
|
private $bottomLines; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var string |
|
79
|
|
|
* |
|
80
|
|
|
* @ORM\Column(name="accessCode", type="string", length=255) |
|
81
|
|
|
*/ |
|
82
|
|
|
private $accessCode; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @ORM\OneToMany(targetEntity="Participant", mappedBy="poll", cascade={"remove"}) |
|
86
|
|
|
* @ORM\OrderBy({"priority" = "ASC"}) |
|
87
|
|
|
*/ |
|
88
|
|
|
private $participants; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @ORM\OneToMany(targetEntity="Event", mappedBy="poll", cascade={"remove"}) |
|
92
|
|
|
*/ |
|
93
|
|
|
private $events; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @ORM\OneToMany(targetEntity="Choice", mappedBy="poll", cascade={"remove", "persist"}) |
|
97
|
|
|
* @ORM\OrderBy({"priority" = "ASC"}) |
|
98
|
|
|
*/ |
|
99
|
|
|
private $choices; |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @ORM\OneToMany(targetEntity="Comment", mappedBy="poll", cascade={"remove"}) |
|
103
|
|
|
*/ |
|
104
|
|
|
private $comments; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get id |
|
108
|
|
|
* |
|
109
|
|
|
* @return integer |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getId() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->id; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Set url |
|
118
|
|
|
* |
|
119
|
|
|
* @param string $url |
|
120
|
|
|
* @return Poll |
|
121
|
|
|
*/ |
|
122
|
|
|
public function setUrl($url) |
|
123
|
|
|
{ |
|
124
|
|
|
$this->url = $url; |
|
125
|
|
|
|
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Get url |
|
131
|
|
|
* |
|
132
|
|
|
* @return string |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getUrl() |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->url; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Set title |
|
141
|
|
|
* |
|
142
|
|
|
* @param string $title |
|
143
|
|
|
* @return Poll |
|
144
|
|
|
*/ |
|
145
|
|
|
public function setTitle($title) |
|
146
|
|
|
{ |
|
147
|
|
|
$this->title = $title; |
|
148
|
|
|
|
|
149
|
|
|
return $this; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Get title |
|
154
|
|
|
* |
|
155
|
|
|
* @return string |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getTitle() |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->title; |
|
160
|
|
|
} |
|
161
|
|
|
/** |
|
162
|
|
|
* Constructor |
|
163
|
|
|
*/ |
|
164
|
|
|
public function __construct() |
|
165
|
|
|
{ |
|
166
|
|
|
$this->participants = new ArrayCollection(); |
|
167
|
|
|
$this->events = new ArrayCollection(); |
|
168
|
|
|
$this->choices = new ArrayCollection(); |
|
169
|
|
|
$this->comments = new ArrayCollection(); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Add participants |
|
174
|
|
|
* |
|
175
|
|
|
* @param Participant $participants |
|
176
|
|
|
* @return Poll |
|
177
|
|
|
*/ |
|
178
|
|
|
public function addParticipant(Participant $participants) |
|
179
|
|
|
{ |
|
180
|
|
|
$this->participants[] = $participants; |
|
181
|
|
|
|
|
182
|
|
|
return $this; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Remove participants |
|
187
|
|
|
* |
|
188
|
|
|
* @param Participant $participants |
|
189
|
|
|
*/ |
|
190
|
|
|
public function removeParticipant(Participant $participants) |
|
191
|
|
|
{ |
|
192
|
|
|
$this->participants->removeElement($participants); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Get participants |
|
197
|
|
|
* |
|
198
|
|
|
* @return \Doctrine\Common\Collections\Collection |
|
199
|
|
|
*/ |
|
200
|
|
|
public function getParticipants() |
|
201
|
|
|
{ |
|
202
|
|
|
return $this->participants; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Add events |
|
207
|
|
|
* |
|
208
|
|
|
* @param Event $events |
|
209
|
|
|
* @return Poll |
|
210
|
|
|
*/ |
|
211
|
|
|
public function addEvent(Event $events) |
|
212
|
|
|
{ |
|
213
|
|
|
$this->events[] = $events; |
|
214
|
|
|
|
|
215
|
|
|
return $this; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Remove events |
|
220
|
|
|
* |
|
221
|
|
|
* @param Event $events |
|
222
|
|
|
*/ |
|
223
|
|
|
public function removeEvent(Event $events) |
|
224
|
|
|
{ |
|
225
|
|
|
$this->events->removeElement($events); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Get events |
|
230
|
|
|
* |
|
231
|
|
|
* @return \Doctrine\Common\Collections\Collection |
|
232
|
|
|
*/ |
|
233
|
|
|
public function getEvents() |
|
234
|
|
|
{ |
|
235
|
|
|
return $this->events; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* Add choices |
|
240
|
|
|
* |
|
241
|
|
|
* @param Choice $choices |
|
242
|
|
|
* @return Poll |
|
243
|
|
|
*/ |
|
244
|
|
|
public function addChoice(Choice $choices) |
|
245
|
|
|
{ |
|
246
|
|
|
$this->choices[] = $choices; |
|
247
|
|
|
|
|
248
|
|
|
return $this; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Remove choices |
|
253
|
|
|
* |
|
254
|
|
|
* @param Choice $choices |
|
255
|
|
|
*/ |
|
256
|
|
|
public function removeChoice(Choice $choices) |
|
257
|
|
|
{ |
|
258
|
|
|
$this->choices->removeElement($choices); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Get choices |
|
263
|
|
|
* |
|
264
|
|
|
* @return \Doctrine\Common\Collections\Collection |
|
265
|
|
|
*/ |
|
266
|
|
|
public function getChoices() |
|
267
|
|
|
{ |
|
268
|
|
|
return $this->choices; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Set headLines |
|
273
|
|
|
* |
|
274
|
|
|
* @param string $headLines |
|
275
|
|
|
* @return Poll |
|
276
|
|
|
*/ |
|
277
|
|
|
public function setHeadLines($headLines) |
|
278
|
|
|
{ |
|
279
|
|
|
$this->headLines = $headLines; |
|
280
|
|
|
|
|
281
|
|
|
return $this; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* Get headLines |
|
286
|
|
|
* |
|
287
|
|
|
* @return string |
|
288
|
|
|
*/ |
|
289
|
|
|
public function getHeadLines() |
|
290
|
|
|
{ |
|
291
|
|
|
return $this->headLines; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* Set bottomLines |
|
296
|
|
|
* |
|
297
|
|
|
* @param string $bottomLines |
|
298
|
|
|
* @return Poll |
|
299
|
|
|
*/ |
|
300
|
|
|
public function setBottomLines($bottomLines) |
|
301
|
|
|
{ |
|
302
|
|
|
$this->bottomLines = $bottomLines; |
|
303
|
|
|
|
|
304
|
|
|
return $this; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* Get bottomLines |
|
309
|
|
|
* |
|
310
|
|
|
* @return string |
|
311
|
|
|
*/ |
|
312
|
|
|
public function getBottomLines() |
|
313
|
|
|
{ |
|
314
|
|
|
return $this->bottomLines; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* Set accessCode |
|
319
|
|
|
* |
|
320
|
|
|
* @param string $accessCode |
|
321
|
|
|
* @return Poll |
|
322
|
|
|
*/ |
|
323
|
|
|
public function setAccessCode($accessCode) |
|
324
|
|
|
{ |
|
325
|
|
|
$this->accessCode = $accessCode; |
|
326
|
|
|
|
|
327
|
|
|
return $this; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* Get accessCode |
|
332
|
|
|
* |
|
333
|
|
|
* @return string |
|
334
|
|
|
*/ |
|
335
|
|
|
public function getAccessCode() |
|
336
|
|
|
{ |
|
337
|
|
|
return $this->accessCode; |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* Add comments |
|
342
|
|
|
* |
|
343
|
|
|
* @param Comment $comments |
|
344
|
|
|
* @return Poll |
|
345
|
|
|
*/ |
|
346
|
|
|
public function addComment(Comment $comments) |
|
347
|
|
|
{ |
|
348
|
|
|
$this->comments[] = $comments; |
|
349
|
|
|
|
|
350
|
|
|
return $this; |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
/** |
|
354
|
|
|
* Remove comments |
|
355
|
|
|
* |
|
356
|
|
|
* @param Comment $comments |
|
357
|
|
|
*/ |
|
358
|
|
|
public function removeComment(Comment $comments) |
|
359
|
|
|
{ |
|
360
|
|
|
$this->comments->removeElement($comments); |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* Get comments |
|
365
|
|
|
* |
|
366
|
|
|
* @return \Doctrine\Common\Collections\Collection |
|
367
|
|
|
*/ |
|
368
|
|
|
public function getComments() |
|
369
|
|
|
{ |
|
370
|
|
|
return $this->comments; |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
public function getParticipantsAsArrayOfNames() |
|
374
|
|
|
{ |
|
375
|
|
|
$participants = []; |
|
376
|
|
|
foreach ($this->getParticipants() as $participant) |
|
377
|
|
|
{ |
|
378
|
|
|
$participants[$participant->getName()] = $participant->getName(); |
|
379
|
|
|
} |
|
380
|
|
|
return $participants; |
|
381
|
|
|
} |
|
382
|
|
|
} |
|
383
|
|
|
|