Completed
Push — master ( 70ec3f...33181b )
by Luis Ramón
01:56
created

Element::isIncluded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
  ÁTICA - Aplicación web para la gestión documental de centros educativos
4
5
  Copyright (C) 2015-2017: Luis Ramón López López
6
7
  This program is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU Affero General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
12
  This program is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU Affero General Public License for more details.
16
17
  You should have received a copy of the GNU Affero General Public License
18
  along with this program.  If not, see [http://www.gnu.org/licenses/].
19
*/
20
21
namespace AppBundle\Entity;
22
23
use Doctrine\Common\Collections\Collection;
24
use Gedmo\Mapping\Annotation as Gedmo;
25
use Doctrine\ORM\Mapping as ORM;
26
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
27
28
/**
29
 * @Gedmo\Tree(type="nested")
30
 * @ORM\Entity(repositoryClass="ElementRepository")
31
 * @UniqueEntity(fields={"parent", "name"})
32
 */
33
class Element
34
{
35
    /**
36
     * @ORM\Id()
37
     * @ORM\GeneratedValue(strategy="AUTO")
38
     * @ORM\Column(type="integer")
39
     * @var int
40
     */
41
    private $id;
42
43
    /**
44
     * @ORM\Column(type="string")
45
     * @var string
46
     */
47
    private $name;
48
49
    /**
50
     * @ORM\Column(type="string", nullable=true)
51
     * @var string
52
     */
53
    private $code;
54
55
    /**
56
     * @ORM\Column(type="boolean")
57
     * @var bool
58
     */
59
    private $folder;
60
61
    /**
62
     * @ORM\Column(type="boolean")
63
     * @var bool
64
     */
65
    private $included;
66
67
    /**
68
     * @Gedmo\TreeLeft
69
     * @ORM\Column(name="lft", type="integer")
70
     * @var int
71
     */
72
    private $left;
73
74
    /**
75
     * @Gedmo\TreeLevel
76
     * @ORM\Column(name="lvl", type="integer")
77
     * @var int
78
     */
79
    private $level;
80
81
    /**
82
     * @Gedmo\TreeRight
83
     * @ORM\Column(name="rght", type="integer")
84
     * @var int
85
     */
86
    private $right;
87
88
    /**
89
     * @Gedmo\TreeParent()
90
     * @ORM\ManyToOne(targetEntity="Element", inversedBy="children")
91
     * @ORM\JoinColumn(onDelete="CASCADE", nullable=true)
92
     * @var Element
93
     */
94
    private $parent;
95
96
    /**
97
     * @ORM\OneToMany(targetEntity="Element", mappedBy="parent")
98
     * @var Collection
99
     */
100
    private $children;
101
102
    /**
103
     * @Gedmo\TreeRoot
104
     * @ORM\ManyToOne(targetEntity="Organization")
105
     * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
106
     * @var Organization
107
     */
108
    private $organization;
109
110
    /**
111
     * @ORM\Column(type="text", nullable=true)
112
     * @var string
113
     */
114
    private $description;
115
116
    /**
117
     * @ORM\OneToMany(targetEntity="Reference", mappedBy="source")
118
     * @var Collection
119
     */
120
    private $references;
121
122
    /**
123
     * @ORM\ManyToMany(targetEntity="Element")
124
     * @ORM\JoinTable(name="label")
125
     * @var Collection
126
     */
127
    private $labels;
128
129
    /**
130
     * @ORM\ManyToOne(targetEntity="Element")
131
     * @ORM\JoinColumn(onDelete="SET NULL", nullable=true)
132
     * @var Element
133
     */
134
    private $managedBy;
135
136
    /**
137
     * @ORM\OneToOne(targetEntity="Profile", inversedBy="element")
138
     * @ORM\JoinColumn(onDelete="SET NULL", nullable=true)
139
     * @var Profile
140
     */
141
    private $profile;
142
143
    /**
144
     * @ORM\ManyToMany(targetEntity="User", mappedBy="elements")
145
     * @var Collection
146
     */
147
    private $users;
148
149
    /**
150
     * Constructor
151
     */
152
    public function __construct()
153
    {
154
        $this->references = new \Doctrine\Common\Collections\ArrayCollection();
155
        $this->labels = new \Doctrine\Common\Collections\ArrayCollection();
156
        $this->children = new \Doctrine\Common\Collections\ArrayCollection();
157
        $this->users = new \Doctrine\Common\Collections\ArrayCollection();
158
    }
159
160
    /**
161
     * Converts entity to string
162
     *
163
     * @return string
164
     */
165
    public function __toString()
166
    {
167
        return $this->getName();
168
    }
169
170
    /**
171
     * Get element path
172
     *
173
     * @return string
174
     */
175
    public function getPath()
176
    {
177
        $path = '';
178
        $item = $this;
179
        $first = true;
180
181
        while ($item) {
182
            $path = $item->getName().($first ? '' : '/').$path;
183
            $first = false;
184
            $item = $item->getParent();
185
        }
186
187
        return $path;
188
    }
189
190
    /**
191
     * Get id
192
     *
193
     * @return integer
194
     */
195
    public function getId()
196
    {
197
        return $this->id;
198
    }
199
200
    /**
201
     * Set name
202
     *
203
     * @param string $name
204
     *
205
     * @return Element
206
     */
207
    public function setName($name)
208
    {
209
        $this->name = $name;
210
211
        return $this;
212
    }
213
214
    /**
215
     * Get name
216
     *
217
     * @return string
218
     */
219
    public function getName()
220
    {
221
        return $this->name;
222
    }
223
224
    /**
225
     * Set code
226
     *
227
     * @param string $code
228
     *
229
     * @return Element
230
     */
231
    public function setCode($code)
232
    {
233
        $this->code = $code;
234
235
        return $this;
236
    }
237
238
    /**
239
     * Get code
240
     *
241
     * @return string
242
     */
243
    public function getCode()
244
    {
245
        return $this->code;
246
    }
247
248
    /**
249
     * Set folder
250
     *
251
     * @param boolean $folder
252
     *
253
     * @return Element
254
     */
255
    public function setFolder($folder)
256
    {
257
        $this->folder = $folder;
258
259
        return $this;
260
    }
261
262
    /**
263
     * Is folder
264
     *
265
     * @return boolean
266
     */
267
    public function isFolder()
268
    {
269
        return $this->folder;
270
    }
271
272
    /**
273
     * Set included
274
     *
275
     * @param boolean $included
276
     *
277
     * @return Element
278
     */
279
    public function setIncluded($included)
280
    {
281
        $this->included = $included;
282
283
        return $this;
284
    }
285
286
    /**
287
     * Is included
288
     *
289
     * @return boolean
290
     */
291
    public function isIncluded()
292
    {
293
        return $this->included;
294
    }
295
296
    /**
297
     * Set left
298
     *
299
     * @param integer $left
300
     *
301
     * @return Element
302
     */
303
    public function setLeft($left)
304
    {
305
        $this->left = $left;
306
307
        return $this;
308
    }
309
310
    /**
311
     * Get left
312
     *
313
     * @return integer
314
     */
315
    public function getLeft()
316
    {
317
        return $this->left;
318
    }
319
320
    /**
321
     * Set level
322
     *
323
     * @param integer $level
324
     *
325
     * @return Element
326
     */
327
    public function setLevel($level)
328
    {
329
        $this->level = $level;
330
331
        return $this;
332
    }
333
334
    /**
335
     * Get level
336
     *
337
     * @return integer
338
     */
339
    public function getLevel()
340
    {
341
        return $this->level;
342
    }
343
344
    /**
345
     * Set right
346
     *
347
     * @param integer $right
348
     *
349
     * @return Element
350
     */
351
    public function setRight($right)
352
    {
353
        $this->right = $right;
354
355
        return $this;
356
    }
357
358
    /**
359
     * Get right
360
     *
361
     * @return integer
362
     */
363
    public function getRight()
364
    {
365
        return $this->right;
366
    }
367
368
    /**
369
     * Set parent
370
     *
371
     * @param Element $parent
372
     *
373
     * @return Element
374
     */
375
    public function setParent(Element $parent = null)
376
    {
377
        $this->parent = $parent;
378
379
        return $this;
380
    }
381
382
    /**
383
     * Get parent
384
     *
385
     * @return Element
386
     */
387
    public function getParent()
388
    {
389
        return $this->parent;
390
    }
391
392
    /**
393
     * Add child
394
     *
395
     * @param Element $child
396
     *
397
     * @return Element
398
     */
399
    public function addChild(Element $child)
400
    {
401
        $this->children[] = $child;
402
403
        return $this;
404
    }
405
406
    /**
407
     * Remove child
408
     *
409
     * @param Element $child
410
     */
411
    public function removeChild(Element $child)
412
    {
413
        $this->children->removeElement($child);
414
    }
415
416
    /**
417
     * Get children
418
     *
419
     * @return Collection
420
     */
421
    public function getChildren()
422
    {
423
        return $this->children;
424
    }
425
426
    /**
427
     * Set description
428
     *
429
     * @param string $description
430
     *
431
     * @return Element
432
     */
433
    public function setDescription($description)
434
    {
435
        $this->description = $description;
436
437
        return $this;
438
    }
439
440
    /**
441
     * Get description
442
     *
443
     * @return string
444
     */
445
    public function getDescription()
446
    {
447
        return $this->description;
448
    }
449
450
    /**
451
     * Set organization
452
     *
453
     * @param Organization $organization
454
     *
455
     * @return Element
456
     */
457
    public function setOrganization(Organization $organization)
458
    {
459
        $this->organization = $organization;
460
461
        return $this;
462
    }
463
464
    /**
465
     * Get organization
466
     *
467
     * @return Organization
468
     */
469
    public function getOrganization()
470
    {
471
        return $this->organization;
472
    }
473
474
    /**
475
     * Add reference
476
     *
477
     * @param Reference $reference
478
     *
479
     * @return Element
480
     */
481
    public function addReference(Reference $reference)
482
    {
483
        $this->references[] = $reference;
484
485
        return $this;
486
    }
487
488
    /**
489
     * Remove reference
490
     *
491
     * @param Reference $reference
492
     */
493
    public function removeReference(Reference $reference)
494
    {
495
        $this->references->removeElement($reference);
496
    }
497
498
    /**
499
     * Get references
500
     *
501
     * @return Collection
502
     */
503
    public function getReferences()
504
    {
505
        return $this->references;
506
    }
507
508
    /**
509
     * Add label
510
     *
511
     * @param Element $label
512
     *
513
     * @return Element
514
     */
515
    public function addLabel(Element $label)
516
    {
517
        $this->labels[] = $label;
518
519
        return $this;
520
    }
521
522
    /**
523
     * Remove label
524
     *
525
     * @param Element $label
526
     */
527
    public function removeLabel(Element $label)
528
    {
529
        $this->labels->removeElement($label);
530
    }
531
532
    /**
533
     * Get labels
534
     *
535
     * @return Collection
536
     */
537
    public function getLabels()
538
    {
539
        return $this->labels;
540
    }
541
542
    /**
543
     * Set managedBy
544
     *
545
     * @param Element $managedBy
546
     *
547
     * @return Element
548
     */
549
    public function setManagedBy(Element $managedBy = null)
550
    {
551
        $this->managedBy = $managedBy;
552
553
        return $this;
554
    }
555
556
    /**
557
     * Get managed element
558
     *
559
     * @return Element
560
     */
561
    public function getManagedBy()
562
    {
563
        return $this->managedBy;
564
    }
565
566
    /**
567
     * Set profile
568
     *
569
     * @param Profile $profile
570
     *
571
     * @return Element
572
     */
573
    public function setProfile(Profile $profile = null)
574
    {
575
        $this->profile = $profile;
576
577
        return $this;
578
    }
579
580
    /**
581
     * Get profile
582
     *
583
     * @return Profile
584
     */
585
    public function getProfile()
586
    {
587
        return $this->profile;
588
    }
589
590
    /**
591
     * Add user
592
     *
593
     * @param User $user
594
     *
595
     * @return Element
596
     */
597
    public function addUser(User $user)
598
    {
599
        $this->users[] = $user;
600
601
        return $this;
602
    }
603
604
    /**
605
     * Remove user
606
     *
607
     * @param User $user
608
     */
609
    public function removeUser(User $user)
610
    {
611
        $this->users->removeElement($user);
612
    }
613
614
    /**
615
     * Get users
616
     *
617
     * @return Collection
618
     */
619
    public function getUsers()
620
    {
621
        return $this->users;
622
    }
623
}
624