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\ApiFilter; |
10
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
11
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; |
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
13
|
|
|
use Gedmo\Timestampable\Traits\TimestampableEntity; |
14
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
15
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @ORM\Table( |
19
|
|
|
* name="extra_field_values", |
20
|
|
|
* indexes={ |
21
|
|
|
* @ORM\Index(name="idx_efv_fiii", columns={"field_id", "item_id"}), |
22
|
|
|
* @ORM\Index(name="idx_efv_item", columns={"item_id"}) |
23
|
|
|
* } |
24
|
|
|
* ) |
25
|
|
|
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Repository\ExtraFieldValuesRepository") |
26
|
|
|
* @ORM\MappedSuperclass |
27
|
|
|
*/ |
28
|
|
|
#[ApiResource( |
29
|
|
|
collectionOperations:[ |
30
|
|
|
'get' => [ |
31
|
|
|
'security' => "is_granted('ROLE_ADMIN')", |
32
|
|
|
], |
33
|
|
|
'post' => [ |
34
|
|
|
'security' => "is_granted('ROLE_ADMIN')", |
35
|
|
|
], |
36
|
|
|
], |
37
|
|
|
itemOperations:[ |
38
|
|
|
'get' => [ |
39
|
|
|
'security' => "is_granted('ROLE_ADMIN')", |
40
|
|
|
], |
41
|
|
|
'put' => [ |
42
|
|
|
'security' => "is_granted('ROLE_ADMIN')", |
43
|
|
|
], |
44
|
|
|
], |
45
|
|
|
attributes: [ |
46
|
|
|
'security' => "is_granted('ROLE_ADMIN')", |
47
|
|
|
], |
48
|
|
|
denormalizationContext: [ |
49
|
|
|
'groups' => ['extra_field_values:write'], |
50
|
|
|
], |
51
|
|
|
normalizationContext: [ |
52
|
|
|
'groups' => ['extra_field_values:read'], |
53
|
|
|
], |
54
|
|
|
)] |
55
|
|
|
#[ApiFilter(SearchFilter::class, properties: ['field' => 'exact', 'value' => 'exact'])] |
56
|
|
|
class ExtraFieldValues |
57
|
|
|
{ |
58
|
|
|
use TimestampableEntity; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @ORM\Column(name="id", type="integer") |
62
|
|
|
* @ORM\Id |
63
|
|
|
* @ORM\GeneratedValue() |
64
|
|
|
*/ |
65
|
|
|
#[Groups(['extra_field_values:read'])] |
66
|
|
|
protected ?int $id = null; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @ORM\Column(name="field_value", type="text", nullable=true, unique=false) |
70
|
|
|
*/ |
71
|
|
|
#[Groups(['extra_field_values:read', 'extra_field_values:write'])] |
72
|
|
|
protected ?string $fieldValue = null; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\ExtraField") |
76
|
|
|
* @ORM\JoinColumn(name="field_id", referencedColumnName="id") |
77
|
|
|
*/ |
78
|
|
|
#[Assert\NotBlank] |
79
|
|
|
#[Groups(['extra_field_values:read', 'extra_field_values:write'])] |
80
|
|
|
protected ExtraField $field; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Asset") |
84
|
|
|
* @ORM\JoinColumn(name="asset_id", referencedColumnName="id", onDelete="CASCADE") |
85
|
|
|
*/ |
86
|
|
|
protected ?Asset $asset = null; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Item id can be: userId, courseId, sessionId, etc. |
90
|
|
|
* |
91
|
|
|
* @ORM\Column(name="item_id", type="integer") |
92
|
|
|
*/ |
93
|
|
|
#[Assert\NotBlank] |
94
|
|
|
#[Groups(['extra_field_values:read', 'extra_field_values:write'])] |
95
|
|
|
protected int $itemId; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @ORM\Column(name="comment", type="text", nullable=true, unique=false) |
99
|
|
|
*/ |
100
|
|
|
#[Groups(['extra_field_values:read', 'extra_field_values:write'])] |
101
|
|
|
protected ?string $comment; |
102
|
|
|
|
103
|
|
|
public function __construct() |
104
|
|
|
{ |
105
|
|
|
$this->comment = ''; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function getField(): ExtraField |
109
|
|
|
{ |
110
|
|
|
return $this->field; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function setField(ExtraField $field): self |
114
|
|
|
{ |
115
|
|
|
$this->field = $field; |
116
|
|
|
|
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function getItemId(): int |
121
|
|
|
{ |
122
|
|
|
return $this->itemId; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function setItemId(int $itemId): self |
126
|
|
|
{ |
127
|
|
|
$this->itemId = $itemId; |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function setComment(string $comment): self |
133
|
|
|
{ |
134
|
|
|
$this->comment = $comment; |
135
|
|
|
|
136
|
|
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function getComment(): ?string |
140
|
|
|
{ |
141
|
|
|
return $this->comment; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get id. |
146
|
|
|
* |
147
|
|
|
* @return int |
148
|
|
|
*/ |
149
|
|
|
public function getId() |
150
|
|
|
{ |
151
|
|
|
return $this->id; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function getFieldValue(): ?string |
155
|
|
|
{ |
156
|
|
|
return $this->fieldValue; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function setFieldValue(?string $fieldValue): self |
160
|
|
|
{ |
161
|
|
|
$this->fieldValue = $fieldValue; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function getAsset(): ?Asset |
167
|
|
|
{ |
168
|
|
|
return $this->asset; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function setAsset(?Asset $asset): self |
172
|
|
|
{ |
173
|
|
|
$this->asset = $asset; |
174
|
|
|
|
175
|
|
|
return $this; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|