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="title", type="string", length=250, nullable=false) |
40
|
|
|
*/ |
41
|
|
|
#[Assert\NotBlank] |
42
|
|
|
protected string $title; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @ORM\Column(name="content", type="text", nullable=false) |
46
|
|
|
*/ |
47
|
|
|
#[Assert\NotBlank] |
48
|
|
|
protected string $content; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @ORM\Column(name="lang", type="string", length=70, nullable=true) |
52
|
|
|
*/ |
53
|
|
|
protected ?string $lang = null; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @ORM\ManyToOne(targetEntity="AccessUrl") |
57
|
|
|
* @ORM\JoinColumn(name="access_url_id", referencedColumnName="id", onDelete="CASCADE") |
58
|
|
|
*/ |
59
|
|
|
protected AccessUrl $url; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* An array of roles. Example: ROLE_USER, ROLE_TEACHER, ROLE_ADMIN. |
63
|
|
|
* |
64
|
|
|
* @ORM\Column(type="array") |
65
|
|
|
* |
66
|
|
|
* @var string[] |
67
|
|
|
*/ |
68
|
|
|
protected array $roles = []; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Career") |
72
|
|
|
* @ORM\JoinColumn(name="career_id", referencedColumnName="id", onDelete="CASCADE") |
73
|
|
|
*/ |
74
|
|
|
protected ?Career $career = null; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Promotion") |
78
|
|
|
* @ORM\JoinColumn(name="promotion_id", referencedColumnName="id", onDelete="CASCADE") |
79
|
|
|
*/ |
80
|
|
|
protected ?Promotion $promotion = null; |
81
|
|
|
|
82
|
|
|
public function __construct() |
83
|
|
|
{ |
84
|
|
|
$this->roles = []; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get dateStart. |
89
|
|
|
* |
90
|
|
|
* @return DateTime |
91
|
|
|
*/ |
92
|
|
|
public function getDateStart() |
93
|
|
|
{ |
94
|
|
|
return $this->dateStart; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function setDateStart(DateTime $dateStart): self |
98
|
|
|
{ |
99
|
|
|
$this->dateStart = $dateStart; |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get dateEnd. |
106
|
|
|
* |
107
|
|
|
* @return DateTime |
108
|
|
|
*/ |
109
|
|
|
public function getDateEnd() |
110
|
|
|
{ |
111
|
|
|
return $this->dateEnd; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function setDateEnd(DateTime $dateEnd): self |
115
|
|
|
{ |
116
|
|
|
$this->dateEnd = $dateEnd; |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get title. |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getTitle() |
127
|
|
|
{ |
128
|
|
|
return $this->title; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function setTitle(string $title): self |
132
|
|
|
{ |
133
|
|
|
$this->title = $title; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get content. |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getContent() |
144
|
|
|
{ |
145
|
|
|
return $this->content; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function setContent(string $content): self |
149
|
|
|
{ |
150
|
|
|
$this->content = $content; |
151
|
|
|
|
152
|
|
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Get lang. |
157
|
|
|
* |
158
|
|
|
* @return string |
159
|
|
|
*/ |
160
|
|
|
public function getLang() |
161
|
|
|
{ |
162
|
|
|
return $this->lang; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function setLang(string $lang): self |
166
|
|
|
{ |
167
|
|
|
$this->lang = $lang; |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Get id. |
174
|
|
|
* |
175
|
|
|
* @return int |
176
|
|
|
*/ |
177
|
|
|
public function getId() |
178
|
|
|
{ |
179
|
|
|
return $this->id; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function getUrl(): AccessUrl |
183
|
|
|
{ |
184
|
|
|
return $this->url; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function setUrl(AccessUrl $url): self |
188
|
|
|
{ |
189
|
|
|
$this->url = $url; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function hasCareer(): bool |
195
|
|
|
{ |
196
|
|
|
return null !== $this->career; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function getCareer(): ?Career |
200
|
|
|
{ |
201
|
|
|
return $this->career; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function setCareer(?Career $career): self |
205
|
|
|
{ |
206
|
|
|
$this->career = $career; |
207
|
|
|
|
208
|
|
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function hasPromotion(): bool |
212
|
|
|
{ |
213
|
|
|
return null !== $this->promotion; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function getPromotion(): ?Promotion |
217
|
|
|
{ |
218
|
|
|
return $this->promotion; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function setPromotion(?Promotion $promotion): self |
222
|
|
|
{ |
223
|
|
|
$this->promotion = $promotion; |
224
|
|
|
|
225
|
|
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function getRoles(): array |
229
|
|
|
{ |
230
|
|
|
return $this->roles; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
public function setRoles(array $roles): self |
234
|
|
|
{ |
235
|
|
|
$this->roles = []; |
236
|
|
|
foreach ($roles as $role) { |
237
|
|
|
$this->addRole($role); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
return $this; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public function addRole(string $role): self |
244
|
|
|
{ |
245
|
|
|
$role = strtoupper($role); |
246
|
|
|
|
247
|
|
|
if (!\in_array($role, $this->roles, true)) { |
248
|
|
|
$this->roles[] = $role; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
return $this; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function isVisible(): bool |
255
|
|
|
{ |
256
|
|
|
$now = new DateTime(); |
257
|
|
|
|
258
|
|
|
return $this->getDateStart() <= $now && $now <= $this->getDateEnd(); |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
|