Completed
Push — master ( 0c6f8d...202b50 )
by Julito
16:24 queued 04:05
created

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