Completed
Push — master ( f6198e...300d99 )
by Paweł
53:20
created

Route::getRoot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Content Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\ContentBundle\Model;
16
17
use Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\Common\Collections\Collection;
19
use Symfony\Cmf\Bundle\RoutingBundle\Model\Route as BaseRoute;
20
21
class Route extends BaseRoute implements RouteInterface
22
{
23
    use RouteTrait;
24
25
    /**
26
     * @var int
27
     */
28
    protected $id;
29
30
    /**
31
     * @var Collection
32
     */
33
    protected $articles;
34
35
    /**
36
     * @var RouteInterface
37
     */
38
    protected $root;
39
40
    /**
41
     * @var RouteInterface
42
     */
43
    protected $parent;
44
45
    /**
46
     * @var Collection|RouteInterface[]
47
     */
48
    protected $children;
49
50
    /**
51
     * @var int
52
     */
53
    protected $lft;
54
55
    /**
56
     * @var int
57
     */
58
    protected $rgt;
59
60
    /**
61
     * @var int
62
     */
63
    protected $level;
64
65 102
    public function __construct()
66
    {
67 102
        $this->articles = new ArrayCollection();
68 102
        $this->children = new ArrayCollection();
69
70 102
        parent::__construct();
71 102
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function getArticles()
77
    {
78
        return $this->articles;
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function setArticles($articles)
85
    {
86
        $this->articles = $articles;
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92 29
    public function getId()
93
    {
94 29
        return parent::getId();
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function getRouteName()
101
    {
102
        return $this->getName();
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function isRoot(): bool
109
    {
110
        return null === $this->parent;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function getRoot(): RouteInterface
117
    {
118
        return $this->root;
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124
    public function getParent()
125
    {
126
        return $this->parent;
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132
    public function setParent(RouteInterface $parent = null)
133
    {
134
        $this->parent = $parent;
135
    }
136
137
    /**
138
     * @return Collection|RouteInterface[]
139
     */
140
    public function getChildren()
141
    {
142
        return $this->children;
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148
    public function hasChild(RouteInterface $route): bool
149
    {
150
        return $this->children->contains($route);
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156
    public function addChild(RouteInterface $route)
157
    {
158
        if (!$this->hasChild($route)) {
159
            $route->setParent($this);
160
            $this->children->add($route);
161
        }
162
    }
163
164
    /**
165
     * {@inheritdoc}
166
     */
167
    public function removeChild(RouteInterface $route)
168
    {
169
        if ($this->hasChild($route)) {
170
            $route->setParent(null);
171
            $this->children->removeElement($route);
172
        }
173
    }
174
175
    /**
176
     * {@inheritdoc}
177
     */
178
    public function getLeft(): int
179
    {
180
        return $this->lft;
181
    }
182
183
    /**
184
     * {@inheritdoc}
185
     */
186
    public function setLeft(int $left)
187
    {
188
        $this->lft = $left;
189
    }
190
191
    /**
192
     * {@inheritdoc}
193
     */
194
    public function getRight(): int
195
    {
196
        return $this->rgt;
197
    }
198
199
    /**
200
     * @param int $right
201
     */
202
    public function setRight(int $right)
203
    {
204
        $this->rgt = $right;
205
    }
206
207
    /**
208
     * {@inheritdoc}
209
     */
210
    public function getLevel(): int
211
    {
212
        return $this->level;
213
    }
214
215
    /**
216
     * {@inheritdoc}
217
     */
218
    public function setLevel(int $level)
219
    {
220
        $this->level = $level;
221
    }
222
223
    /**
224
     * {@inheritdoc}
225
     */
226
    public function getParentId()
227
    {
228
        if (null !== $this->parent) {
229
            return (int) $this->parent->getId();
230
        }
231
    }
232
233
    /**
234
     * {@inheritdoc}
235
     */
236
    public function getRootId()
237
    {
238
        if (null !== $this->root) {
239
            return (int) $this->root->getId();
240
        }
241
    }
242
}
243