1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
declare(strict_types=1); |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Entity; |
8
|
|
|
|
9
|
|
|
use ApiPlatform\Metadata\ApiResource; |
10
|
|
|
use ApiPlatform\Metadata\Delete; |
11
|
|
|
use ApiPlatform\Metadata\Get; |
12
|
|
|
use ApiPlatform\Metadata\GetCollection; |
13
|
|
|
use ApiPlatform\Metadata\Post; |
14
|
|
|
use ApiPlatform\Metadata\Put; |
15
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
16
|
|
|
use Doctrine\Common\Collections\Collection; |
17
|
|
|
use Doctrine\ORM\Mapping as ORM; |
18
|
|
|
use Symfony\Component\Serializer\Attribute\Groups; |
19
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
20
|
|
|
|
21
|
|
|
#[ApiResource( |
22
|
|
|
normalizationContext: [ |
23
|
|
|
'groups' => ['skill_profile:read'], |
24
|
|
|
], |
25
|
|
|
denormalizationContext: [ |
26
|
|
|
'groups' => ['skill_profile:write'], |
27
|
|
|
], |
28
|
|
|
paginationEnabled: false, |
29
|
|
|
)] |
30
|
|
|
#[ORM\Table(name: 'skill_profile')] |
31
|
|
|
#[ORM\Entity] |
32
|
|
|
class SkillProfile |
33
|
|
|
{ |
34
|
|
|
#[Groups(['skill_profile:read'])] |
35
|
|
|
#[ORM\Column(name: 'id', type: 'integer')] |
36
|
|
|
#[ORM\Id] |
37
|
|
|
#[ORM\GeneratedValue] |
38
|
|
|
protected ?int $id = null; |
39
|
|
|
|
40
|
|
|
#[Groups(['skill_profile:write', 'skill_profile:read'])] |
41
|
|
|
#[Assert\NotBlank] |
42
|
|
|
#[ORM\Column(name: 'title', type: 'string', length: 255, nullable: false)] |
43
|
|
|
protected string $title; |
44
|
|
|
|
45
|
|
|
#[Groups(['skill_profile:write', 'skill_profile:read'])] |
46
|
|
|
#[ORM\Column(name: 'description', type: 'text', nullable: false)] |
47
|
|
|
protected string $description; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var Collection<int, SkillRelProfile> |
51
|
|
|
*/ |
52
|
|
|
#[Groups(['skill_profile:write', 'skill_profile:read'])] |
53
|
|
|
#[ORM\OneToMany(mappedBy: 'profile', targetEntity: SkillRelProfile::class, cascade: ['persist'])] |
54
|
|
|
private Collection $skills; |
55
|
|
|
|
56
|
|
|
public function __construct() |
57
|
|
|
{ |
58
|
|
|
$this->skills = new ArrayCollection(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function setTitle(string $title): self |
62
|
|
|
{ |
63
|
|
|
$this->title = $title; |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get title. |
70
|
|
|
*/ |
71
|
|
|
public function getTitle(): string |
72
|
|
|
{ |
73
|
|
|
return $this->title; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function setDescription(string $description): self |
77
|
|
|
{ |
78
|
|
|
$this->description = $description; |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get description. |
85
|
|
|
*/ |
86
|
|
|
public function getDescription(): string |
87
|
|
|
{ |
88
|
|
|
return $this->description; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get id. |
93
|
|
|
*/ |
94
|
|
|
public function getId(): ?int |
95
|
|
|
{ |
96
|
|
|
return $this->id; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return Collection<int, SkillRelProfile> |
101
|
|
|
*/ |
102
|
|
|
public function getSkills(): Collection |
103
|
|
|
{ |
104
|
|
|
return $this->skills; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function addSkill(SkillRelProfile $skill): static |
108
|
|
|
{ |
109
|
|
|
if (!$this->skills->contains($skill)) { |
110
|
|
|
$this->skills->add($skill); |
111
|
|
|
$skill->setProfile($this); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function removeSkill(SkillRelProfile $skill): static |
118
|
|
|
{ |
119
|
|
|
if ($this->skills->removeElement($skill)) { |
120
|
|
|
// set the owning side to null (unless already changed) |
121
|
|
|
if ($skill->getProfile() === $this) { |
122
|
|
|
$skill->setProfile(null); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|