Passed
Push — master ( 221f68...d89cd9 )
by Julito
09:13
created

CQuizQuestionCategory::getResourceName()   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
c 0
b 0
f 0
nop 0
dl 0
loc 3
rs 10
nc 1
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 Chamilo\CoreBundle\Entity\Session;
10
use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\Common\Collections\Collection;
13
use Doctrine\ORM\Event\LifecycleEventArgs;
14
use Doctrine\ORM\Mapping as ORM;
15
16
/**
17
 * CQuizQuestionCategory.
18
 *
19
 * @ORM\Table(
20
 *  name="c_quiz_question_category",
21
 *  indexes={
22
 *      @ORM\Index(name="course", columns={"c_id"})
23
 *  }
24
 * )
25
 * @ORM\Entity
26
 */
27
class CQuizQuestionCategory extends AbstractResource implements ResourceInterface
28
{
29
    use ShowCourseResourcesInSessionTrait;
30
31
    /**
32
     * @var int
33
     *
34
     * @ORM\Column(name="iid", type="integer")
35
     * @ORM\Id
36
     * @ORM\GeneratedValue
37
     */
38
    protected $iid;
39
40
    /**
41
     * @var string
42
     *
43
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
44
     */
45
    protected $title;
46
47
    /**
48
     * @var string
49
     *
50
     * @ORM\Column(name="description", type="text", nullable=true)
51
     */
52
    protected $description;
53
54
    /**
55
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course")
56
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false)
57
     */
58
    protected $course;
59
60
    /**
61
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", cascade={"persist"})
62
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true)
63
     */
64
    protected $session;
65
66
    /**
67
     * @var Collection|CQuizQuestion[]
68
     *
69
     * @ORM\ManyToMany(targetEntity="Chamilo\CourseBundle\Entity\CQuizQuestion", mappedBy="categories")
70
     */
71
    protected $questions;
72
73
    public function __construct()
74
    {
75
        $this->questions = new ArrayCollection();
76
    }
77
78
    public function __toString(): string
79
    {
80
        return $this->getTitle();
81
    }
82
83
    public function addQuestion(CQuizQuestion $question)
84
    {
85
        if ($this->questions->contains($question)) {
86
            return;
87
        }
88
89
        $this->questions->add($question);
90
        $question->addCategory($this);
91
    }
92
93
    public function removeQuestion(CQuizQuestion $question)
94
    {
95
        if (!$this->questions->contains($question)) {
96
            return;
97
        }
98
99
        $this->questions->removeElement($question);
100
        $question->removeCategory($this);
101
    }
102
103
    public function getIid(): int
104
    {
105
        return $this->iid;
106
    }
107
108
    public function setTitle(string $title): self
109
    {
110
        $this->title = $title;
111
112
        return $this;
113
    }
114
115
    /**
116
     * Get title.
117
     *
118
     * @return string
119
     */
120
    public function getTitle()
121
    {
122
        return (string) $this->title;
123
    }
124
125
    public function setDescription(string $description): self
126
    {
127
        $this->description = $description;
128
129
        return $this;
130
    }
131
132
    /**
133
     * Get description.
134
     *
135
     * @return string
136
     */
137
    public function getDescription()
138
    {
139
        return $this->description;
140
    }
141
142
    public function getCourse()
143
    {
144
        return $this->course;
145
    }
146
147
    /**
148
     * @return CQuizQuestionCategory
149
     */
150
    public function setCourse($course)
151
    {
152
        $this->course = $course;
153
154
        return $this;
155
    }
156
157
    public function getSession()
158
    {
159
        return $this->session;
160
    }
161
162
    /**
163
     * @param Session $session
164
     *
165
     * @return CQuizQuestionCategory
166
     */
167
    public function setSession($session)
168
    {
169
        $this->session = $session;
170
171
        return $this;
172
    }
173
174
    /**
175
     * @return bool
176
     */
177
    public function hasSession()
178
    {
179
        return null !== $this->session;
180
    }
181
182
    /**
183
     * @ORM\PostPersist()
184
     */
185
    public function postPersist(LifecycleEventArgs $args)
186
    {
187
        // Update id with iid value
188
        /*$em = $args->getEntityManager();
189
        $em->persist($this);
190
        $em->flush();*/
191
    }
192
193
    /**
194
     * @return CQuizQuestion[]|Collection
195
     */
196
    public function getQuestions()
197
    {
198
        return $this->questions;
199
    }
200
201
    /**
202
     * @param CQuizQuestion[]|Collection $questions
203
     *
204
     * @return CQuizQuestionCategory
205
     */
206
    public function setQuestions($questions)
207
    {
208
        $this->questions = $questions;
209
210
        return $this;
211
    }
212
213
    /**
214
     * Resource identifier.
215
     */
216
    public function getResourceIdentifier(): int
217
    {
218
        return $this->getIid();
219
    }
220
221
    public function getResourceName(): string
222
    {
223
        return $this->getTitle();
224
    }
225
226
    public function setResourceName(string $name): self
227
    {
228
        return $this->setTitle($name);
229
    }
230
}
231