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