Passed
Push — master ( f57a21...2863a7 )
by Julito
07:23
created

CQuizQuestionCategory::postPersist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
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 Chamilo\CoreBundle\Entity\ResourceShowCourseResourcesInSessionInterface;
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\Common\Collections\Collection;
14
use Doctrine\ORM\Mapping as ORM;
15
use Symfony\Component\Validator\Constraints as Assert;
16
17
/**
18
 * @ORM\Table(
19
 *     name="c_quiz_question_category",
20
 *     indexes={
21
 *     }
22
 * )
23
 * @ORM\Entity(repositoryClass="Chamilo\CourseBundle\Repository\CQuizQuestionCategoryRepository")
24
 */
25
class CQuizQuestionCategory extends AbstractResource implements ResourceInterface, ResourceShowCourseResourcesInSessionInterface
26
{
27
    /**
28
     * @ORM\Column(name="iid", type="integer")
29
     * @ORM\Id
30
     * @ORM\GeneratedValue
31
     */
32
    protected int $iid;
33
34
    /**
35
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
36
     */
37
    #[Assert\NotBlank]
38
    protected string $title;
39
40
    /**
41
     * @ORM\Column(name="description", type="text", nullable=true)
42
     */
43
    protected ?string $description = null;
44
45
    /**
46
     * @var Collection|CQuizQuestion[]
47
     *
48
     * @ORM\ManyToMany(targetEntity="Chamilo\CourseBundle\Entity\CQuizQuestion", mappedBy="categories")
49
     */
50
    protected Collection $questions;
51
52
    public function __construct()
53
    {
54
        $this->questions = new ArrayCollection();
55
    }
56
57
    public function __toString(): string
58
    {
59
        return $this->getTitle();
60
    }
61
62
    public function addQuestion(CQuizQuestion $question): void
63
    {
64
        if ($this->questions->contains($question)) {
65
            return;
66
        }
67
68
        $this->questions->add($question);
69
        $question->addCategory($this);
70
    }
71
72
    public function removeQuestion(CQuizQuestion $question): void
73
    {
74
        if (!$this->questions->contains($question)) {
75
            return;
76
        }
77
78
        $this->questions->removeElement($question);
79
        $question->removeCategory($this);
80
    }
81
82
    public function getIid(): int
83
    {
84
        return $this->iid;
85
    }
86
87
    public function setTitle(string $title): self
88
    {
89
        $this->title = $title;
90
91
        return $this;
92
    }
93
94
    public function getTitle(): string
95
    {
96
        return $this->title;
97
    }
98
99
    public function setDescription(string $description): self
100
    {
101
        $this->description = $description;
102
103
        return $this;
104
    }
105
106
    /**
107
     * Get description.
108
     *
109
     * @return string
110
     */
111
    public function getDescription()
112
    {
113
        return $this->description;
114
    }
115
116
    /**
117
     * @return Collection|CQuizQuestion[]
118
     */
119
    public function getQuestions()
120
    {
121
        return $this->questions;
122
    }
123
124
    /**
125
     * @param Collection|CQuizQuestion[] $questions
126
     */
127
    public function setQuestions(Collection $questions): self
128
    {
129
        $this->questions = $questions;
130
131
        return $this;
132
    }
133
134
    public function getResourceIdentifier(): int
135
    {
136
        return $this->getIid();
137
    }
138
139
    public function getResourceName(): string
140
    {
141
        return $this->getTitle();
142
    }
143
144
    public function setResourceName(string $name): self
145
    {
146
        return $this->setTitle($name);
147
    }
148
}
149