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