Passed
Push — master ( 4c4023...2b0e92 )
by Julito
07:08
created

ExtraField::setOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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