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 ApiPlatform\Core\Annotation\ApiResource; |
10
|
|
|
use DateTime; |
11
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
12
|
|
|
use Doctrine\Common\Collections\Collection; |
13
|
|
|
use Doctrine\ORM\Mapping as ORM; |
14
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
15
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
16
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @ApiResource( |
20
|
|
|
* attributes={"security"="is_granted('ROLE_ADMIN')"}, |
21
|
|
|
* normalizationContext={"groups"={"skill:read"}} |
22
|
|
|
* ) |
23
|
|
|
* |
24
|
|
|
* @ORM\Table(name="skill") |
25
|
|
|
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Repository\SkillRepository") |
26
|
|
|
*/ |
27
|
|
|
class Skill |
28
|
|
|
{ |
29
|
|
|
public const STATUS_DISABLED = 0; |
30
|
|
|
public const STATUS_ENABLED = 1; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @Groups({"skill:read"}) |
34
|
|
|
* @ORM\Column(name="id", type="integer") |
35
|
|
|
* @ORM\Id |
36
|
|
|
* @ORM\GeneratedValue |
37
|
|
|
*/ |
38
|
|
|
protected int $id; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Profile", inversedBy="skills") |
42
|
|
|
* @ORM\JoinColumn(name="profile_id", referencedColumnName="id") |
43
|
|
|
*/ |
44
|
|
|
protected ?Profile $profile = null; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @ORM\OneToMany(targetEntity="SkillRelUser", mappedBy="skill", cascade={"persist"}) |
48
|
|
|
* |
49
|
|
|
* @var SkillRelUser[]|Collection |
50
|
|
|
*/ |
51
|
|
|
protected Collection $issuedSkills; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @ORM\OneToMany(targetEntity="SkillRelItem", mappedBy="skill", cascade={"persist"}) |
55
|
|
|
* |
56
|
|
|
* @var Collection|SkillRelItem[] |
57
|
|
|
*/ |
58
|
|
|
protected Collection $items; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @ORM\OneToMany(targetEntity="SkillRelSkill", mappedBy="skill", cascade={"persist"}) |
62
|
|
|
* |
63
|
|
|
* @var Collection|SkillRelSkill[] |
64
|
|
|
*/ |
65
|
|
|
protected Collection $skills; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelCourse", mappedBy="skill", cascade={"persist"}) |
69
|
|
|
* |
70
|
|
|
* @var Collection|SkillRelCourse[] |
71
|
|
|
*/ |
72
|
|
|
protected Collection $courses; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelGradebook", mappedBy="skill", cascade={"persist"}) |
76
|
|
|
* |
77
|
|
|
* @var Collection|SkillRelGradebook[] |
78
|
|
|
*/ |
79
|
|
|
protected Collection $gradeBookCategories; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @Groups({"skill:read", "skill:write"}) |
83
|
|
|
* |
84
|
|
|
* @ORM\Column(name="name", type="string", length=255, nullable=false) |
85
|
|
|
*/ |
86
|
|
|
#[Assert\NotBlank] |
87
|
|
|
protected string $name; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @Groups({"skill:read", "skill:write"}) |
91
|
|
|
* |
92
|
|
|
* @ORM\Column(name="short_code", type="string", length=100, nullable=false) |
93
|
|
|
*/ |
94
|
|
|
#[Assert\NotBlank] |
95
|
|
|
protected string $shortCode; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @Groups({"skill:read", "skill:write"}) |
99
|
|
|
* |
100
|
|
|
* @ORM\Column(name="description", type="text", nullable=false) |
101
|
|
|
*/ |
102
|
|
|
protected string $description; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @ORM\Column(name="access_url_id", type="integer", nullable=false) |
106
|
|
|
*/ |
107
|
|
|
protected int $accessUrlId; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @ORM\Column(name="icon", type="string", length=255, nullable=false) |
111
|
|
|
*/ |
112
|
|
|
protected string $icon; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Asset", cascade={"persist", "remove"}) |
116
|
|
|
* @ORM\JoinColumn(name="asset_id", referencedColumnName="id") |
117
|
|
|
*/ |
118
|
|
|
protected ?Asset $asset = null; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @ORM\Column(name="criteria", type="text", nullable=true) |
122
|
|
|
*/ |
123
|
|
|
protected ?string $criteria = null; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @ORM\Column(name="status", type="integer", nullable=false, options={"default":1}) |
127
|
|
|
*/ |
128
|
|
|
protected int $status; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @Gedmo\Timestampable(on="update") |
132
|
|
|
* |
133
|
|
|
* @ORM\Column(name="updated_at", type="datetime", nullable=false) |
134
|
|
|
*/ |
135
|
|
|
protected DateTime $updatedAt; |
136
|
|
|
|
137
|
|
|
public function __construct() |
138
|
|
|
{ |
139
|
|
|
$this->issuedSkills = new ArrayCollection(); |
140
|
|
|
$this->items = new ArrayCollection(); |
141
|
|
|
$this->courses = new ArrayCollection(); |
142
|
|
|
$this->gradeBookCategories = new ArrayCollection(); |
143
|
|
|
$this->skills = new ArrayCollection(); |
144
|
|
|
$this->icon = ''; |
145
|
|
|
$this->description = ''; |
146
|
|
|
$this->status = self::STATUS_ENABLED; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function __toString(): string |
150
|
|
|
{ |
151
|
|
|
return $this->getName(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function setName(string $name): self |
155
|
|
|
{ |
156
|
|
|
$this->name = $name; |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function getName(): string |
162
|
|
|
{ |
163
|
|
|
return $this->name; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function getShortCode(): string |
167
|
|
|
{ |
168
|
|
|
return $this->shortCode; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function setShortCode(string $shortCode): self |
172
|
|
|
{ |
173
|
|
|
$this->shortCode = $shortCode; |
174
|
|
|
|
175
|
|
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function setDescription(string $description): self |
179
|
|
|
{ |
180
|
|
|
$this->description = $description; |
181
|
|
|
|
182
|
|
|
return $this; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function getDescription(): string |
186
|
|
|
{ |
187
|
|
|
return $this->description; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Set accessUrlId. |
192
|
|
|
* |
193
|
|
|
* @return Skill |
194
|
|
|
*/ |
195
|
|
|
public function setAccessUrlId(int $accessUrlId) |
196
|
|
|
{ |
197
|
|
|
$this->accessUrlId = $accessUrlId; |
198
|
|
|
|
199
|
|
|
return $this; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Get accessUrlId. |
204
|
|
|
* |
205
|
|
|
* @return int |
206
|
|
|
*/ |
207
|
|
|
public function getAccessUrlId() |
208
|
|
|
{ |
209
|
|
|
return $this->accessUrlId; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
public function setIcon(string $icon): self |
213
|
|
|
{ |
214
|
|
|
$this->icon = $icon; |
215
|
|
|
|
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Get icon. |
221
|
|
|
* |
222
|
|
|
* @return string |
223
|
|
|
*/ |
224
|
|
|
public function getIcon() |
225
|
|
|
{ |
226
|
|
|
return $this->icon; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
public function setCriteria(string $criteria): self |
230
|
|
|
{ |
231
|
|
|
$this->criteria = $criteria; |
232
|
|
|
|
233
|
|
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Get criteria. |
238
|
|
|
* |
239
|
|
|
* @return string |
240
|
|
|
*/ |
241
|
|
|
public function getCriteria() |
242
|
|
|
{ |
243
|
|
|
return $this->criteria; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function setStatus(int $status): self |
247
|
|
|
{ |
248
|
|
|
$this->status = $status; |
249
|
|
|
|
250
|
|
|
return $this; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Get status. |
255
|
|
|
* |
256
|
|
|
* @return int |
257
|
|
|
*/ |
258
|
|
|
public function getStatus() |
259
|
|
|
{ |
260
|
|
|
return $this->status; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Set updatedAt. |
265
|
|
|
* |
266
|
|
|
* @param DateTime $updatedAt The update datetime |
267
|
|
|
* |
268
|
|
|
* @return Skill |
269
|
|
|
*/ |
270
|
|
|
public function setUpdatedAt(DateTime $updatedAt) |
271
|
|
|
{ |
272
|
|
|
$this->updatedAt = $updatedAt; |
273
|
|
|
|
274
|
|
|
return $this; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Get updatedAt. |
279
|
|
|
* |
280
|
|
|
* @return DateTime |
281
|
|
|
*/ |
282
|
|
|
public function getUpdatedAt() |
283
|
|
|
{ |
284
|
|
|
return $this->updatedAt; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Get id. |
289
|
|
|
* |
290
|
|
|
* @return int |
291
|
|
|
*/ |
292
|
|
|
public function getId() |
293
|
|
|
{ |
294
|
|
|
return $this->id; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @return Profile |
299
|
|
|
*/ |
300
|
|
|
public function getProfile() |
301
|
|
|
{ |
302
|
|
|
return $this->profile; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
public function setProfile(Profile $profile): self |
306
|
|
|
{ |
307
|
|
|
$this->profile = $profile; |
308
|
|
|
|
309
|
|
|
return $this; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Get issuedSkills. |
314
|
|
|
* |
315
|
|
|
* @return Collection |
316
|
|
|
*/ |
317
|
|
|
public function getIssuedSkills() |
318
|
|
|
{ |
319
|
|
|
return $this->issuedSkills; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @return Collection |
324
|
|
|
*/ |
325
|
|
|
public function getItems() |
326
|
|
|
{ |
327
|
|
|
return $this->items; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
public function setItems(ArrayCollection $items): self |
331
|
|
|
{ |
332
|
|
|
$this->items = $items; |
333
|
|
|
|
334
|
|
|
return $this; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
public function hasItem(int $typeId, int $itemId): bool |
338
|
|
|
{ |
339
|
|
|
if (0 !== $this->getItems()->count()) { |
340
|
|
|
$found = false; |
341
|
|
|
/** @var SkillRelItem $item */ |
342
|
|
|
foreach ($this->getItems() as $item) { |
343
|
|
|
if ($item->getItemId() === $itemId && $item->getItemType() === $typeId) { |
344
|
|
|
$found = true; |
345
|
|
|
|
346
|
|
|
break; |
347
|
|
|
} |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
return $found; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
return false; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
public function addItem(SkillRelItem $skillRelItem): void |
357
|
|
|
{ |
358
|
|
|
$skillRelItem->setSkill($this); |
359
|
|
|
$this->items[] = $skillRelItem; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @return Collection |
364
|
|
|
*/ |
365
|
|
|
public function getCourses() |
366
|
|
|
{ |
367
|
|
|
return $this->courses; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
public function setCourses(ArrayCollection $courses): self |
371
|
|
|
{ |
372
|
|
|
$this->courses = $courses; |
373
|
|
|
|
374
|
|
|
return $this; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @return SkillRelSkill[]|Collection |
379
|
|
|
*/ |
380
|
|
|
public function getSkills() |
381
|
|
|
{ |
382
|
|
|
return $this->skills; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* @param SkillRelSkill[]|Collection $skills |
387
|
|
|
* |
388
|
|
|
* @return Skill |
389
|
|
|
*/ |
390
|
|
|
public function setSkills($skills): self |
391
|
|
|
{ |
392
|
|
|
$this->skills = $skills; |
393
|
|
|
|
394
|
|
|
return $this; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @return SkillRelGradebook[]|Collection |
399
|
|
|
*/ |
400
|
|
|
public function getGradeBookCategories() |
401
|
|
|
{ |
402
|
|
|
return $this->gradeBookCategories; |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* @param SkillRelGradebook[]|Collection $gradeBookCategories |
407
|
|
|
* |
408
|
|
|
* @return Skill |
409
|
|
|
*/ |
410
|
|
|
public function setGradeBookCategories($gradeBookCategories): self |
411
|
|
|
{ |
412
|
|
|
$this->gradeBookCategories = $gradeBookCategories; |
413
|
|
|
|
414
|
|
|
return $this; |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
public function hasAsset(): bool |
418
|
|
|
{ |
419
|
|
|
return null !== $this->asset; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
public function getAsset(): ?Asset |
423
|
|
|
{ |
424
|
|
|
return $this->asset; |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
public function setAsset(?Asset $asset): self |
428
|
|
|
{ |
429
|
|
|
$this->asset = $asset; |
430
|
|
|
|
431
|
|
|
return $this; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
public function hasCourseAndSession(SkillRelCourse $searchItem): bool |
435
|
|
|
{ |
436
|
|
|
if (0 !== $this->getCourses()->count()) { |
437
|
|
|
$found = false; |
438
|
|
|
/** @var SkillRelCourse $item */ |
439
|
|
|
foreach ($this->getCourses() as $item) { |
440
|
|
|
$sessionPassFilter = false; |
441
|
|
|
$session = $item->getSession(); |
442
|
|
|
$sessionId = empty($session) ? 0 : $session->getId(); |
443
|
|
|
$searchSessionId = empty($searchItem->getSession()) ? 0 : $searchItem->getSession()->getId(); |
444
|
|
|
|
445
|
|
|
if ($sessionId === $searchSessionId) { |
446
|
|
|
$sessionPassFilter = true; |
447
|
|
|
} |
448
|
|
|
if ($item->getCourse()->getId() === $searchItem->getCourse()->getId() && |
449
|
|
|
$sessionPassFilter |
450
|
|
|
) { |
451
|
|
|
$found = true; |
452
|
|
|
|
453
|
|
|
break; |
454
|
|
|
} |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
return $found; |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
return false; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
public function addToCourse(SkillRelCourse $item): void |
464
|
|
|
{ |
465
|
|
|
$item->setSkill($this); |
466
|
|
|
$this->courses[] = $item; |
467
|
|
|
} |
468
|
|
|
} |
469
|
|
|
|