Completed
Push — master ( 792ce7...e487ad )
by Julito
21:06 queued 10s
created

CTool::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CourseBundle\Entity;
5
6
use APY\DataGridBundle\Grid\Mapping as GRID;
7
use Chamilo\CoreBundle\Entity\Course;
8
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
9
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
10
use Chamilo\CoreBundle\Entity\Session;
11
use Chamilo\CoreBundle\Entity\Tool;
12
use Doctrine\ORM\Event\LifecycleEventArgs;
13
use Doctrine\ORM\Mapping as ORM;
14
use Gedmo\Mapping\Annotation as Gedmo;
15
use Symfony\Component\Validator\Constraints as Assert;
16
17
/**
18
 * CTool.
19
 *
20
 * @ORM\HasLifecycleCallbacks
21
 * @ORM\Table(
22
 *  name="c_tool",
23
 *  indexes={
24
 *      @ORM\Index(name="course", columns={"c_id"}),
25
 *      @ORM\Index(name="session_id", columns={"session_id"})
26
 *  }
27
 * )
28
 * @ORM\Entity
29
 * @GRID\Source(columns="iid, name, resourceNode.createdAt", filterable=false, groups={"resource"})
30
 */
31
class CTool extends AbstractResource implements ResourceInterface
32
{
33
    /**
34
     * @var int
35
     *
36
     * @ORM\Column(name="iid", type="integer")
37
     * @ORM\Id
38
     * @ORM\GeneratedValue
39
     */
40
    protected $iid;
41
42
    /**
43
     * @var int
44
     *
45
     * @ORM\Column(name="id", type="integer", nullable=true)
46
     */
47
    protected $id;
48
49
    /**
50
     * @Assert\NotBlank
51
     *
52
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
53
     */
54
    protected $name;
55
56
    /**
57
     * @var bool
58
     *
59
     * @ORM\Column(name="visibility", type="boolean", nullable=true)
60
     */
61
    protected $visibility;
62
63
    /**
64
     * @var string
65
     *
66
     * @ORM\Column(name="category", type="string", length=20, nullable=false, options={"default" = "authoring"})
67
     */
68
    protected $category;
69
70
    /**
71
     * @var Course
72
     *
73
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="tools")
74
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false)
75
     */
76
    protected $course;
77
78
    /**
79
     * @var Session
80
     *
81
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session")
82
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true)
83
     */
84
    protected $session;
85
86
    /**
87
     * @var Tool
88
     *
89
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Tool")
90
     * @ORM\JoinColumn(name="tool_id", referencedColumnName="id", nullable=false)
91
     */
92
    protected $tool;
93
94
    /**
95
     * @Gedmo\SortablePosition
96
     * @ORM\Column(name="position", type="integer")
97
     */
98
    private $position;
99
100
    /**
101
     * Constructor.
102
     */
103
    public function __construct()
104
    {
105
        // Default values
106
        $this->id = 0;
107
    }
108
109
    public function getName(): string
110
    {
111
        return $this->name;
112
    }
113
114
    /**
115
     * @param string $name
116
     *
117
     * @return CTool
118
     */
119
    public function setName(string $name): CTool
120
    {
121
        $this->name = $name;
122
123
        return $this;
124
    }
125
126
    /**
127
     * @return int
128
     */
129
    public function getIid()
130
    {
131
        return $this->iid;
132
    }
133
134
    /**
135
     * @param int $iid
136
     *
137
     * @return CTool
138
     */
139
    public function setIid($iid)
140
    {
141
        $this->iid = $iid;
142
143
        return $this;
144
    }
145
146
    /**
147
     * @return $this
148
     */
149
    public function setCourse(Course $course)
150
    {
151
        $this->course = $course;
152
153
        return $this;
154
    }
155
156
    public function getCourse(): Course
157
    {
158
        return $this->course;
159
    }
160
161
    /**
162
     * @return Session
163
     */
164
    public function getSession(): ?Session
165
    {
166
        return $this->session;
167
    }
168
169
    /**
170
     * @param Session $session
171
     */
172
    public function setSession(Session $session = null): CTool
173
    {
174
        $this->session = $session;
175
176
        return $this;
177
    }
178
179
    /**
180
     * Set visibility.
181
     *
182
     * @param bool $visibility
183
     *
184
     * @return CTool
185
     */
186
    public function setVisibility($visibility)
187
    {
188
        $this->visibility = $visibility;
189
190
        return $this;
191
    }
192
193
    /**
194
     * Get visibility.
195
     *
196
     * @return bool
197
     */
198
    public function getVisibility()
199
    {
200
        return $this->visibility;
201
    }
202
203
    /**
204
     * Set category.
205
     *
206
     * @param string $category
207
     *
208
     * @return CTool
209
     */
210
    public function setCategory($category)
211
    {
212
        $this->category = $category;
213
214
        return $this;
215
    }
216
217
    /**
218
     * Get category.
219
     *
220
     * @return string
221
     */
222
    public function getCategory()
223
    {
224
        return $this->category;
225
    }
226
227
    /**
228
     * Set id.
229
     *
230
     * @param int $id
231
     *
232
     * @return CTool
233
     */
234
    public function setId($id)
235
    {
236
        $this->id = $id;
237
238
        return $this;
239
    }
240
241
    /**
242
     * Get id.
243
     *
244
     * @return int
245
     */
246
    public function getId()
247
    {
248
        return $this->id;
249
    }
250
251
    public function getTool(): Tool
252
    {
253
        return $this->tool;
254
    }
255
256
    public function setTool(Tool $tool): CTool
257
    {
258
        $this->tool = $tool;
259
260
        return $this;
261
    }
262
263
    /**
264
     * @ORM\PostPersist()
265
     */
266
    public function postPersist(LifecycleEventArgs $args)
267
    {
268
        // Update id with iid value
269
        $em = $args->getEntityManager();
270
        $this->setId($this->iid);
271
        $em->persist($this);
272
        $em->flush($this);
273
    }
274
275
    /**
276
     * @return mixed
277
     */
278
    public function getPosition()
279
    {
280
        return $this->position;
281
    }
282
283
    /**
284
     * @param mixed $position
285
     *
286
     * @return CTool
287
     */
288
    public function setPosition($position)
289
    {
290
        $this->position = $position;
291
292
        return $this;
293
    }
294
295
    /**
296
     * Resource identifier.
297
     */
298
    public function getResourceIdentifier(): int
299
    {
300
        return $this->iid;
301
    }
302
303
    public function getResourceName(): string
304
    {
305
        return (string) $this->getName();
306
    }
307
308
    public function __toString(): string
309
    {
310
        return (string) $this->getName();
311
    }
312
}
313