Completed
Push — develop ( b3b9d6...b879cb )
by greg
19:23 queued 20s
created

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