Completed
Push — master ( f75b34...c65fe1 )
by Julito
11:42
created

CQuizQuestionCategory::setQuestions()   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\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
     * @var CQuizQuestionCategory[] $questionCategories
67
     *
68
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CQuizQuestionCategory", mappedBy="event")
69
     */
70
    protected $questionCategories;
71
72
    public function __construct()
73
    {
74
        $this->questionCategories = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type Chamilo\CourseBundle\Ent...CQuizQuestionCategory[] of property $questionCategories.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
75
    }
76
77
    public function __toString(): string
78
    {
79
        return $this->getTitle();
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
    /**
95
     * Get title.
96
     *
97
     * @return string
98
     */
99
    public function getTitle()
100
    {
101
        return (string) $this->title;
102
    }
103
104
    public function setDescription(string $description): self
105
    {
106
        $this->description = $description;
107
108
        return $this;
109
    }
110
111
    /**
112
     * Get description.
113
     *
114
     * @return string
115
     */
116
    public function getDescription()
117
    {
118
        return $this->description;
119
    }
120
121
    public function getCourse()
122
    {
123
        return $this->course;
124
    }
125
126
    /**
127
     * @return CQuizQuestionCategory
128
     */
129
    public function setCourse($course)
130
    {
131
        $this->course = $course;
132
133
        return $this;
134
    }
135
136
    public function getSession()
137
    {
138
        return $this->session;
139
    }
140
141
    /**
142
     * @param Session $session
143
     *
144
     * @return CQuizQuestionCategory
145
     */
146
    public function setSession($session)
147
    {
148
        $this->session = $session;
149
150
        return $this;
151
    }
152
153
    /**
154
     * @return bool
155
     */
156
    public function hasSession()
157
    {
158
        return null !== $this->session;
159
    }
160
161
    /**
162
     * @ORM\PostPersist()
163
     */
164
    public function postPersist(LifecycleEventArgs $args)
165
    {
166
        // Update id with iid value
167
        /*$em = $args->getEntityManager();
168
        $em->persist($this);
169
        $em->flush();*/
170
    }
171
172
    /**
173
     * @return CQuizQuestionCategory[]
174
     */
175
    public function getQuestionCategories()
176
    {
177
        return $this->questionCategories;
178
    }
179
180
    /**
181
     * @param CQuizQuestionCategory[] $questionCategories
182
     *
183
     * @return CQuizQuestionCategory
184
     */
185
    public function setQuestionCategories($questionCategories): self
186
    {
187
        $this->questionCategories = $questionCategories;
188
189
        return $this;
190
    }
191
192
    /**
193
     * Resource identifier.
194
     */
195
    public function getResourceIdentifier(): int
196
    {
197
        return $this->getIid();
198
    }
199
200
    public function getResourceName(): string
201
    {
202
        return $this->getTitle();
203
    }
204
}
205