|
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; |
|
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; |
|
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; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @ORM\Column(name="extra", type="string", length=255, nullable=true) |
|
80
|
|
|
*/ |
|
81
|
|
|
protected ?string $extra; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @ORM\Column(name="question_code", type="string", length=10, nullable=true) |
|
85
|
|
|
*/ |
|
86
|
|
|
protected ?string $questionCode; |
|
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={@ORM\JoinColumn(name="category_id", referencedColumnName="iid")}, |
|
94
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="question_id", referencedColumnName="iid")} |
|
95
|
|
|
* ) |
|
96
|
|
|
*/ |
|
97
|
|
|
protected $categories; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @var Collection|CQuizRelQuestion[] |
|
101
|
|
|
* |
|
102
|
|
|
* @ORM\OneToMany(targetEntity="CQuizRelQuestion", mappedBy="question", cascade={"persist"}) |
|
103
|
|
|
*/ |
|
104
|
|
|
protected $relQuizzes; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @ORM\Column(name="mandatory", type="integer") |
|
108
|
|
|
*/ |
|
109
|
|
|
protected int $mandatory; |
|
110
|
|
|
|
|
111
|
|
|
public function __construct() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->categories = new ArrayCollection(); |
|
114
|
|
|
$this->ponderation = 0.0; |
|
115
|
|
|
$this->mandatory = 0; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function __toString(): string |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->getQuestion(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function addCategory(CQuizQuestionCategory $category): void |
|
124
|
|
|
{ |
|
125
|
|
|
if ($this->categories->contains($category)) { |
|
126
|
|
|
return; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$this->categories->add($category); |
|
130
|
|
|
$category->addQuestion($this); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function updateCategory(CQuizQuestionCategory $category): void |
|
134
|
|
|
{ |
|
135
|
|
|
if (0 === $this->categories->count()) { |
|
136
|
|
|
$this->addCategory($category); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
if ($this->categories->contains($category)) { |
|
140
|
|
|
return; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
foreach ($this->categories as $item) { |
|
144
|
|
|
$this->categories->removeElement($item); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
$this->addCategory($category); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function removeCategory(CQuizQuestionCategory $category): void |
|
151
|
|
|
{ |
|
152
|
|
|
if (!$this->categories->contains($category)) { |
|
153
|
|
|
return; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
$this->categories->removeElement($category); |
|
157
|
|
|
$category->removeQuestion($this); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Set question. |
|
162
|
|
|
* |
|
163
|
|
|
* @param string $question |
|
164
|
|
|
*/ |
|
165
|
|
|
public function setQuestion($question): self |
|
166
|
|
|
{ |
|
167
|
|
|
$this->question = $question; |
|
168
|
|
|
|
|
169
|
|
|
return $this; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function getQuestion(): string |
|
173
|
|
|
{ |
|
174
|
|
|
return $this->question; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Set description. |
|
179
|
|
|
* |
|
180
|
|
|
* @param string $description |
|
181
|
|
|
*/ |
|
182
|
|
|
public function setDescription($description): self |
|
183
|
|
|
{ |
|
184
|
|
|
$this->description = $description; |
|
185
|
|
|
|
|
186
|
|
|
return $this; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Get description. |
|
191
|
|
|
* |
|
192
|
|
|
* @return string |
|
193
|
|
|
*/ |
|
194
|
|
|
public function getDescription() |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->description; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Set ponderation. |
|
201
|
|
|
* |
|
202
|
|
|
* @param float $ponderation |
|
203
|
|
|
*/ |
|
204
|
|
|
public function setPonderation($ponderation): self |
|
205
|
|
|
{ |
|
206
|
|
|
$this->ponderation = $ponderation; |
|
207
|
|
|
|
|
208
|
|
|
return $this; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Get ponderation. |
|
213
|
|
|
* |
|
214
|
|
|
* @return float |
|
215
|
|
|
*/ |
|
216
|
|
|
public function getPonderation() |
|
217
|
|
|
{ |
|
218
|
|
|
return $this->ponderation; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Set position. |
|
223
|
|
|
* |
|
224
|
|
|
* @param int $position |
|
225
|
|
|
*/ |
|
226
|
|
|
public function setPosition($position): self |
|
227
|
|
|
{ |
|
228
|
|
|
$this->position = $position; |
|
229
|
|
|
|
|
230
|
|
|
return $this; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Get position. |
|
235
|
|
|
* |
|
236
|
|
|
* @return int |
|
237
|
|
|
*/ |
|
238
|
|
|
public function getPosition() |
|
239
|
|
|
{ |
|
240
|
|
|
return $this->position; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* Set type. |
|
245
|
|
|
* |
|
246
|
|
|
* @param int $type |
|
247
|
|
|
*/ |
|
248
|
|
|
public function setType($type): self |
|
249
|
|
|
{ |
|
250
|
|
|
$this->type = $type; |
|
251
|
|
|
|
|
252
|
|
|
return $this; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Get type. |
|
257
|
|
|
* |
|
258
|
|
|
* @return int |
|
259
|
|
|
*/ |
|
260
|
|
|
public function getType() |
|
261
|
|
|
{ |
|
262
|
|
|
return $this->type; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* Set picture. |
|
267
|
|
|
* |
|
268
|
|
|
* @param string $picture |
|
269
|
|
|
* |
|
270
|
|
|
* @return CQuizQuestion |
|
271
|
|
|
*/ |
|
272
|
|
|
public function setPicture($picture) |
|
273
|
|
|
{ |
|
274
|
|
|
$this->picture = $picture; |
|
275
|
|
|
|
|
276
|
|
|
return $this; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Get picture. |
|
281
|
|
|
* |
|
282
|
|
|
* @return string |
|
283
|
|
|
*/ |
|
284
|
|
|
public function getPicture() |
|
285
|
|
|
{ |
|
286
|
|
|
return $this->picture; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* Set level. |
|
291
|
|
|
* |
|
292
|
|
|
* @param int $level |
|
293
|
|
|
* |
|
294
|
|
|
* @return CQuizQuestion |
|
295
|
|
|
*/ |
|
296
|
|
|
public function setLevel($level) |
|
297
|
|
|
{ |
|
298
|
|
|
$this->level = $level; |
|
299
|
|
|
|
|
300
|
|
|
return $this; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* Get level. |
|
305
|
|
|
* |
|
306
|
|
|
* @return int |
|
307
|
|
|
*/ |
|
308
|
|
|
public function getLevel() |
|
309
|
|
|
{ |
|
310
|
|
|
return $this->level; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* Set extra. |
|
315
|
|
|
* |
|
316
|
|
|
* @param string $extra |
|
317
|
|
|
* |
|
318
|
|
|
* @return CQuizQuestion |
|
319
|
|
|
*/ |
|
320
|
|
|
public function setExtra($extra) |
|
321
|
|
|
{ |
|
322
|
|
|
$this->extra = $extra; |
|
323
|
|
|
|
|
324
|
|
|
return $this; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* Get extra. |
|
329
|
|
|
* |
|
330
|
|
|
* @return string |
|
331
|
|
|
*/ |
|
332
|
|
|
public function getExtra() |
|
333
|
|
|
{ |
|
334
|
|
|
return $this->extra; |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* Set questionCode. |
|
339
|
|
|
* |
|
340
|
|
|
* @param string $questionCode |
|
341
|
|
|
* |
|
342
|
|
|
* @return CQuizQuestion |
|
343
|
|
|
*/ |
|
344
|
|
|
public function setQuestionCode($questionCode) |
|
345
|
|
|
{ |
|
346
|
|
|
$this->questionCode = $questionCode; |
|
347
|
|
|
|
|
348
|
|
|
return $this; |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* Get questionCode. |
|
353
|
|
|
* |
|
354
|
|
|
* @return string |
|
355
|
|
|
*/ |
|
356
|
|
|
public function getQuestionCode() |
|
357
|
|
|
{ |
|
358
|
|
|
return $this->questionCode; |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
/** |
|
362
|
|
|
* @return string |
|
363
|
|
|
*/ |
|
364
|
|
|
public function getFeedback() |
|
365
|
|
|
{ |
|
366
|
|
|
return $this->feedback; |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
/** |
|
370
|
|
|
* @param string $feedback |
|
371
|
|
|
*/ |
|
372
|
|
|
public function setFeedback($feedback): self |
|
373
|
|
|
{ |
|
374
|
|
|
$this->feedback = $feedback; |
|
375
|
|
|
|
|
376
|
|
|
return $this; |
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* Get iid. |
|
381
|
|
|
* |
|
382
|
|
|
* @return int |
|
383
|
|
|
*/ |
|
384
|
|
|
public function getIid() |
|
385
|
|
|
{ |
|
386
|
|
|
return $this->iid; |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
public function getResourceIdentifier(): int |
|
390
|
|
|
{ |
|
391
|
|
|
return $this->getIid(); |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
public function getResourceName(): string |
|
395
|
|
|
{ |
|
396
|
|
|
return $this->getQuestion(); |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
public function setResourceName(string $name): self |
|
400
|
|
|
{ |
|
401
|
|
|
return $this->setQuestion($name); |
|
402
|
|
|
} |
|
403
|
|
|
} |
|
404
|
|
|
|