Completed
Push — master ( c65fe1...e7429e )
by Julito
11:34
created

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