Passed
Push — master ( efc6d8...ea9271 )
by Julito
11:57
created

CTool::postPersist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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