Completed
Push — master ( cc9b98...5f169a )
by Louis
14s
created

Notification::getReads()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace KI\UserBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use JMS\Serializer\Annotation as JMS;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9
/**
10
 * Stocke les notifications utilisateur
11
 * @ORM\Entity
12
 * @JMS\ExclusionPolicy("all")
13
 */
14
class Notification
15
{
16
    /**
17
     * @ORM\Id
18
     * @ORM\Column(type="integer")
19
     * @ORM\GeneratedValue(strategy="AUTO")
20
     */
21
    protected $id;
22
23
    /**
24
     * Date
25
     * @ORM\Column(name="date", type="integer")
26
     * @JMS\Expose
27
     * @Assert\Type("integer")
28
     */
29
    protected $date;
30
31
    /**
32
     * Raison d'envoi (string unique)
33
     * @ORM\Column(name="reason", type="string")
34
     * @JMS\Expose
35
     * @Assert\Type("string")
36
     */
37
    protected $reason;
38
39
    /**
40
     * Titre
41
     * @ORM\Column(name="title", type="string")
42
     * @JMS\Expose
43
     * @Assert\Type("string")
44
     */
45
    protected $title;
46
47
    /**
48
     * Message
49
     * @ORM\Column(name="message", type="string")
50
     * @JMS\Expose
51
     * @Assert\Type("string")
52
     */
53
    protected $message;
54
55
    /**
56
     * Ressource : lien éventuel vers l'objet de la notification
57
     * @ORM\Column(name="resource", type="string")
58
     * @JMS\Expose
59
     * @Assert\Type("string")
60
     */
61
    protected $resource;
62
63
    /**
64
     * Mode d'envoi (to|exclude)
65
     * @ORM\Column(name="mode", type="string")
66
     * @JMS\Expose
67
     * @Assert\Type("string")
68
     */
69
    protected $mode;
70
71
    /**
72
     * Destinataire(s) ou liste d'exclusion suivant le mode d'envoi choisi
73
     * @ORM\ManyToMany(targetEntity="KI\UserBundle\Entity\User", inversedBy="notifications")
74
     * @ORM\JoinTable(name="notifications_recipient",
75
     *      joinColumns={@ORM\JoinColumn(name="notifications_id", referencedColumnName="id", onDelete="cascade")},
76
     *      inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="cascade")}
77
     * )
78
     */
79
    protected $recipients;
80
81
    /**
82
     * Personnes ayant lu la notification
83
     * @ORM\ManyToMany(targetEntity="KI\UserBundle\Entity\User", inversedBy="notificationsRead")
84
     * @ORM\JoinTable(name="notifications_read",
85
     *      joinColumns={@ORM\JoinColumn(name="notification_id", referencedColumnName="id", onDelete="cascade")},
86
     *      inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="cascade")}
87
     *  )
88
     */
89
    protected $reads;
90
91
92
93
94
95
96
97
    //===== GENERATED AUTOMATICALLY =====//
98
99
    /**
100
     * Constructor
101
     */
102
    public function __construct($reason, $title, $message, $mode = 'to', $resource = '')
103
    {
104
        $this->recipients = new \Doctrine\Common\Collections\ArrayCollection();
105
        $this->reads = new \Doctrine\Common\Collections\ArrayCollection();
106
107
        $this->setReason($reason);
108
        $this->setTitle(strip_tags($title));
109
        $this->setMessage(strip_tags($message));
110
        $this->setDate(time());
111
        $this->setMode($mode);
112
        $this->setResource($resource);
113
    }
114
115
    /**
116
     * Get id
117
     *
118
     * @return integer
119
     */
120
    public function getId()
121
    {
122
        return $this->id;
123
    }
124
125
    /**
126
     * Set date
127
     *
128
     * @param integer $date
129
     * @return Newsitem
130
     */
131
    public function setDate($date)
132
    {
133
        $this->date = $date;
134
135
        return $this;
136
    }
137
138
    /**
139
     * Get date
140
     *
141
     * @return integer
142
     */
143
    public function getDate()
144
    {
145
        return $this->date;
146
    }
147
148
    /**
149
     * Set reason
150
     *
151
     * @param string $reason
152
     * @return Notification
153
     */
154
    public function setReason($reason)
155
    {
156
        $this->reason = $reason;
157
158
        return $this;
159
    }
160
161
    /**
162
     * Get reason
163
     *
164
     * @return string
165
     */
166
    public function getReason()
167
    {
168
        return $this->reason;
169
    }
170
171
    /**
172
     * Set title
173
     *
174
     * @param string $title
175
     * @return Notification
176
     */
177
    public function setTitle($title)
178
    {
179
        $this->title = $title;
180
181
        return $this;
182
    }
183
184
    /**
185
     * Get title
186
     *
187
     * @return string
188
     */
189
    public function getTitle()
190
    {
191
        return $this->title;
192
    }
193
194
    /**
195
     * Set message
196
     *
197
     * @param string $message
198
     * @return Notification
199
     */
200
    public function setMessage($message)
201
    {
202
        $this->message = $message;
203
204
        return $this;
205
    }
206
207
    /**
208
     * Get message
209
     *
210
     * @return string
211
     */
212
    public function getMessage()
213
    {
214
        return $this->message;
215
    }
216
217
    /**
218
     * Set resource
219
     *
220
     * @param string $resource
221
     * @return Notification
222
     */
223
    public function setResource($resource)
224
    {
225
        $this->resource = $resource;
226
227
        return $this;
228
    }
229
230
    /**
231
     * Get resource
232
     *
233
     * @return string
234
     */
235
    public function getResource()
236
    {
237
        return $this->resource;
238
    }
239
240
    /**
241
     * Set mode
242
     *
243
     * @param string $mode
244
     * @return Notification
245
     */
246
    public function setMode($mode)
247
    {
248
        $this->mode = $mode;
249
250
        return $this;
251
    }
252
253
    /**
254
     * Get mode
255
     *
256
     * @return string
257
     */
258
    public function getMode()
259
    {
260
        return $this->mode;
261
    }
262
263
    /**
264
     * Add recipient
265
     *
266
     * @param \KI\UserBundle\Entity\User $recipient
267
     * @return Notification
268
     */
269
    public function addRecipient(\KI\UserBundle\Entity\User $recipient)
270
    {
271
        $this->recipients[] = $recipient;
272
273
        return $this;
274
    }
275
276
    /**
277
     * Remove recipient
278
     *
279
     * @param \KI\UserBundle\Entity\User $recipient
280
     */
281
    public function removeRecipient(\KI\UserBundle\Entity\User $recipient)
282
    {
283
        $this->recipients->removeElement($recipient);
284
    }
285
286
    /**
287
     * Get recipient
288
     *
289
     * @return \Doctrine\Common\Collections\Collection
290
     */
291
    public function getRecipients()
292
    {
293
        return $this->recipients;
294
    }
295
296
    /**
297
     * Add read
298
     *
299
     * @param \KI\UserBundle\Entity\User $read
300
     * @return Notification
301
     */
302
    public function addRead(\KI\UserBundle\Entity\User $read)
303
    {
304
        $this->reads[] = $read;
305
306
        return $this;
307
    }
308
309
    /**
310
     * Remove read
311
     *
312
     * @param \KI\UserBundle\Entity\User $read
313
     */
314
    public function removeRead(\KI\UserBundle\Entity\User $read)
315
    {
316
        $this->reads->removeElement($read);
317
    }
318
319
    /**
320
     * Get read
321
     *
322
     * @return \Doctrine\Common\Collections\Collection
323
     */
324
    public function getReads()
325
    {
326
        return $this->reads;
327
    }
328
}
329