Completed
Push — master ( d28136...3a5b5f )
by Julito
16:58
created

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