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

CQuizQuestionCategory::setTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
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 addQuestion(CQuizQuestion $question)
79
    {
80
        if ($this->questions->contains($question)) {
81
            return;
82
        }
83
84
        $this->questions->add($question);
85
        $question->addCategory($this);
86
    }
87
88
    public function removeQuestion(CQuizQuestion $question)
89
    {
90
        if (!$this->questions->contains($question)) {
91
            return;
92
        }
93
94
        $this->questions->removeElement($question);
95
        $question->removeCategory($this);
96
    }
97
98
    public function __toString(): string
99
    {
100
        return $this->getTitle();
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 CQuizQuestionCategory[]
195
     */
196
    public function getQuestionCategories()
197
    {
198
        return $this->questionCategories;
199
    }
200
201
    /**
202
     * @param CQuizQuestionCategory[] $questionCategories
203
     *
204
     * @return CQuizQuestionCategory
205
     */
206
    public function setQuestionCategories($questionCategories): self
207
    {
208
        $this->questionCategories = $questionCategories;
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