Completed
Pull Request — master (#304)
by greg
22:15 queued 16:42
created

PostVotePost::setUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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", onDelete="CASCADE")
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
     * # of shares (FB, Twitter, mails...)
77
     * @ORM\Column(type="integer", nullable=false)
78
     */
79
    protected $shares = 0;
80
81
    /**
82
     * values :
83
     *          0 : draft
84
     *          1 : user confirmed
85
     *          2 : admin accepted
86
     *          9 : admin rejected
87
     *
88
     * @ORM\Column(type="integer", nullable=false)
89
     */
90
    protected $status = 0;
91
    
92
   /**
93
    * @ORM\Column(type="boolean", nullable=true)
94
    */
95
    protected $pushed = 0;
96
97
    /**
98
     * @ORM\Column(name="created_at", type="datetime")
99
     */
100
    protected $createdAt;
101
102
    /**
103
     * @ORM\Column(name="updated_at", type="datetime")
104
     */
105
    protected $updatedAt;
106
107
    public function __construct()
108
    {
109
        $this->postElements = new ArrayCollection();
110
        $this->votes = new ArrayCollection();
111
        $this->comments = new ArrayCollection();
112
    }
113
114
    /**
115
     * @PrePersist
116
     */
117
    public function createChrono()
118
    {
119
        $this->createdAt = new \DateTime("now");
120
        $this->updatedAt = new \DateTime("now");
121
    }
122
123
    /**
124
     * @PreUpdate
125
     */
126
    public function updateChrono()
127
    {
128
        $this->updatedAt = new \DateTime("now");
129
    }
130
131
    /**
132
     * @return the unknown_type
133
     */
134
    public function getId()
135
    {
136
        return $this->id;
137
    }
138
139
    /**
140
     * @param unknown_type $id
141
     */
142
    public function setId($id)
143
    {
144
        $this->id = $id;
145
146
        return $this;
147
    }
148
149
    /**
150
     * @return the unknown_type
151
     */
152
    public function getPostvote()
153
    {
154
        return $this->postvote;
155
    }
156
157
    /**
158
     * @param unknown_type $postvote
159
     */
160
    public function setPostvote($postvote)
161
    {
162
        $postvote->addPost($this);
163
        $this->postvote = $postvote;
164
165
        return $this;
166
    }
167
168
    /**
169
     * @return the unknown_type
170
     */
171
    public function getUser()
172
    {
173
        return $this->user;
174
    }
175
176
    /**
177
     * @param unknown_type $user
178
     */
179
    public function setUser($user)
180
    {
181
        $this->user = $user;
182
183
        return $this;
184
    }
185
186
    /**
187
     * @return boolean
188
     */
189
    public function getEntry()
190
    {
191
        return $this->entry;
192
    }
193
194
    /**
195
     * @param boolean $entry
196
     */
197
    public function setEntry($entry)
198
    {
199
        $this->entry = $entry;
200
201
        return $this;
202
    }
203
204
    /**
205
     * Add an entry to the post.
206
     *
207
     * @param PostVotePostEntry $postElement
208
     *
209
     * @return void
210
     */
211
    public function addPostElement($postElement)
212
    {
213
        $postElement->setPost($this);
214
        $this->postElements[] = $postElement;
215
    }
216
217
    /**
218
     * @return ArrayCollection unknown_type
219
     */
220
    public function getPostElements()
221
    {
222
        return $this->postElements;
223
    }
224
225
    /**
226
     */
227
    public function setPostElements($postElements)
228
    {
229
        $this->postElements = $postElements;
230
231
        return $this;
232
    }
233
234
    /**
235
     * Add an entry to the vote.
236
     *
237
     * @param PostVoteVote $vote
238
     *
239
     * @return void
240
     */
241
    public function addVote($vote)
242
    {
243
        $this->votes[] = $vote;
244
    }
245
246
    /**
247
     * @return the unknown_type
248
     */
249
    public function getVotes()
250
    {
251
        return $this->votes;
252
    }
253
254
    /**
255
     * @param unknown_type $votes
256
     */
257
    public function setVotes($votes)
258
    {
259
        $this->votes = $votes;
260
261
        return $this;
262
    }
263
264
    /**
265
     * Add an entry to the comment.
266
     *
267
     * @param PostVoteComment $comment
268
     *
269
     * @return void
270
     */
271
    public function addComment(PostVoteComment $comment)
272
    {
273
        //$comment->setPost($this);
274
        $this->comments[] = $comment;
275
    }
276
277
    /**
278
     * @return the unknown_type
279
     */
280
    public function getComments()
281
    {
282
        return $this->comments;
283
    }
284
285
    /**
286
     * @param unknown_type $comments
287
     */
288
    public function setComments($comments)
289
    {
290
        $this->comments = $comments;
291
292
        return $this;
293
    }
294
295
    public function addComments(ArrayCollection $comments)
296
    {
297
        foreach ($comments as $comment) {
298
            $comment->setPost($this);
299
            $this->comments->add($comment);
300
        }
301
    }
302
303
    public function removeComments(\Doctrine\Common\Collections\Collection $comments)
304
    {
305
        foreach ($comments as $comment) {
306
            $comment->setPost(null);
307
            $this->comments->removeElement($comment);
308
        }
309
    }
310
311
    /**
312
     * @return integer unknown_type
313
     */
314
    public function getShares()
315
    {
316
        return $this->shares;
317
    }
318
319
    /**
320
     * @param unknown_shares $shares
321
     */
322
    public function setShares($shares)
323
    {
324
        $this->shares = $shares;
0 ignored issues
show
Documentation Bug introduced by
It seems like $shares of type object<PlaygroundGame\Entity\unknown_shares> is incompatible with the declared type integer of property $shares.

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..

Loading history...
325
326
        return $this;
327
    }
328
329
    /**
330
     * @return integer unknown_type
331
     */
332
    public function getStatus()
333
    {
334
        return $this->status;
335
    }
336
337
    /**
338
     * @param unknown_status $status
339
     */
340
    public function setStatus($status)
341
    {
342
        $this->status = $status;
0 ignored issues
show
Documentation Bug introduced by
It seems like $status of type object<PlaygroundGame\Entity\unknown_status> is incompatible with the declared type integer of property $status.

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..

Loading history...
343
344
        return $this;
345
    }
346
    
347
   /**
348
    * @return integer
349
    */
350
    public function isPushed()
351
    {
352
        return $this->pushed;
353
    }
354
        
355
   /**
356
    * @param bool $pushed
357
    * @return PostVotePost
358
    */
359
    public function setPushed($pushed)
360
    {
361
        $this->pushed = (boolean)$pushed;
0 ignored issues
show
Documentation Bug introduced by
The property $pushed was declared of type integer, but (bool) $pushed is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
362
        return $this;
363
    }
364
365
    /**
366
     * @return the unknown_type
367
     */
368
    public function getCreatedAt()
369
    {
370
        return $this->createdAt;
371
    }
372
373
    /**
374
     * @param unknown_type $createdAt
375
     */
376
    public function setCreatedAt($createdAt)
377
    {
378
        $this->createdAt = $createdAt;
379
380
        return $this;
381
    }
382
383
    /**
384
     * @return the unknown_type
385
     */
386
    public function getUpdatedAt()
387
    {
388
        return $this->updatedAt;
389
    }
390
391
    /**
392
     * @param unknown_type $updatedAt
393
     */
394
    public function setUpdatedAt($updatedAt)
395
    {
396
        $this->updatedAt = $updatedAt;
397
398
        return $this;
399
    }
400
401
    /**
402
     * Convert the object to an array.
403
     *
404
     * @return array
405
     */
406
    public function getArrayCopy()
407
    {
408
        $obj_vars = get_object_vars($this);
409
410
        if (isset($obj_vars['postElements'])) {
411
            $obj_vars['postElements'] = $this->getPostElements()->toArray();
412
        }
413
414
        return $obj_vars;
415
    }
416
417
    /**
418
     * Convert the object to json.
419
     *
420
     * @return array
421
     */
422
    public function jsonSerialize()
423
    {
424
        return $this->getArrayCopy();
425
    }
426
427
    /**
428
     * Populate from an array.
429
     *
430
     * @param array $data
431
     */
432
    public function populate($data = array())
433
    {
434
    }
435
436
    public function setInputFilter(InputFilterInterface $inputFilter)
437
    {
438
        throw new \Exception("Not used");
439
    }
440
441
    public function getInputFilter()
442
    {
443
        if (!$this->inputFilter) {
444
            $inputFilter = new InputFilter();
445
            $factory = new InputFactory();
446
447
            $inputFilter->add(
448
                $factory->createInput(
449
                    array(
450
                        'name' => 'id',
451
                        'required' => true,
452
                        'filters' => array(array('name' => 'Int'))
453
                    )
454
                )
455
            );
456
457
            $this->inputFilter = $inputFilter;
458
        }
459
460
        return $this->inputFilter;
461
    }
462
463
    public function setTranslatableLocale($locale)
464
    {
465
        $this->locale = $locale;
466
    }
467
}
468