Completed
Push — master ( d998d0...abb41b )
by Kamil
38:34
created

Taxon::getRight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Taxonomy\Model;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Sylius\Component\Resource\Model\SoftDeletableTrait;
17
use Sylius\Component\Translation\Model\AbstractTranslatable;
18
19
/**
20
 * @author Paweł Jędrzejewski <[email protected]>
21
 * @author Gonzalo Vilaseca <[email protected]>
22
 */
23
class Taxon extends AbstractTranslatable implements TaxonInterface
24
{
25
    use SoftDeletableTrait;
26
27
    /**
28
     * @var mixed
29
     */
30
    protected $id;
31
32
    /**
33
     * @var string
34
     */
35
    protected $code;
36
37
    /**
38
     * @var TaxonomyInterface
39
     */
40
    protected $taxonomy;
41
42
    /**
43
     * @var TaxonInterface
44
     */
45
    protected $parent;
46
47
    /**
48
     * @var Collection|TaxonInterface[]
49
     */
50
    protected $children;
51
52
    /**
53
     * @var int
54
     */
55
    protected $left;
56
57
    /**
58
     * @var int
59
     */
60
    protected $right;
61
62
    /**
63
     * @var int
64
     */
65
    protected $level;
66
67
    public function __construct()
68
    {
69
        parent::__construct();
70
71
        $this->children = new ArrayCollection();
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function __toString()
78
    {
79
        return (string) $this->translate()->__toString();
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function getId()
86
    {
87
        return $this->id;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getCode()
94
    {
95
        return $this->code;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function setCode($code)
102
    {
103
        $this->code = $code;
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function getTaxonomy()
110
    {
111
        return $this->taxonomy;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function setTaxonomy(TaxonomyInterface $taxonomy = null)
118
    {
119
        $this->taxonomy = $taxonomy;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function isRoot()
126
    {
127
        return null === $this->parent;
128
    }
129
130
    /**
131
     * {@inheritdoc}
132
     */
133
    public function getParent()
134
    {
135
        return $this->parent;
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    public function setParent(TaxonInterface $parent = null)
142
    {
143
        $this->parent = $parent;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    public function getChildren()
150
    {
151
        return $this->children;
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157
    public function hasChild(TaxonInterface $taxon)
158
    {
159
        return $this->children->contains($taxon);
160
    }
161
162
    /**
163
     * {@inheritdoc}
164
     */
165
    public function addChild(TaxonInterface $taxon)
166
    {
167
        if (!$this->hasChild($taxon)) {
168
            $taxon->setTaxonomy($this->taxonomy);
169
            $taxon->setParent($this);
170
171
            $this->children->add($taxon);
172
        }
173
    }
174
175
    /**
176
     * {@inheritdoc}
177
     */
178
    public function removeChild(TaxonInterface $taxon)
179
    {
180
        if ($this->hasChild($taxon)) {
181
            $taxon->setTaxonomy(null);
182
            $taxon->setParent(null);
183
184
            $this->children->removeElement($taxon);
185
        }
186
    }
187
188
    /**
189
     * {@inheritdoc}
190
     */
191
    public function getName()
192
    {
193
        return $this->translate()->getName();
194
    }
195
196
    /**
197
     * {@inheritdoc}
198
     */
199
    public function setName($name)
200
    {
201
        $this->translate()->setName($name);
202
    }
203
204
    /**
205
     * {@inheritdoc}
206
     */
207
    public function getSlug()
208
    {
209
        return $this->translate()->getSlug();
210
    }
211
212
    /**
213
     * {@inheritdoc}
214
     */
215
    public function setSlug($slug = null)
216
    {
217
        $this->translate()->setSlug($slug);
218
    }
219
220
    /**
221
     * {@inheritdoc}
222
     */
223
    public function getPermalink()
224
    {
225
        $permalink = $this->translate()->getPermalink();
226
227
        if (null !== $permalink) {
228
            return $permalink;
229
        }
230
231
        if (null === $this->parent) {
232
            return $this->getSlug();
233
        }
234
235
        $this->setPermalink($permalink = $this->parent->getPermalink().'/'.$this->getSlug());
236
237
        return $permalink;
238
    }
239
240
    /**
241
     * {@inheritdoc}
242
     */
243
    public function setPermalink($permalink)
244
    {
245
        $this->translate()->setPermalink($permalink);
246
    }
247
248
    /**
249
     * {@inheritdoc}
250
     */
251
    public function getDescription()
252
    {
253
        return $this->translate()->getDescription();
254
    }
255
256
    /**
257
     * {@inheritdoc}
258
     */
259
    public function setDescription($description)
260
    {
261
        $this->translate()->setDescription($description);
262
    }
263
264
    /**
265
     * {@inheritdoc}
266
     */
267
    public function getLeft()
268
    {
269
        return $this->left;
270
    }
271
272
    /**
273
     * {@inheritdoc}
274
     */
275
    public function setLeft($left)
276
    {
277
        $this->left = $left;
278
    }
279
280
    /**
281
     * {@inheritdoc}
282
     */
283
    public function getRight()
284
    {
285
        return $this->right;
286
    }
287
288
    /**
289
     * {@inheritdoc}
290
     */
291
    public function setRight($right)
292
    {
293
        $this->right = $right;
294
    }
295
296
    /**
297
     * {@inheritdoc}
298
     */
299
    public function getLevel()
300
    {
301
        return $this->level;
302
    }
303
304
    /**
305
     * {@inheritdoc}
306
     */
307
    public function setLevel($level)
308
    {
309
        $this->level = $level;
310
    }
311
}
312