Passed
Push — master ( 4d43e7...34bdad )
by Julito
13:39
created

CTool::setCId()   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
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CourseBundle\Entity;
5
6
use Chamilo\CoreBundle\Entity\Course;
7
use Doctrine\ORM\Event\LifecycleEventArgs;
8
use Doctrine\ORM\Mapping as ORM;
9
10
/**
11
 * CTool.
12
 *
13
 * @ORM\HasLifecycleCallbacks
14
 * @ORM\Table(
15
 *  name="c_tool",
16
 *  indexes={
17
 *      @ORM\Index(name="course", columns={"c_id"}),
18
 *      @ORM\Index(name="session_id", columns={"session_id"})
19
 *  }
20
 * )
21
 * @ORM\Entity
22
 */
23
class CTool
24
{
25
    protected $originalImage;
26
27
    /**
28
     * @var int
29
     *
30
     * @ORM\Column(name="iid", type="integer")
31
     * @ORM\Id
32
     * @ORM\GeneratedValue
33
     */
34
    protected $iid;
35
36
    /**
37
     * @var int
38
     *
39
     * @ORM\Column(name="id", type="integer", nullable=true)
40
     */
41
    protected $id;
42
43
    /**
44
     * @var string
45
     *
46
     * @ORM\Column(name="name", type="text", nullable=false)
47
     */
48
    protected $name;
49
50
    /**
51
     * @var string
52
     *
53
     * @ORM\Column(name="link", type="string", length=255, nullable=false)
54
     */
55
    protected $link;
56
57
    /**
58
     * @var string
59
     *
60
     * @ORM\Column(name="image", type="string", length=255, nullable=true)
61
     */
62
    protected $image;
63
64
    /**
65
     * @var bool
66
     *
67
     * @ORM\Column(name="visibility", type="boolean", nullable=true)
68
     */
69
    protected $visibility;
70
71
    /**
72
     * @var string
73
     *
74
     * @ORM\Column(name="admin", type="string", length=255, nullable=true)
75
     */
76
    protected $admin;
77
78
    /**
79
     * @var string
80
     *
81
     * @ORM\Column(name="address", type="string", length=255, nullable=true)
82
     */
83
    protected $address;
84
85
    /**
86
     * @var bool
87
     *
88
     * @ORM\Column(name="added_tool", type="boolean", nullable=true)
89
     */
90
    protected $addedTool;
91
92
    /**
93
     * @var string
94
     *
95
     * @ORM\Column(name="target", type="string", length=20, nullable=false)
96
     */
97
    protected $target;
98
99
    /**
100
     * @var string
101
     *
102
     * @ORM\Column(name="category", type="string", length=20, nullable=false, options={"default" = "authoring"})
103
     */
104
    protected $category;
105
106
    /**
107
     * @var int
108
     *
109
     * @ORM\Column(name="session_id", type="integer", nullable=true)
110
     */
111
    protected $sessionId;
112
113
    /**
114
     * @var string
115
     *
116
     * @ORM\Column(name="description", type="text", nullable=true)
117
     */
118
    protected $description;
119
120
    /**
121
     * @var string
122
     *
123
     * @ORM\Column(name="custom_icon", type="string", length=255, nullable=true)
124
     */
125
    protected $customIcon;
126
127
    /**
128
     * @var Course
129
     *
130
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="tools")
131
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false)
132
     */
133
    protected $course;
134
135
    /**
136
     * Constructor.
137
     */
138
    public function __construct()
139
    {
140
        // Default values
141
        $this->id = 0;
142
        $this->sessionId = 0;
143
        $this->address = 'squaregrey.gif';
144
    }
145
146
    /**
147
     * @return int
148
     */
149
    public function getIid()
150
    {
151
        return $this->iid;
152
    }
153
154
    /**
155
     * @param int $iid
156
     *
157
     * @return CTool
158
     */
159
    public function setIid($iid)
160
    {
161
        $this->iid = $iid;
162
163
        return $this;
164
    }
165
166
    /**
167
     * @param Course $course
168
     *
169
     * @return $this
170
     */
171
    public function setCourse(Course $course)
172
    {
173
        $this->course = $course;
174
175
        return $this;
176
    }
177
178
    /**
179
     * @return Course
180
     */
181
    public function getCourse(): Course
182
    {
183
        return $this->course;
184
    }
185
186
    /**
187
     * @param ClassMetadata $metadata
188
     */
189
    public static function loadValidatorMetadata(ClassMetadata $metadata)
190
    {
191
        $metadata->addPropertyConstraint(
192
            'customIcon',
193
            new Assert\File(['mimeTypes' => ['image/png']])
194
        );
195
        $metadata->addPropertyConstraint(
196
            'customIcon',
197
            new Assert\Image(['maxWidth' => 64, 'minHeight' => 64])
198
        );
199
        $metadata->addPropertyConstraint('cId', new Assert\NotBlank());
200
    }
201
202
    /**
203
     * Set name.
204
     *
205
     * @param string $name
206
     *
207
     * @return CTool
208
     */
209
    public function setName($name)
210
    {
211
        $this->name = $name;
212
213
        return $this;
214
    }
215
216
    /**
217
     * Get name.
218
     *
219
     * @return string
220
     */
221
    public function getName()
222
    {
223
        return $this->name;
224
    }
225
226
    /**
227
     * Set link.
228
     *
229
     * @param string $link
230
     *
231
     * @return CTool
232
     */
233
    public function setLink($link)
234
    {
235
        $this->link = $link;
236
237
        return $this;
238
    }
239
240
    /**
241
     * Get link.
242
     *
243
     * @return string
244
     */
245
    public function getLink()
246
    {
247
        return $this->link;
248
    }
249
250
    /**
251
     * Set image.
252
     *
253
     * @param string $image
254
     *
255
     * @return CTool
256
     */
257
    public function setImage($image)
258
    {
259
        $this->image = $image;
260
261
        return $this;
262
    }
263
264
    /**
265
     * Get image.
266
     *
267
     * @return string
268
     */
269
    public function getImage()
270
    {
271
        return $this->image;
272
    }
273
274
    /**
275
     * Set visibility.
276
     *
277
     * @param bool $visibility
278
     *
279
     * @return CTool
280
     */
281
    public function setVisibility($visibility)
282
    {
283
        $this->visibility = $visibility;
284
285
        return $this;
286
    }
287
288
    /**
289
     * Get visibility.
290
     *
291
     * @return bool
292
     */
293
    public function getVisibility()
294
    {
295
        return $this->visibility;
296
    }
297
298
    /**
299
     * Set admin.
300
     *
301
     * @param string $admin
302
     *
303
     * @return CTool
304
     */
305
    public function setAdmin($admin)
306
    {
307
        $this->admin = $admin;
308
309
        return $this;
310
    }
311
312
    /**
313
     * Get admin.
314
     *
315
     * @return string
316
     */
317
    public function getAdmin()
318
    {
319
        return $this->admin;
320
    }
321
322
    /**
323
     * Set address.
324
     *
325
     * @param string $address
326
     *
327
     * @return CTool
328
     */
329
    public function setAddress($address)
330
    {
331
        $this->address = $address;
332
333
        return $this;
334
    }
335
336
    /**
337
     * Get address.
338
     *
339
     * @return string
340
     */
341
    public function getAddress()
342
    {
343
        return $this->address;
344
    }
345
346
    /**
347
     * Set addedTool.
348
     *
349
     * @param bool $addedTool
350
     *
351
     * @return CTool
352
     */
353
    public function setAddedTool($addedTool)
354
    {
355
        $this->addedTool = $addedTool;
356
357
        return $this;
358
    }
359
360
    /**
361
     * Get addedTool.
362
     *
363
     * @return bool
364
     */
365
    public function getAddedTool()
366
    {
367
        return $this->addedTool;
368
    }
369
370
    /**
371
     * Set target.
372
     *
373
     * @param string $target
374
     *
375
     * @return CTool
376
     */
377
    public function setTarget($target)
378
    {
379
        $this->target = $target;
380
381
        return $this;
382
    }
383
384
    /**
385
     * Get target.
386
     *
387
     * @return string
388
     */
389
    public function getTarget()
390
    {
391
        return $this->target;
392
    }
393
394
    /**
395
     * Set category.
396
     *
397
     * @param string $category
398
     *
399
     * @return CTool
400
     */
401
    public function setCategory($category)
402
    {
403
        $this->category = $category;
404
405
        return $this;
406
    }
407
408
    /**
409
     * Get category.
410
     *
411
     * @return string
412
     */
413
    public function getCategory()
414
    {
415
        return $this->category;
416
    }
417
418
    /**
419
     * Set sessionId.
420
     *
421
     * @param int $sessionId
422
     *
423
     * @return CTool
424
     */
425
    public function setSessionId($sessionId)
426
    {
427
        $this->sessionId = $sessionId;
428
429
        return $this;
430
    }
431
432
    /**
433
     * Get sessionId.
434
     *
435
     * @return int
436
     */
437
    public function getSessionId()
438
    {
439
        return $this->sessionId;
440
    }
441
442
    /**
443
     * Set id.
444
     *
445
     * @param int $id
446
     *
447
     * @return CTool
448
     */
449
    public function setId($id)
450
    {
451
        $this->id = $id;
452
453
        return $this;
454
    }
455
456
    /**
457
     * Get id.
458
     *
459
     * @return int
460
     */
461
    public function getId()
462
    {
463
        return $this->id;
464
    }
465
466
    /**
467
     * @return string
468
     */
469
    public function getDescription()
470
    {
471
        return $this->description;
472
    }
473
474
    /**
475
     * @param string $description
476
     *
477
     * @return CTool
478
     */
479
    public function setDescription($description)
480
    {
481
        $this->description = $description;
482
483
        return $this;
484
    }
485
486
    /**
487
     * @return string
488
     */
489
    public function getCustomIcon()
490
    {
491
        return $this->customIcon;
492
    }
493
494
    /**
495
     * @param string $customIcon
496
     *
497
     * @return CTool
498
     */
499
    public function setCustomIcon($customIcon)
500
    {
501
        $this->customIcon = $customIcon;
502
503
        return $this;
504
    }
505
506
    /**
507
     * @ORM\PostPersist()
508
     */
509
    public function postPersist(LifecycleEventArgs $args)
510
    {
511
        // Update id with iid value
512
        $em = $args->getEntityManager();
513
        $this->setId($this->iid);
514
        $em->persist($this);
515
        $em->flush($this);
516
    }
517
}
518