Passed
Push — master ( b95980...a81919 )
by Julito
08:46
created

AccessUrl::getParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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