Passed
Push — master ( 3ef090...0b35a3 )
by Julito
12:21
created

AccessUrl::setUrl()   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
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Entity;
6
7
use ApiPlatform\Core\Annotation\ApiResource;
8
use Doctrine\ORM\Mapping as ORM;
9
use Gedmo\Mapping\Annotation as Gedmo;
10
use Symfony\Component\Serializer\Annotation\Groups;
11
use Symfony\Component\Validator\Constraints as Assert;
12
13
/**
14
 * @ApiResource(
15
 *     attributes={"security"="is_granted('ROLE_ADMIN')"},
16
 *     normalizationContext={"groups"={"access_url:read"}, "swagger_definition_name"="Read"},
17
 *     denormalizationContext={"groups"={"access_url:write","course_category:write"}},
18
 * )
19
 *
20
 * @Gedmo\Tree(type="nested")
21
 * @ORM\Table(name="access_url")
22
 * @ORM\Entity
23
 */
24
class AccessUrl extends AbstractResource implements ResourceInterface
25
{
26
    /**
27
     * @var int
28
     *
29
     * @ORM\Column(name="id", type="integer")
30
     * @ORM\Id
31
     * @ORM\GeneratedValue(strategy="AUTO")
32
     *
33
     * @Groups({"access_url:read", "access_url:write"})
34
     */
35
    protected $id;
36
37
    /**
38
     * @ORM\OneToMany(targetEntity="AccessUrlRelCourse", mappedBy="url", cascade={"persist"}, orphanRemoval=true)
39
     */
40
    protected $courses;
41
42
    /**
43
     * @ORM\OneToMany(targetEntity="AccessUrlRelSession", mappedBy="url", cascade={"persist"}, orphanRemoval=true)
44
     */
45
    protected $sessions;
46
47
    /**
48
     * @ORM\OneToMany(targetEntity="AccessUrlRelUser", mappedBy="url", cascade={"persist"}, orphanRemoval=true)
49
     */
50
    protected $user;
51
52
    /**
53
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SettingsCurrent", mappedBy="url", cascade={"persist"}, orphanRemoval=true)
54
     */
55
    protected $settings;
56
57
    /**
58
     * @ORM\OneToMany(
59
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionCategory",
60
     *     mappedBy="url",
61
     *     cascade={"persist"},
62
     *     orphanRemoval=true
63
     * )
64
     */
65
    protected $sessionCategories;
66
67
    /**
68
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelCourseCategory", mappedBy="url", cascade={"persist"}, orphanRemoval=true)
69
     */
70
    protected $courseCategory;
71
72
    /**
73
     * @Gedmo\TreeParent
74
     *
75
     * @ORM\ManyToOne(
76
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrl",
77
     *     inversedBy="children"
78
     * )
79
     * @ORM\JoinColumns({@ORM\JoinColumn(onDelete="CASCADE")})
80
     */
81
    protected $parent;
82
83
    /**
84
     * @var AccessUrl[]
85
     *
86
     * @ORM\OneToMany(
87
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrl",
88
     *     mappedBy="parent"
89
     * )
90
     * @ORM\OrderBy({"id" = "ASC"})
91
     */
92
    protected $children;
93
94
    /**
95
     * @Gedmo\TreeLeft
96
     * @ORM\Column(name="lft", type="integer")
97
     */
98
    protected $lft;
99
100
    /**
101
     * @Gedmo\TreeLevel
102
     * @ORM\Column(name="lvl", type="integer")
103
     */
104
    protected $lvl;
105
106
    /**
107
     * @Gedmo\TreeRight
108
     * @ORM\Column(name="rgt", type="integer")
109
     */
110
    protected $rgt;
111
112
    /**
113
     * @Gedmo\TreeRoot
114
     * @ORM\ManyToOne(targetEntity="AccessUrl")
115
     * @ORM\JoinColumn(name="tree_root", referencedColumnName="id", onDelete="CASCADE")
116
     */
117
    protected $root;
118
119
    /**
120
     * @var string
121
     * @Assert\NotBlank()
122
     *
123
     * @Groups({"access_url:read", "access_url:write"})
124
     *
125
     * @ORM\Column(name="url", type="string", length=255, nullable=false, unique=false)
126
     */
127
    protected $url;
128
129
    /**
130
     * @var string
131
     *
132
     * @ORM\Column(name="description", type="text", unique=false)
133
     */
134
    protected $description;
135
136
    /**
137
     * @var int
138
     *
139
     * @ORM\Column(name="active", type="integer", nullable=false, unique=false)
140
     */
141
    protected $active;
142
143
    /**
144
     * @var int
145
     *
146
     * @ORM\Column(name="created_by", type="integer", nullable=false, unique=false)
147
     */
148
    protected $createdBy;
149
150
    /**
151
     * @var \DateTime
152
     *
153
     * @ORM\Column(name="tms", type="datetime", nullable=true)
154
     */
155
    protected $tms;
156
157
    /**
158
     * @var bool
159
     *
160
     * @ORM\Column(name="url_type", type="boolean", nullable=true)
161
     */
162
    protected $urlType;
163
164
    /**
165
     * @var int
166
     *
167
     * @ORM\Column(name="limit_courses", type="integer", nullable=true, unique=false)
168
     */
169
    protected $limitCourses;
170
171
    /**
172
     * @var int
173
     *
174
     * @ORM\Column(name="limit_active_courses", type="integer", nullable=true, unique=false)
175
     */
176
    protected $limitActiveCourses;
177
178
    /**
179
     * @var int
180
     *
181
     * @ORM\Column(name="limit_sessions", type="integer", nullable=true, unique=false)
182
     */
183
    protected $limitSessions;
184
185
    /**
186
     * @var int
187
     *
188
     * @ORM\Column(name="limit_users", type="integer", nullable=true, unique=false)
189
     */
190
    protected $limitUsers;
191
192
    /**
193
     * @var int
194
     *
195
     * @ORM\Column(name="limit_teachers", type="integer", nullable=true, unique=false)
196
     */
197
    protected $limitTeachers;
198
199
    /**
200
     * @var int
201
     *
202
     * @ORM\Column(name="limit_disk_space", type="integer", nullable=true, unique=false)
203
     */
204
    protected $limitDiskSpace;
205
206
    /**
207
     * @var string
208
     *
209
     * @ORM\Column(name="email", type="string", length=255, nullable=true, unique=false)
210
     */
211
    protected $email;
212
213
    /**
214
     * Constructor.
215
     */
216
    public function __construct()
217
    {
218
        $this->tms = new \DateTime();
219
        $this->createdBy = 1;
220
    }
221
222
    public function __toString(): string
223
    {
224
        return (string) $this->getUrl();
225
    }
226
227
    /**
228
     * Get id.
229
     *
230
     * @return int
231
     */
232
    public function getId()
233
    {
234
        return $this->id;
235
    }
236
237
    /**
238
     * Set url.
239
     *
240
     * @param string $url
241
     *
242
     * @return AccessUrl
243
     */
244
    public function setUrl($url)
245
    {
246
        $this->url = $url;
247
248
        return $this;
249
    }
250
251
    /**
252
     * Get url.
253
     *
254
     * @return string
255
     */
256
    public function getUrl()
257
    {
258
        return $this->url;
259
    }
260
261
    /**
262
     * Set description.
263
     *
264
     * @param string $description
265
     *
266
     * @return AccessUrl
267
     */
268
    public function setDescription($description)
269
    {
270
        $this->description = $description;
271
272
        return $this;
273
    }
274
275
    /**
276
     * Get description.
277
     *
278
     * @return string
279
     */
280
    public function getDescription()
281
    {
282
        return $this->description;
283
    }
284
285
    /**
286
     * Set active.
287
     *
288
     * @param int $active
289
     *
290
     * @return AccessUrl
291
     */
292
    public function setActive($active)
293
    {
294
        $this->active = $active;
295
296
        return $this;
297
    }
298
299
    /**
300
     * Get active.
301
     *
302
     * @return int
303
     */
304
    public function getActive()
305
    {
306
        return $this->active;
307
    }
308
309
    /**
310
     * Set createdBy.
311
     *
312
     * @param int $createdBy
313
     *
314
     * @return AccessUrl
315
     */
316
    public function setCreatedBy($createdBy)
317
    {
318
        $this->createdBy = $createdBy;
319
320
        return $this;
321
    }
322
323
    /**
324
     * Get createdBy.
325
     *
326
     * @return int
327
     */
328
    public function getCreatedBy()
329
    {
330
        return $this->createdBy;
331
    }
332
333
    /**
334
     * Set tms.
335
     *
336
     * @param \DateTime $tms
337
     *
338
     * @return AccessUrl
339
     */
340
    public function setTms($tms)
341
    {
342
        $this->tms = $tms;
343
344
        return $this;
345
    }
346
347
    /**
348
     * Get tms.
349
     *
350
     * @return \DateTime
351
     */
352
    public function getTms()
353
    {
354
        return $this->tms;
355
    }
356
357
    /**
358
     * Set urlType.
359
     *
360
     * @param bool $urlType
361
     *
362
     * @return AccessUrl
363
     */
364
    public function setUrlType($urlType)
365
    {
366
        $this->urlType = $urlType;
367
368
        return $this;
369
    }
370
371
    /**
372
     * Get urlType.
373
     *
374
     * @return bool
375
     */
376
    public function getUrlType()
377
    {
378
        return $this->urlType;
379
    }
380
381
    /**
382
     * @return int
383
     */
384
    public function getLimitActiveCourses()
385
    {
386
        return $this->limitActiveCourses;
387
    }
388
389
    /**
390
     * @param int $limitActiveCourses
391
     *
392
     * @return AccessUrl
393
     */
394
    public function setLimitActiveCourses($limitActiveCourses)
395
    {
396
        $this->limitActiveCourses = $limitActiveCourses;
397
398
        return $this;
399
    }
400
401
    /**
402
     * @return int
403
     */
404
    public function getLimitSessions()
405
    {
406
        return $this->limitSessions;
407
    }
408
409
    /**
410
     * @param int $limitSessions
411
     *
412
     * @return AccessUrl
413
     */
414
    public function setLimitSessions($limitSessions)
415
    {
416
        $this->limitSessions = $limitSessions;
417
418
        return $this;
419
    }
420
421
    /**
422
     * @return int
423
     */
424
    public function getLimitUsers()
425
    {
426
        return $this->limitUsers;
427
    }
428
429
    /**
430
     * @param int $limitUsers
431
     *
432
     * @return AccessUrl
433
     */
434
    public function setLimitUsers($limitUsers)
435
    {
436
        $this->limitUsers = $limitUsers;
437
438
        return $this;
439
    }
440
441
    /**
442
     * @return int
443
     */
444
    public function getLimitTeachers()
445
    {
446
        return $this->limitTeachers;
447
    }
448
449
    /**
450
     * @param int $limitTeachers
451
     *
452
     * @return AccessUrl
453
     */
454
    public function setLimitTeachers($limitTeachers)
455
    {
456
        $this->limitTeachers = $limitTeachers;
457
458
        return $this;
459
    }
460
461
    /**
462
     * @return int
463
     */
464
    public function getLimitDiskSpace()
465
    {
466
        return $this->limitDiskSpace;
467
    }
468
469
    /**
470
     * @param int $limitDiskSpace
471
     *
472
     * @return AccessUrl
473
     */
474
    public function setLimitDiskSpace($limitDiskSpace)
475
    {
476
        $this->limitDiskSpace = $limitDiskSpace;
477
478
        return $this;
479
    }
480
481
    /**
482
     * @return string
483
     */
484
    public function getEmail()
485
    {
486
        return $this->email;
487
    }
488
489
    /**
490
     * @param string $email
491
     *
492
     * @return AccessUrl
493
     */
494
    public function setEmail($email)
495
    {
496
        $this->email = $email;
497
498
        return $this;
499
    }
500
501
    public function getSettings()
502
    {
503
        return $this->settings;
504
    }
505
506
    /**
507
     * @return AccessUrl
508
     */
509
    public function setSettings($settings)
510
    {
511
        $this->settings = $settings;
512
513
        return $this;
514
    }
515
516
    /**
517
     * @return int
518
     */
519
    public function getLimitCourses()
520
    {
521
        return $this->limitCourses;
522
    }
523
524
    /**
525
     * @param int $limitCourses
526
     *
527
     * @return AccessUrl
528
     */
529
    public function setLimitCourses($limitCourses)
530
    {
531
        $this->limitCourses = $limitCourses;
532
533
        return $this;
534
    }
535
536
    /**
537
     * @return mixed
538
     */
539
    public function getCourses()
540
    {
541
        return $this->courses;
542
    }
543
544
    /**
545
     * @param mixed $courses
546
     *
547
     * @return AccessUrl
548
     */
549
    public function setCourses($courses)
550
    {
551
        $this->courses = $courses;
552
553
        return $this;
554
    }
555
556
    /**
557
     * @return mixed
558
     */
559
    public function getSessionCategories()
560
    {
561
        return $this->sessionCategories;
562
    }
563
564
    /**
565
     * @param mixed $sessionCategories
566
     *
567
     * @return AccessUrl
568
     */
569
    public function setSessionCategories($sessionCategories)
570
    {
571
        $this->sessionCategories = $sessionCategories;
572
573
        return $this;
574
    }
575
576
    /**
577
     * Resource identifier.
578
     */
579
    public function getResourceIdentifier(): int
580
    {
581
        return $this->getId();
582
    }
583
584
    public function getResourceName(): string
585
    {
586
        $url = $this->getUrl();
587
        $url = parse_url($url);
588
589
        return $url['host'];
590
    }
591
592
    public function setResourceName(string $name): self
593
    {
594
        return $this->setUrl($name);
595
    }
596
}
597