Passed
Push — master ( 1a7924...8ee120 )
by Julito
11:25
created

SysAnnouncement::getRoles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Entity;
8
9
use DateTime;
10
use Doctrine\ORM\Mapping as ORM;
11
use Symfony\Component\Validator\Constraints as Assert;
12
13
/**
14
 * Portal announcements.
15
 *
16
 * @ORM\Table(name="sys_announcement")
17
 * @ORM\Entity
18
 */
19
class SysAnnouncement
20
{
21
    /**
22
     * @ORM\Column(name="id", type="integer")
23
     * @ORM\Id
24
     * @ORM\GeneratedValue()
25
     */
26
    protected int $id;
27
28
    /**
29
     * @ORM\Column(name="date_start", type="datetime", nullable=false)
30
     */
31
    protected DateTime $dateStart;
32
33
    /**
34
     * @ORM\Column(name="date_end", type="datetime", nullable=false)
35
     */
36
    protected DateTime $dateEnd;
37
38
    /**
39
     * @ORM\Column(name="visible_teacher", type="boolean", nullable=false)
40
     */
41
    protected bool $visibleTeacher;
42
43
    /**
44
     * @ORM\Column(name="visible_student", type="boolean", nullable=false)
45
     */
46
    protected bool $visibleStudent;
47
48
    /**
49
     * @ORM\Column(name="visible_guest", type="boolean", nullable=false)
50
     */
51
    protected bool $visibleGuest;
52
53
    /**
54
     * @ORM\Column(name="visible_drh", type="boolean", nullable=false)
55
     */
56
    protected bool $visibleDrh;
57
58
    /**
59
     * @ORM\Column(name="visible_session_admin", type="boolean", nullable=false)
60
     */
61
    protected bool $visibleSessionAdmin;
62
63
    /**
64
     * @ORM\Column(name="visible_boss", type="boolean", nullable=false)
65
     */
66
    protected bool $visibleBoss;
67
68
    /**
69
     * @Assert\NotBlank()
70
     *
71
     * @ORM\Column(name="title", type="string", length=250, nullable=false)
72
     */
73
    protected string $title;
74
75
    /**
76
     * @Assert\NotBlank()
77
     *
78
     * @ORM\Column(name="content", type="text", nullable=false)
79
     */
80
    protected string $content;
81
82
    /**
83
     * @ORM\Column(name="lang", type="string", length=70, nullable=true)
84
     */
85
    protected ?string $lang = null;
86
87
    /**
88
     * @ORM\ManyToOne(targetEntity="AccessUrl")
89
     * @ORM\JoinColumn(name="access_url_id", referencedColumnName="id", onDelete="CASCADE")
90
     */
91
    protected AccessUrl $url;
92
93
    /**
94
     * An array of roles. Example: ROLE_USER, ROLE_TEACHER, ROLE_ADMIN.
95
     *
96
     * @ORM\Column(type="array")
97
     *
98
     * @var string[]
99
     */
100
    protected array $roles = [];
101
102
    /**
103
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Career")
104
     * @ORM\JoinColumn(name="career_id", referencedColumnName="id", onDelete="CASCADE")
105
     */
106
    protected ?Career $career = null;
107
108
    /**
109
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Promotion")
110
     * @ORM\JoinColumn(name="promotion_id", referencedColumnName="id", onDelete="CASCADE")
111
     */
112
    protected ?Promotion $promotion = null;
113
114
    public function __construct()
115
    {
116
        $this->roles = [];
117
        $this->visibleBoss = false;
118
        $this->visibleDrh = false;
119
        $this->visibleGuest = false;
120
        $this->visibleSessionAdmin = false;
121
        $this->visibleStudent = false;
122
        $this->visibleTeacher = false;
123
    }
124
125
    /**
126
     * Get dateStart.
127
     *
128
     * @return DateTime
129
     */
130
    public function getDateStart()
131
    {
132
        return $this->dateStart;
133
    }
134
135
    public function setDateStart(DateTime $dateStart): self
136
    {
137
        $this->dateStart = $dateStart;
138
139
        return $this;
140
    }
141
142
    /**
143
     * Get dateEnd.
144
     *
145
     * @return DateTime
146
     */
147
    public function getDateEnd()
148
    {
149
        return $this->dateEnd;
150
    }
151
152
    public function setDateEnd(DateTime $dateEnd): self
153
    {
154
        $this->dateEnd = $dateEnd;
155
156
        return $this;
157
    }
158
159
    /**
160
     * Get visibleTeacher.
161
     *
162
     * @return bool
163
     */
164
    public function getVisibleTeacher()
165
    {
166
        return $this->visibleTeacher;
167
    }
168
169
    public function setVisibleTeacher(bool $visibleTeacher): self
170
    {
171
        $this->visibleTeacher = $visibleTeacher;
172
173
        return $this;
174
    }
175
176
    /**
177
     * Get visibleStudent.
178
     *
179
     * @return bool
180
     */
181
    public function getVisibleStudent()
182
    {
183
        return $this->visibleStudent;
184
    }
185
186
    public function setVisibleStudent(bool $visibleStudent): self
187
    {
188
        $this->visibleStudent = $visibleStudent;
189
190
        return $this;
191
    }
192
193
    /**
194
     * Get visibleGuest.
195
     *
196
     * @return bool
197
     */
198
    public function getVisibleGuest()
199
    {
200
        return $this->visibleGuest;
201
    }
202
203
    public function setVisibleGuest(bool $visibleGuest): self
204
    {
205
        $this->visibleGuest = $visibleGuest;
206
207
        return $this;
208
    }
209
210
    /**
211
     * Get title.
212
     *
213
     * @return string
214
     */
215
    public function getTitle()
216
    {
217
        return $this->title;
218
    }
219
220
    public function setTitle(string $title): self
221
    {
222
        $this->title = $title;
223
224
        return $this;
225
    }
226
227
    /**
228
     * Get content.
229
     *
230
     * @return string
231
     */
232
    public function getContent()
233
    {
234
        return $this->content;
235
    }
236
237
    public function setContent(string $content): self
238
    {
239
        $this->content = $content;
240
241
        return $this;
242
    }
243
244
    /**
245
     * Get lang.
246
     *
247
     * @return string
248
     */
249
    public function getLang()
250
    {
251
        return $this->lang;
252
    }
253
254
    public function setLang(string $lang): self
255
    {
256
        $this->lang = $lang;
257
258
        return $this;
259
    }
260
261
    /**
262
     * Get id.
263
     *
264
     * @return int
265
     */
266
    public function getId()
267
    {
268
        return $this->id;
269
    }
270
271
    public function isVisibleDrh(): bool
272
    {
273
        return $this->visibleDrh;
274
    }
275
276
    public function setVisibleDrh(bool $visibleDrh): self
277
    {
278
        $this->visibleDrh = $visibleDrh;
279
280
        return $this;
281
    }
282
283
    public function isVisibleSessionAdmin(): bool
284
    {
285
        return $this->visibleSessionAdmin;
286
    }
287
288
    public function setVisibleSessionAdmin(bool $visibleSessionAdmin): self
289
    {
290
        $this->visibleSessionAdmin = $visibleSessionAdmin;
291
292
        return $this;
293
    }
294
295
    public function isVisibleBoss(): bool
296
    {
297
        return $this->visibleBoss;
298
    }
299
300
    public function setVisibleBoss(bool $visibleBoss): self
301
    {
302
        $this->visibleBoss = $visibleBoss;
303
304
        return $this;
305
    }
306
307
    public function getUrl(): AccessUrl
308
    {
309
        return $this->url;
310
    }
311
312
    public function setUrl(AccessUrl $url): self
313
    {
314
        $this->url = $url;
315
316
        return $this;
317
    }
318
319
    public function getCareer(): ?Career
320
    {
321
        return $this->career;
322
    }
323
324
    public function setCareer(?Career $career): self
325
    {
326
        $this->career = $career;
327
328
        return $this;
329
    }
330
331
    public function getPromotion(): ?Promotion
332
    {
333
        return $this->promotion;
334
    }
335
336
    public function setPromotion(?Promotion $promotion): self
337
    {
338
        $this->promotion = $promotion;
339
340
        return $this;
341
    }
342
343
    public function getRoles(): array
344
    {
345
        return $this->roles;
346
    }
347
348
    public function setRoles(array $roles): self
349
    {
350
        $this->roles = [];
351
        foreach ($roles as $role) {
352
            $this->addRole($role);
353
        }
354
355
        return $this;
356
    }
357
358
    public function addRole(string $role): self
359
    {
360
        $role = strtoupper($role);
361
362
        if (!\in_array($role, $this->roles, true)) {
363
            $this->roles[] = $role;
364
        }
365
366
        return $this;
367
    }
368
369
    public function isVisible(): bool
370
    {
371
        $now = new DateTime();
372
373
        return $this->getDateStart() <= $now && $now <= $this->getDateEnd();
374
    }
375
}
376