Completed
Push — master ( 58523e...56a418 )
by greg
37:25 queued 34:17
created

PostVoteComment::addVote()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace PlaygroundGame\Entity;
3
4
use Doctrine\Common\Collections\ArrayCollection;
5
use Doctrine\ORM\Mapping as ORM;
6
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
7
use Doctrine\ORM\Mapping\PrePersist;
8
use Doctrine\ORM\Mapping\PreUpdate;
9
use Zend\InputFilter\InputFilter;
10
use Zend\InputFilter\InputFilterAwareInterface;
11
use Zend\InputFilter\InputFilterInterface;
12
13
/**
14
 * @ORM\Entity @HasLifecycleCallbacks
15
 * @ORM\Table(name="game_postvote_comment")
16
 */
17
class PostVoteComment implements InputFilterAwareInterface, \JsonSerializable
18
{
19
    protected $inputFilter;
20
21
    /**
22
     * @ORM\Id
23
     * @ORM\Column(type="integer");
24
     * @ORM\GeneratedValue(strategy="AUTO")
25
     */
26
    protected $id;
27
28
    /**
29
     * @ORM\ManyToOne(targetEntity="PostVotePost", inversedBy="comments")
30
     * @ORM\JoinColumn(name="post_id", referencedColumnName="id", onDelete="CASCADE")
31
     **/
32
    protected $post;
33
34
    /**
35
     * @ORM\ManyToOne(targetEntity="PostVote")
36
     **/
37
    protected $postvote;
38
39
    /**
40
     * @ORM\OneToMany(targetEntity="PostVoteVote", mappedBy="postComment")
41
     * @ORM\OrderBy({"createdAt" = "DESC"})
42
     */
43
    private $votes;
44
45
    /**
46
     * @ORM\ManyToOne(targetEntity="PlaygroundUser\Entity\User")
47
     * @ORM\JoinColumn(name="user_id", referencedColumnName="user_id", onDelete="CASCADE")
48
     **/
49
    protected $user;
50
51
    /**
52
     * @ORM\Column(type="text", nullable=true)
53
     */
54
    protected $ip;
55
56
    /**
57
     * @ORM\Column(type="text", nullable=true)
58
     */
59
    protected $message;
60
61
    /**
62
     * @ORM\Column(type="text", nullable=true)
63
     */
64
    protected $category;
65
66
    /**
67
     * @ORM\Column(name="created_at", type="datetime")
68
     */
69
    protected $createdAt;
70
71
    /**
72
     * @ORM\Column(name="updated_at", type="datetime")
73
     */
74
    protected $updatedAt;
75
76
    public function __construct()
77
    {
78
        $this->votes = new ArrayCollection();
79
    }
80
81
    /** @PrePersist */
82
    public function createChrono()
83
    {
84
        $this->createdAt = new \DateTime("now");
85
        $this->updatedAt = new \DateTime("now");
86
    }
87
88
    /** @PreUpdate */
89
    public function updateChrono()
90
    {
91
        $this->updatedAt = new \DateTime("now");
92
    }
93
94
    /**
95
     * @return the unknown_type
96
     */
97
    public function getId()
98
    {
99
        return $this->id;
100
    }
101
102
    /**
103
     * @param unknown_type $id
104
     */
105
    public function setId($id)
106
    {
107
        $this->id = $id;
108
109
        return $this;
110
    }
111
112
    /**
113
     * @return string unknown_type
114
     */
115
    public function getIp()
116
    {
117
        return $this->ip;
118
    }
119
120
    /**
121
     * @param string $ip
122
     */
123
    public function setIp($ip)
124
    {
125
        $this->ip = $ip;
126
127
        return $this;
128
    }
129
130
    /**
131
     * @return the unknown_type
132
     */
133
    public function getUser()
134
    {
135
        return $this->user;
136
    }
137
138
    /**
139
     * @param unknown_type $user
140
     */
141
    public function setUser($user)
142
    {
143
        $this->user = $user;
144
145
        return $this;
146
    }
147
148
    /**
149
     * @return the unknown_type
150
     */
151
    public function getPost()
152
    {
153
        return $this->post;
154
    }
155
156
    /**
157
     * @param unknown_type $post
158
     */
159
    public function setPost($post)
160
    {
161
        // Check that there is no drawback using the cascading update from PostVoteEntry
162
        $post->addComment($this);
163
        $this->post = $post;
164
165
        return $this;
166
    }
167
168
    /**
169
     * @return the unknown_type
170
     */
171
    public function getPostvote()
172
    {
173
        return $this->postvote;
174
    }
175
176
    /**
177
     * @param unknown_type $postvote
178
     */
179
    public function setPostvote($postvote)
180
    {
181
        $this->postvote = $postvote;
182
183
        return $this;
184
    }
185
186
    /**
187
     * Add an entry to the vote.
188
     *
189
     * @param PostVoteVote $vote
190
     *
191
     * @return void
192
     */
193
    public function addVote($vote)
194
    {
195
        $this->votes[] = $vote;
196
    }
197
198
    /**
199
     * @return the unknown_type
200
     */
201
    public function getVotes()
202
    {
203
        return $this->votes;
204
    }
205
206
    /**
207
     * @param unknown_type $votes
208
     */
209
    public function setVotes($votes)
210
    {
211
        $this->votes = $votes;
212
213
        return $this;
214
    }
215
216
    /**
217
    * @return the unknown_type
218
    */
219
    public function getMessage()
220
    {
221
        return $this->message;
222
    }
223
224
    /**
225
     * @param unknown_type $message
226
     */
227
    public function setMessage($message)
228
    {
229
        $this->message = $message;
230
231
        return $this;
232
    }
233
234
    /**
235
    * @return the unknown_type
236
    */
237
    public function getCategory()
238
    {
239
        return $this->category;
240
    }
241
242
    /**
243
     * @param unknown_type $category
244
     */
245
    public function setCategory($category)
246
    {
247
        $this->category = $category;
248
249
        return $this;
250
    }
251
    /**
252
     * @return the unknown_type
253
     */
254
    public function getCreatedAt()
255
    {
256
        return $this->createdAt;
257
    }
258
259
    /**
260
     * @param unknown_type $createdAt
261
     */
262
    public function setCreatedAt($createdAt)
263
    {
264
        $this->createdAt = $createdAt;
265
266
        return $this;
267
    }
268
269
    /**
270
     * @return the unknown_type
271
     */
272
    public function getUpdatedAt()
273
    {
274
        return $this->updatedAt;
275
    }
276
277
    /**
278
     * @param unknown_type $updatedAt
279
     */
280
    public function setUpdatedAt($updatedAt)
281
    {
282
        $this->updatedAt = $updatedAt;
283
284
        return $this;
285
    }
286
287
    /**
288
     * Convert the object to an array.
289
     *
290
     * @return array
291
     */
292
    public function getArrayCopy()
293
    {
294
        $obj_vars = get_object_vars($this);
295
296
        return $obj_vars;
297
    }
298
    
299
    /**
300
     * Convert the object to json.
301
     *
302
     * @return array
303
     */
304
    public function jsonSerialize()
305
    {
306
        return $this->getArrayCopy();
307
    }
308
309
    /**
310
     * Populate from an array.
311
     *
312
     * @param array $data
313
     */
314
    public function populate($data = array())
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
315
    {
316
    }
317
318
    public function setInputFilter(InputFilterInterface $inputFilter)
319
    {
320
        throw new \Exception("Not used");
321
    }
322
323
    public function getInputFilter()
324
    {
325
        if (!$this->inputFilter) {
326
            $inputFilter = new InputFilter();
327
328
            $this->inputFilter = $inputFilter;
329
        }
330
331
        return $this->inputFilter;
332
    }
333
}
334