Completed
Push — master ( db9c88...be5baf )
by Julito
14:58
created

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