1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PlaygroundGame\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Doctrine\ORM\Mapping\HasLifecycleCallbacks; |
8
|
|
|
use Doctrine\ORM\Mapping\PrePersist; |
9
|
|
|
use Doctrine\ORM\Mapping\PreUpdate; |
10
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
11
|
|
|
use Gedmo\Translatable\Translatable; |
12
|
|
|
use Zend\InputFilter\InputFilter; |
13
|
|
|
use Zend\InputFilter\Factory as InputFactory; |
14
|
|
|
use Zend\InputFilter\InputFilterAwareInterface; |
15
|
|
|
use Zend\InputFilter\InputFilterInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @ORM\Entity @HasLifecycleCallbacks |
19
|
|
|
* @ORM\Table(name="game_postvote_post") |
20
|
|
|
* @Gedmo\TranslationEntity(class="PlaygroundGame\Entity\PostVotePostTranslation") |
21
|
|
|
*/ |
22
|
|
|
class PostVotePost implements InputFilterAwareInterface, Translatable, \JsonSerializable |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @Gedmo\Locale |
26
|
|
|
* Used locale to override Translation listener`s locale |
27
|
|
|
* this is not a mapped field of entity metadata, just a simple property |
28
|
|
|
*/ |
29
|
|
|
protected $locale; |
30
|
|
|
|
31
|
|
|
protected $inputFilter; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\Id |
35
|
|
|
* @ORM\Column(type="integer"); |
36
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
37
|
|
|
*/ |
38
|
|
|
protected $id; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @ORM\ManyToOne(targetEntity="PostVote", inversedBy="posts") |
42
|
|
|
* @ORM\JoinColumn(name="postvote_id", referencedColumnName="id", onDelete="CASCADE") |
43
|
|
|
*/ |
44
|
|
|
protected $postvote; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @ORM\ManyToOne(targetEntity="PlaygroundUser\Entity\User") |
48
|
|
|
* @ORM\JoinColumn(name="user_id", referencedColumnName="user_id") |
49
|
|
|
**/ |
50
|
|
|
protected $user; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @ORM\ManyToOne(targetEntity="Entry") |
54
|
|
|
* @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="CASCADE") |
55
|
|
|
**/ |
56
|
|
|
protected $entry; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @ORM\OneToMany(targetEntity="PostVoteVote", mappedBy="post") |
60
|
|
|
* @ORM\OrderBy({"createdAt" = "DESC"}) |
61
|
|
|
*/ |
62
|
|
|
private $votes; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @ORM\OneToMany(targetEntity="PostVoteComment", mappedBy="post") |
66
|
|
|
* @ORM\OrderBy({"createdAt" = "DESC"}) |
67
|
|
|
*/ |
68
|
|
|
private $comments; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @ORM\OneToMany(targetEntity="PostVotePostElement", mappedBy="post", cascade={"persist","remove"}) |
72
|
|
|
*/ |
73
|
|
|
private $postElements; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* values : |
77
|
|
|
* 0 : draft |
78
|
|
|
* 1 : user confirmed |
79
|
|
|
* 2 : admin accepted |
80
|
|
|
* 9 : admin rejected |
81
|
|
|
* |
82
|
|
|
* @ORM\Column(type="integer", nullable=false) |
83
|
|
|
*/ |
84
|
|
|
protected $status = 0; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @ORM\Column(type="boolean", nullable=true) |
88
|
|
|
*/ |
89
|
|
|
protected $pushed = 0; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @ORM\Column(name="created_at", type="datetime") |
93
|
|
|
*/ |
94
|
|
|
protected $createdAt; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @ORM\Column(name="updated_at", type="datetime") |
98
|
|
|
*/ |
99
|
|
|
protected $updatedAt; |
100
|
|
|
|
101
|
|
|
public function __construct() |
102
|
|
|
{ |
103
|
|
|
$this->postElements = new ArrayCollection(); |
104
|
|
|
$this->votes = new ArrayCollection(); |
105
|
|
|
$this->comments = new ArrayCollection(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @PrePersist |
110
|
|
|
*/ |
111
|
|
|
public function createChrono() |
112
|
|
|
{ |
113
|
|
|
$this->createdAt = new \DateTime("now"); |
114
|
|
|
$this->updatedAt = new \DateTime("now"); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @PreUpdate |
119
|
|
|
*/ |
120
|
|
|
public function updateChrono() |
121
|
|
|
{ |
122
|
|
|
$this->updatedAt = new \DateTime("now"); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return the unknown_type |
127
|
|
|
*/ |
128
|
|
|
public function getId() |
129
|
|
|
{ |
130
|
|
|
return $this->id; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param unknown_type $id |
135
|
|
|
*/ |
136
|
|
|
public function setId($id) |
137
|
|
|
{ |
138
|
|
|
$this->id = $id; |
139
|
|
|
|
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return the unknown_type |
145
|
|
|
*/ |
146
|
|
|
public function getPostvote() |
147
|
|
|
{ |
148
|
|
|
return $this->postvote; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param unknown_type $postvote |
153
|
|
|
*/ |
154
|
|
|
public function setPostvote($postvote) |
155
|
|
|
{ |
156
|
|
|
$postvote->addPost($this); |
157
|
|
|
$this->postvote = $postvote; |
158
|
|
|
|
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return the unknown_type |
164
|
|
|
*/ |
165
|
|
|
public function getUser() |
166
|
|
|
{ |
167
|
|
|
return $this->user; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param unknown_type $user |
172
|
|
|
*/ |
173
|
|
|
public function setUser($user) |
174
|
|
|
{ |
175
|
|
|
$this->user = $user; |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return boolean |
182
|
|
|
*/ |
183
|
|
|
public function getEntry() |
184
|
|
|
{ |
185
|
|
|
return $this->entry; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param boolean $entry |
190
|
|
|
*/ |
191
|
|
|
public function setEntry($entry) |
192
|
|
|
{ |
193
|
|
|
$this->entry = $entry; |
194
|
|
|
|
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Add an entry to the post. |
200
|
|
|
* |
201
|
|
|
* @param PostVotePostEntry $postElement |
202
|
|
|
* |
203
|
|
|
* @return void |
204
|
|
|
*/ |
205
|
|
|
public function addPostElement($postElement) |
206
|
|
|
{ |
207
|
|
|
$postElement->setPost($this); |
208
|
|
|
$this->postElements[] = $postElement; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return ArrayCollection unknown_type |
213
|
|
|
*/ |
214
|
|
|
public function getPostElements() |
215
|
|
|
{ |
216
|
|
|
return $this->postElements; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
*/ |
221
|
|
|
public function setPostElements($postElements) |
222
|
|
|
{ |
223
|
|
|
$this->postElements = $postElements; |
224
|
|
|
|
225
|
|
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Add an entry to the vote. |
230
|
|
|
* |
231
|
|
|
* @param PostVoteVote $vote |
232
|
|
|
* |
233
|
|
|
* @return void |
234
|
|
|
*/ |
235
|
|
|
public function addVote($vote) |
236
|
|
|
{ |
237
|
|
|
$this->votes[] = $vote; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @return the unknown_type |
242
|
|
|
*/ |
243
|
|
|
public function getVotes() |
244
|
|
|
{ |
245
|
|
|
return $this->votes; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @param unknown_type $votes |
250
|
|
|
*/ |
251
|
|
|
public function setVotes($votes) |
252
|
|
|
{ |
253
|
|
|
$this->votes = $votes; |
254
|
|
|
|
255
|
|
|
return $this; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Add an entry to the comment. |
260
|
|
|
* |
261
|
|
|
* @param PostVoteComment $comment |
262
|
|
|
* |
263
|
|
|
* @return void |
264
|
|
|
*/ |
265
|
|
|
public function addComment(PostVoteComment $comment) |
266
|
|
|
{ |
267
|
|
|
//$comment->setPost($this); |
268
|
|
|
$this->comments[] = $comment; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @return the unknown_type |
273
|
|
|
*/ |
274
|
|
|
public function getComments() |
275
|
|
|
{ |
276
|
|
|
return $this->comments; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @param unknown_type $comments |
281
|
|
|
*/ |
282
|
|
|
public function setComments($comments) |
283
|
|
|
{ |
284
|
|
|
$this->comments = $comments; |
285
|
|
|
|
286
|
|
|
return $this; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
public function addComments(ArrayCollection $comments) |
290
|
|
|
{ |
291
|
|
|
foreach ($comments as $comment) { |
292
|
|
|
$comment->setPost($this); |
293
|
|
|
$this->comments->add($comment); |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
public function removeComments(\Doctrine\Common\Collections\Collection $comments) |
298
|
|
|
{ |
299
|
|
|
foreach ($comments as $comment) { |
300
|
|
|
$comment->setPost(null); |
301
|
|
|
$this->comments->removeElement($comment); |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @return integer unknown_type |
307
|
|
|
*/ |
308
|
|
|
public function getStatus() |
309
|
|
|
{ |
310
|
|
|
return $this->status; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @param unknown_status $status |
315
|
|
|
*/ |
316
|
|
|
public function setStatus($status) |
317
|
|
|
{ |
318
|
|
|
$this->status = $status; |
|
|
|
|
319
|
|
|
|
320
|
|
|
return $this; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @return integer |
325
|
|
|
*/ |
326
|
|
|
public function isPushed() |
327
|
|
|
{ |
328
|
|
|
return $this->pushed; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @param bool $pushed |
333
|
|
|
* @return PostVotePost |
334
|
|
|
*/ |
335
|
|
|
public function setPushed($pushed) |
336
|
|
|
{ |
337
|
|
|
$this->pushed = (boolean)$pushed; |
|
|
|
|
338
|
|
|
return $this; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @return the unknown_type |
343
|
|
|
*/ |
344
|
|
|
public function getCreatedAt() |
345
|
|
|
{ |
346
|
|
|
return $this->createdAt; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* @param unknown_type $createdAt |
351
|
|
|
*/ |
352
|
|
|
public function setCreatedAt($createdAt) |
353
|
|
|
{ |
354
|
|
|
$this->createdAt = $createdAt; |
355
|
|
|
|
356
|
|
|
return $this; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* @return the unknown_type |
361
|
|
|
*/ |
362
|
|
|
public function getUpdatedAt() |
363
|
|
|
{ |
364
|
|
|
return $this->updatedAt; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @param unknown_type $updatedAt |
369
|
|
|
*/ |
370
|
|
|
public function setUpdatedAt($updatedAt) |
371
|
|
|
{ |
372
|
|
|
$this->updatedAt = $updatedAt; |
373
|
|
|
|
374
|
|
|
return $this; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* Convert the object to an array. |
379
|
|
|
* |
380
|
|
|
* @return array |
381
|
|
|
*/ |
382
|
|
|
public function getArrayCopy() |
383
|
|
|
{ |
384
|
|
|
$obj_vars = get_object_vars($this); |
385
|
|
|
|
386
|
|
|
if (isset($obj_vars['postElements'])) { |
387
|
|
|
$obj_vars['postElements'] = $this->getPostElements()->toArray(); |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
return $obj_vars; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Convert the object to json. |
395
|
|
|
* |
396
|
|
|
* @return array |
397
|
|
|
*/ |
398
|
|
|
public function jsonSerialize() |
399
|
|
|
{ |
400
|
|
|
return $this->getArrayCopy(); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Populate from an array. |
405
|
|
|
* |
406
|
|
|
* @param array $data |
407
|
|
|
*/ |
408
|
|
|
public function populate($data = array()) |
409
|
|
|
{ |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
public function setInputFilter(InputFilterInterface $inputFilter) |
413
|
|
|
{ |
414
|
|
|
throw new \Exception("Not used"); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
public function getInputFilter() |
418
|
|
|
{ |
419
|
|
|
if (!$this->inputFilter) { |
420
|
|
|
$inputFilter = new InputFilter(); |
421
|
|
|
$factory = new InputFactory(); |
422
|
|
|
|
423
|
|
|
$inputFilter->add( |
424
|
|
|
$factory->createInput( |
425
|
|
|
array( |
426
|
|
|
'name' => 'id', |
427
|
|
|
'required' => true, |
428
|
|
|
'filters' => array(array('name' => 'Int')) |
429
|
|
|
) |
430
|
|
|
) |
431
|
|
|
); |
432
|
|
|
|
433
|
|
|
$this->inputFilter = $inputFilter; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
return $this->inputFilter; |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
public function setTranslatableLocale($locale) |
440
|
|
|
{ |
441
|
|
|
$this->locale = $locale; |
442
|
|
|
} |
443
|
|
|
} |
444
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..