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\Doctrine\Orm\Filter\SearchFilter; |
10
|
|
|
use ApiPlatform\Metadata\ApiFilter; |
11
|
|
|
use ApiPlatform\Metadata\ApiResource; |
12
|
|
|
use ApiPlatform\Metadata\Get; |
13
|
|
|
use ApiPlatform\Metadata\GetCollection; |
14
|
|
|
use ApiPlatform\Metadata\Post; |
15
|
|
|
use ApiPlatform\Metadata\Put; |
16
|
|
|
use DateTime; |
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
18
|
|
|
use Doctrine\Common\Collections\Collection; |
19
|
|
|
use Doctrine\ORM\Mapping as ORM; |
20
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
21
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
22
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
23
|
|
|
|
24
|
|
|
#[ApiResource(operations: [new Get(security: 'is_granted(\'ROLE_ADMIN\')'), new Put(security: 'is_granted(\'ROLE_ADMIN\')'), new GetCollection(security: 'is_granted(\'ROLE_ADMIN\')'), new Post(security: 'is_granted(\'ROLE_ADMIN\')')], security: 'is_granted(\'ROLE_ADMIN\')', denormalizationContext: ['groups' => ['extra_field:write']], normalizationContext: ['groups' => ['extra_field:read']])] |
25
|
|
|
#[ORM\Table(name: 'extra_field')] |
26
|
|
|
#[ORM\Entity] |
27
|
|
|
#[ORM\MappedSuperclass] |
28
|
|
|
#[ApiFilter(filterClass: SearchFilter::class, properties: ['variable'])] |
29
|
|
|
class ExtraField |
30
|
|
|
{ |
31
|
|
|
public const USER_FIELD_TYPE = 1; |
32
|
|
|
public const COURSE_FIELD_TYPE = 2; |
33
|
|
|
public const SESSION_FIELD_TYPE = 3; |
34
|
|
|
public const QUESTION_FIELD_TYPE = 4; |
35
|
|
|
public const CALENDAR_FIELD_TYPE = 5; |
36
|
|
|
public const LP_FIELD_TYPE = 6; |
37
|
|
|
public const LP_ITEM_FIELD_TYPE = 7; |
38
|
|
|
public const SKILL_FIELD_TYPE = 8; |
39
|
|
|
public const WORK_FIELD_TYPE = 9; |
40
|
|
|
public const CAREER_FIELD_TYPE = 10; |
41
|
|
|
public const USER_CERTIFICATE = 11; |
42
|
|
|
public const SURVEY_FIELD_TYPE = 12; |
43
|
|
|
public const SCHEDULED_ANNOUNCEMENT = 13; |
44
|
|
|
public const TERMS_AND_CONDITION_TYPE = 14; |
45
|
|
|
public const FORUM_CATEGORY_TYPE = 15; |
46
|
|
|
public const FORUM_POST_TYPE = 16; |
47
|
|
|
public const EXERCISE_FIELD_TYPE = 17; |
48
|
|
|
public const TRACK_EXERCISE_FIELD_TYPE = 18; |
49
|
|
|
public const PORTFOLIO_TYPE = 19; |
50
|
|
|
public const LP_VIEW_TYPE = 20; |
51
|
|
|
public const COURSE_ANNOUNCEMENT = 21; |
52
|
|
|
public const MESSAGE_TYPE = 22; |
53
|
|
|
public const DOCUMENT_TYPE = 23; |
54
|
|
|
public const ATTENDANCE_CALENDAR_TYPE = 24; |
55
|
|
|
|
56
|
|
|
public const USER_FIELD_TYPE_RADIO = 3; |
57
|
|
|
public const USER_FIELD_TYPE_SELECT_MULTIPLE = 5; |
58
|
|
|
public const USER_FIELD_TYPE_TAG = 10; |
59
|
|
|
public const FIELD_TYPE_TEXT = 1; |
60
|
|
|
public const FIELD_TYPE_TEXTAREA = 2; |
61
|
|
|
public const FIELD_TYPE_RADIO = 3; |
62
|
|
|
public const FIELD_TYPE_SELECT = 4; |
63
|
|
|
public const FIELD_TYPE_SELECT_MULTIPLE = 5; |
64
|
|
|
public const FIELD_TYPE_DATE = 6; |
65
|
|
|
public const FIELD_TYPE_DATETIME = 7; |
66
|
|
|
public const FIELD_TYPE_DOUBLE_SELECT = 8; |
67
|
|
|
public const FIELD_TYPE_TAG = 10; |
68
|
|
|
public const FIELD_TYPE_SOCIAL_PROFILE = 12; |
69
|
|
|
public const FIELD_TYPE_CHECKBOX = 13; |
70
|
|
|
public const FIELD_TYPE_INTEGER = 15; |
71
|
|
|
public const FIELD_TYPE_FILE_IMAGE = 16; |
72
|
|
|
public const FIELD_TYPE_FLOAT = 17; |
73
|
|
|
public const FIELD_TYPE_FILE = 18; |
74
|
|
|
public const FIELD_TYPE_GEOLOCALIZATION = 24; |
75
|
|
|
public const FIELD_TYPE_GEOLOCALIZATION_COORDINATES = 25; |
76
|
|
|
|
77
|
|
|
#[Groups(['extra_field:read'])] |
78
|
|
|
#[ORM\Column(name: 'id', type: 'integer')] |
79
|
|
|
#[ORM\Id] |
80
|
|
|
#[ORM\GeneratedValue] |
81
|
|
|
protected ?int $id = null; |
82
|
|
|
#[Groups(['extra_field:read', 'extra_field:write'])] |
83
|
|
|
#[ORM\Column(name: 'item_type', type: 'integer')] |
84
|
|
|
protected int $itemType; |
85
|
|
|
#[Groups(['extra_field:read', 'extra_field:write'])] |
86
|
|
|
#[ORM\Column(name: 'value_type', type: 'integer')] |
87
|
|
|
protected int $valueType; |
88
|
|
|
#[Assert\NotBlank] |
89
|
|
|
#[Groups(['extra_field:read', 'extra_field:write'])] |
90
|
|
|
#[ORM\Column(name: 'variable', type: 'string', length: 255)] |
91
|
|
|
protected string $variable; |
92
|
|
|
#[Groups(['extra_field:read', 'extra_field:write'])] |
93
|
|
|
#[ORM\Column(name: 'description', type: 'text', nullable: true)] |
94
|
|
|
protected ?string $description; |
95
|
|
|
#[Assert\NotBlank] |
96
|
|
|
#[Groups(['extra_field:read', 'extra_field:write'])] |
97
|
|
|
#[Gedmo\Translatable] |
98
|
|
|
#[ORM\Column(name: 'display_text', type: 'string', length: 255, nullable: true, unique: false)] |
99
|
|
|
protected ?string $displayText = null; |
100
|
|
|
#[ORM\Column(name: 'helper_text', type: 'text', nullable: true, unique: false)] |
101
|
|
|
protected ?string $helperText = null; |
102
|
|
|
#[ORM\Column(name: 'default_value', type: 'text', nullable: true, unique: false)] |
103
|
|
|
protected ?string $defaultValue = null; |
104
|
|
|
#[ORM\Column(name: 'field_order', type: 'integer', nullable: true, unique: false)] |
105
|
|
|
protected ?int $fieldOrder = null; |
106
|
|
|
#[ORM\Column(name: 'visible_to_self', type: 'boolean', nullable: true, unique: false)] |
107
|
|
|
protected ?bool $visibleToSelf = false; |
108
|
|
|
#[ORM\Column(name: 'visible_to_others', type: 'boolean', nullable: true, unique: false)] |
109
|
|
|
protected ?bool $visibleToOthers = false; |
110
|
|
|
#[ORM\Column(name: 'changeable', type: 'boolean', nullable: true, unique: false)] |
111
|
|
|
protected ?bool $changeable = false; |
112
|
|
|
#[ORM\Column(name: 'filter', type: 'boolean', nullable: true, unique: false)] |
113
|
|
|
protected ?bool $filter = false; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @var Collection<int, ExtraFieldOptions> |
117
|
|
|
*/ |
118
|
|
|
#[Groups(['extra_field:read'])] |
119
|
|
|
#[ORM\OneToMany(targetEntity: ExtraFieldOptions::class, mappedBy: 'field')] |
120
|
|
|
protected Collection $options; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @var Collection<int, Tag> |
124
|
|
|
*/ |
125
|
|
|
#[ORM\OneToMany(targetEntity: Tag::class, mappedBy: 'field')] |
126
|
|
|
protected Collection $tags; |
127
|
|
|
#[Gedmo\Timestampable(on: 'create')] |
128
|
|
|
#[ORM\Column(name: 'created_at', type: 'datetime')] |
129
|
|
|
protected DateTime $createdAt; |
130
|
|
|
|
131
|
|
|
#[Groups(['extra_field:read'])] |
132
|
|
|
#[ORM\Column(name: 'auto_remove', type: 'boolean', options: ['default' => false])] |
133
|
|
|
protected bool $autoRemove = false; |
134
|
|
|
|
135
|
|
|
#[Gedmo\Locale] |
136
|
|
|
private ?string $locale = null; |
137
|
|
|
|
138
|
|
|
public function __construct() |
139
|
|
|
{ |
140
|
|
|
$this->options = new ArrayCollection(); |
141
|
|
|
$this->tags = new ArrayCollection(); |
142
|
|
|
$this->description = ''; |
143
|
|
|
$this->visibleToOthers = false; |
144
|
|
|
$this->visibleToSelf = false; |
145
|
|
|
$this->changeable = false; |
146
|
|
|
$this->filter = false; |
147
|
|
|
$this->autoRemove = false; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function getId(): ?int |
151
|
|
|
{ |
152
|
|
|
return $this->id; |
153
|
|
|
} |
154
|
|
|
public function getItemType(): int |
155
|
|
|
{ |
156
|
|
|
return $this->itemType; |
157
|
|
|
} |
158
|
|
|
public function setItemType(int $itemType): self |
159
|
|
|
{ |
160
|
|
|
$this->itemType = $itemType; |
161
|
|
|
|
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
public function getValueType(): int |
165
|
|
|
{ |
166
|
|
|
return $this->valueType; |
167
|
|
|
} |
168
|
|
|
public function setValueType(int $valueType): self |
169
|
|
|
{ |
170
|
|
|
$this->valueType = $valueType; |
171
|
|
|
|
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function getVariable(): string |
176
|
|
|
{ |
177
|
|
|
return $this->variable; |
178
|
|
|
} |
179
|
|
|
public function setVariable(string $variable): self |
180
|
|
|
{ |
181
|
|
|
$this->variable = $variable; |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function getDisplayText(): ?string |
187
|
|
|
{ |
188
|
|
|
return $this->displayText; |
189
|
|
|
} |
190
|
|
|
public function setDisplayText(string $displayText): self |
191
|
|
|
{ |
192
|
|
|
$this->displayText = $displayText; |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function getDefaultValue(): ?string |
198
|
|
|
{ |
199
|
|
|
return $this->defaultValue; |
200
|
|
|
} |
201
|
|
|
public function setDefaultValue(string $defaultValue): self |
202
|
|
|
{ |
203
|
|
|
$this->defaultValue = $defaultValue; |
204
|
|
|
|
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function getFieldOrder(): ?int |
209
|
|
|
{ |
210
|
|
|
return $this->fieldOrder; |
211
|
|
|
} |
212
|
|
|
public function setFieldOrder(int $fieldOrder): self |
213
|
|
|
{ |
214
|
|
|
$this->fieldOrder = $fieldOrder; |
215
|
|
|
|
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function isChangeable(): ?bool |
220
|
|
|
{ |
221
|
|
|
return $this->changeable; |
222
|
|
|
} |
223
|
|
|
public function setChangeable(bool $changeable): self |
224
|
|
|
{ |
225
|
|
|
$this->changeable = $changeable; |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
public function isFilter(): bool |
230
|
|
|
{ |
231
|
|
|
return $this->filter; |
|
|
|
|
232
|
|
|
} |
233
|
|
|
public function setFilter(bool $filter): self |
234
|
|
|
{ |
235
|
|
|
$this->filter = $filter; |
236
|
|
|
|
237
|
|
|
return $this; |
238
|
|
|
} |
239
|
|
|
public function isVisibleToSelf(): bool |
240
|
|
|
{ |
241
|
|
|
return $this->visibleToSelf; |
|
|
|
|
242
|
|
|
} |
243
|
|
|
public function setVisibleToSelf(bool $visibleToSelf): self |
244
|
|
|
{ |
245
|
|
|
$this->visibleToSelf = $visibleToSelf; |
246
|
|
|
|
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
public function isVisibleToOthers(): bool |
250
|
|
|
{ |
251
|
|
|
return $this->visibleToOthers; |
|
|
|
|
252
|
|
|
} |
253
|
|
|
public function setVisibleToOthers(bool $visibleToOthers): self |
254
|
|
|
{ |
255
|
|
|
$this->visibleToOthers = $visibleToOthers; |
256
|
|
|
|
257
|
|
|
return $this; |
258
|
|
|
} |
259
|
|
|
public function getDescription(): ?string |
260
|
|
|
{ |
261
|
|
|
return $this->description; |
262
|
|
|
} |
263
|
|
|
public function setDescription(string $description): self |
264
|
|
|
{ |
265
|
|
|
$this->description = $description; |
266
|
|
|
|
267
|
|
|
return $this; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @return Collection<int, ExtraFieldOptions> |
272
|
|
|
*/ |
273
|
|
|
public function getOptions(): Collection |
274
|
|
|
{ |
275
|
|
|
return $this->options; |
276
|
|
|
} |
277
|
|
|
public function setOptions(Collection $options): self |
278
|
|
|
{ |
279
|
|
|
$this->options = $options; |
280
|
|
|
|
281
|
|
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @return Collection<int, Tag> |
286
|
|
|
*/ |
287
|
|
|
public function getTags(): Collection |
288
|
|
|
{ |
289
|
|
|
return $this->tags; |
290
|
|
|
} |
291
|
|
|
public function setTags(Collection $tags): self |
292
|
|
|
{ |
293
|
|
|
$this->tags = $tags; |
294
|
|
|
|
295
|
|
|
return $this; |
296
|
|
|
} |
297
|
|
|
public function hasTag(string $tagName): bool |
298
|
|
|
{ |
299
|
|
|
if (0 === $this->tags->count()) { |
300
|
|
|
return false; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
return $this->tags->exists(fn ($key, Tag $tag) => $tagName === $tag->getTag()); |
304
|
|
|
} |
305
|
|
|
public function getTypeToString(): string |
306
|
|
|
{ |
307
|
|
|
return match ($this->getItemType()) { |
308
|
|
|
\ExtraField::FIELD_TYPE_RADIO, \ExtraField::FIELD_TYPE_SELECT => 'choice', |
309
|
|
|
default => 'text', |
310
|
|
|
}; |
311
|
|
|
} |
312
|
|
|
public function getHelperText(): string |
313
|
|
|
{ |
314
|
|
|
return $this->helperText; |
|
|
|
|
315
|
|
|
} |
316
|
|
|
public function setHelperText(string $helperText): self |
317
|
|
|
{ |
318
|
|
|
$this->helperText = $helperText; |
319
|
|
|
|
320
|
|
|
return $this; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
public function getAutoRemove(): bool |
324
|
|
|
{ |
325
|
|
|
return $this->autoRemove; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
public function setAutoRemove(bool $autoRemove): self |
329
|
|
|
{ |
330
|
|
|
$this->autoRemove = $autoRemove; |
331
|
|
|
|
332
|
|
|
return $this; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
public function getLocale(): string |
336
|
|
|
{ |
337
|
|
|
return $this->locale; |
|
|
|
|
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
public function setLocale(string $locale): self |
341
|
|
|
{ |
342
|
|
|
$this->locale = $locale; |
343
|
|
|
|
344
|
|
|
return $this; |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|