Passed
Push — master ( 251179...3b9d17 )
by Julito
09:58
created

CQuizQuestion::getRelQuizzes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\CourseBundle\Entity;
8
9
use Chamilo\CoreBundle\Entity\AbstractResource;
10
use Chamilo\CoreBundle\Entity\ResourceInterface;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\Common\Collections\Collection;
13
use Doctrine\ORM\Mapping as ORM;
14
use Symfony\Component\Validator\Constraints as Assert;
15
16
/**
17
 * CQuizQuestion.
18
 *
19
 * @ORM\Table(
20
 *     name="c_quiz_question",
21
 *     indexes={
22
 *         @ORM\Index(name="position", columns={"position"})
23
 *     }
24
 * )
25
 * @ORM\Entity()
26
 */
27
class CQuizQuestion extends AbstractResource implements ResourceInterface
28
{
29
    /**
30
     * @ORM\Column(name="iid", type="integer")
31
     * @ORM\Id
32
     * @ORM\GeneratedValue
33
     */
34
    protected int $iid;
35
36
    /**
37
     * @Assert\NotBlank()
38
     *
39
     * @ORM\Column(name="question", type="text", nullable=false)
40
     */
41
    protected string $question;
42
43
    /**
44
     * @ORM\Column(name="description", type="text", nullable=true)
45
     */
46
    protected ?string $description = null;
47
48
    /**
49
     * @ORM\Column(name="ponderation", type="float", precision=6, scale=2, nullable=false, options={"default": 0})
50
     */
51
    protected float $ponderation;
52
53
    /**
54
     * @ORM\Column(name="position", type="integer", nullable=false)
55
     */
56
    protected int $position;
57
58
    /**
59
     * @ORM\Column(name="type", type="integer", nullable=false)
60
     */
61
    protected int $type;
62
63
    /**
64
     * @ORM\Column(name="picture", type="string", length=50, nullable=true)
65
     */
66
    protected ?string $picture = null;
67
68
    /**
69
     * @ORM\Column(name="level", type="integer", nullable=false)
70
     */
71
    protected int $level;
72
73
    /**
74
     * @ORM\Column(name="feedback", type="text", nullable=true)
75
     */
76
    protected ?string $feedback = null;
77
78
    /**
79
     * @ORM\Column(name="extra", type="string", length=255, nullable=true)
80
     */
81
    protected ?string $extra = null;
82
83
    /**
84
     * @ORM\Column(name="question_code", type="string", length=10, nullable=true)
85
     */
86
    protected ?string $questionCode = null;
87
88
    /**
89
     * @var Collection|CQuizQuestionCategory[]
90
     *
91
     * @ORM\ManyToMany(targetEntity="Chamilo\CourseBundle\Entity\CQuizQuestionCategory", inversedBy="questions")
92
     * @ORM\JoinTable(name="c_quiz_question_rel_category",
93
     *     joinColumns={
94
     *         @ORM\JoinColumn(name="category_id", referencedColumnName="iid")
95
     *     },
96
     *     inverseJoinColumns={
97
     *         @ORM\JoinColumn(name="question_id", referencedColumnName="iid")
98
     *     }
99
     * )
100
     */
101
    protected Collection $categories;
102
103
    /**
104
     * @var Collection|CQuizRelQuestion[]
105
     *
106
     * @ORM\OneToMany(targetEntity="CQuizRelQuestion", mappedBy="question", cascade={"persist"})
107
     */
108
    protected Collection $relQuizzes;
109
110
    /**
111
     * @var Collection|CQuizAnswer[]
112
     *
113
     * @ORM\OneToMany(targetEntity="CQuizAnswer", mappedBy="question", cascade={"persist"})
114
     */
115
    protected Collection $answers;
116
117
    /**
118
     * @ORM\Column(name="mandatory", type="integer")
119
     */
120
    protected int $mandatory;
121
122
    public function __construct()
123
    {
124
        $this->categories = new ArrayCollection();
125
        $this->relQuizzes = new ArrayCollection();
126
        $this->answers = new ArrayCollection();
127
        $this->ponderation = 0.0;
128
        $this->mandatory = 0;
129
    }
130
131
    public function __toString(): string
132
    {
133
        return $this->getQuestion();
134
    }
135
136
    public function addCategory(CQuizQuestionCategory $category): void
137
    {
138
        if ($this->categories->contains($category)) {
139
            return;
140
        }
141
142
        $this->categories->add($category);
143
        $category->addQuestion($this);
144
    }
145
146
    public function updateCategory(CQuizQuestionCategory $category): void
147
    {
148
        if (0 === $this->categories->count()) {
149
            $this->addCategory($category);
150
        }
151
152
        if ($this->categories->contains($category)) {
153
            return;
154
        }
155
156
        foreach ($this->categories as $item) {
157
            $this->categories->removeElement($item);
158
        }
159
160
        $this->addCategory($category);
161
    }
162
163
    public function removeCategory(CQuizQuestionCategory $category): void
164
    {
165
        if (!$this->categories->contains($category)) {
166
            return;
167
        }
168
169
        $this->categories->removeElement($category);
170
        $category->removeQuestion($this);
171
    }
172
173
    public function setQuestion(string $question): self
174
    {
175
        $this->question = $question;
176
177
        return $this;
178
    }
179
180
    public function getQuestion(): string
181
    {
182
        return $this->question;
183
    }
184
185
    public function setDescription(string $description): self
186
    {
187
        $this->description = $description;
188
189
        return $this;
190
    }
191
192
    /**
193
     * Get description.
194
     *
195
     * @return string
196
     */
197
    public function getDescription()
198
    {
199
        return $this->description;
200
    }
201
202
    public function setPonderation(float $ponderation): self
203
    {
204
        $this->ponderation = $ponderation;
205
206
        return $this;
207
    }
208
209
    /**
210
     * Get ponderation.
211
     *
212
     * @return float
213
     */
214
    public function getPonderation()
215
    {
216
        return $this->ponderation;
217
    }
218
219
    public function setPosition(int $position): self
220
    {
221
        $this->position = $position;
222
223
        return $this;
224
    }
225
226
    /**
227
     * Get position.
228
     *
229
     * @return int
230
     */
231
    public function getPosition()
232
    {
233
        return $this->position;
234
    }
235
236
    public function setType(int $type): self
237
    {
238
        $this->type = $type;
239
240
        return $this;
241
    }
242
243
    /**
244
     * Get type.
245
     *
246
     * @return int
247
     */
248
    public function getType()
249
    {
250
        return $this->type;
251
    }
252
253
    public function setPicture(string $picture): self
254
    {
255
        $this->picture = $picture;
256
257
        return $this;
258
    }
259
260
    /**
261
     * Get picture.
262
     *
263
     * @return string
264
     */
265
    public function getPicture()
266
    {
267
        return $this->picture;
268
    }
269
270
    public function setLevel(int $level): self
271
    {
272
        $this->level = $level;
273
274
        return $this;
275
    }
276
277
    /**
278
     * Get level.
279
     *
280
     * @return int
281
     */
282
    public function getLevel()
283
    {
284
        return $this->level;
285
    }
286
287
    public function setExtra(string $extra): self
288
    {
289
        $this->extra = $extra;
290
291
        return $this;
292
    }
293
294
    /**
295
     * Get extra.
296
     *
297
     * @return string
298
     */
299
    public function getExtra()
300
    {
301
        return $this->extra;
302
    }
303
304
    public function setQuestionCode(string $questionCode): self
305
    {
306
        $this->questionCode = $questionCode;
307
308
        return $this;
309
    }
310
311
    /**
312
     * Get questionCode.
313
     *
314
     * @return string
315
     */
316
    public function getQuestionCode()
317
    {
318
        return $this->questionCode;
319
    }
320
321
    /**
322
     * @return string
323
     */
324
    public function getFeedback()
325
    {
326
        return $this->feedback;
327
    }
328
329
    public function setFeedback(string $feedback): self
330
    {
331
        $this->feedback = $feedback;
332
333
        return $this;
334
    }
335
336
    /**
337
     * @return CQuizQuestionCategory[]|Collection
338
     */
339
    public function getCategories()
340
    {
341
        return $this->categories;
342
    }
343
344
    /**
345
     * @return CQuizRelQuestion[]|Collection
346
     */
347
    public function getRelQuizzes()
348
    {
349
        return $this->relQuizzes;
350
    }
351
352
    /**
353
     * @return CQuizAnswer[]|Collection
354
     */
355
    public function getAnswers()
356
    {
357
        return $this->answers;
358
    }
359
360
    public function getMandatory(): int
361
    {
362
        return $this->mandatory;
363
    }
364
365
    /**
366
     * Get iid.
367
     *
368
     * @return int
369
     */
370
    public function getIid()
371
    {
372
        return $this->iid;
373
    }
374
375
    public function getResourceIdentifier(): int
376
    {
377
        return $this->getIid();
378
    }
379
380
    public function getResourceName(): string
381
    {
382
        return $this->getQuestion();
383
    }
384
385
    public function setResourceName(string $name): self
386
    {
387
        return $this->setQuestion($name);
388
    }
389
}
390