1 | <?php |
||
25 | class Taxon implements TaxonInterface |
||
26 | { |
||
27 | use TranslatableTrait { |
||
28 | __construct as private initializeTranslationsCollection; |
||
29 | getTranslation as private doGetTranslation; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @var mixed |
||
34 | */ |
||
35 | protected $id; |
||
36 | |||
37 | /** |
||
38 | * @var string|null |
||
39 | */ |
||
40 | protected $code; |
||
41 | |||
42 | /** |
||
43 | * @var TaxonInterface|null |
||
44 | */ |
||
45 | protected $root; |
||
46 | |||
47 | /** |
||
48 | * @var TaxonInterface|null |
||
49 | */ |
||
50 | protected $parent; |
||
51 | |||
52 | /** |
||
53 | * @var Collection|TaxonInterface[] |
||
54 | */ |
||
55 | protected $children; |
||
56 | |||
57 | /** |
||
58 | * @var int|null |
||
59 | */ |
||
60 | protected $left; |
||
61 | |||
62 | /** |
||
63 | * @var int|null |
||
64 | */ |
||
65 | protected $right; |
||
66 | |||
67 | /** |
||
68 | * @var int|null |
||
69 | */ |
||
70 | protected $level; |
||
71 | |||
72 | /** |
||
73 | * @var int|null |
||
74 | */ |
||
75 | protected $position; |
||
76 | |||
77 | public function __construct() |
||
78 | { |
||
79 | $this->initializeTranslationsCollection(); |
||
80 | |||
81 | $this->children = new ArrayCollection(); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @return string |
||
86 | */ |
||
87 | public function __toString(): string |
||
88 | { |
||
89 | return (string) $this->getName(); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | public function getId() |
||
96 | { |
||
97 | return $this->id; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function getCode(): ?string |
||
104 | { |
||
105 | return $this->code; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | public function setCode(?string $code): void |
||
112 | { |
||
113 | $this->code = $code; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | public function isRoot(): bool |
||
120 | { |
||
121 | return null === $this->parent; |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function getRoot(): ?TaxonInterface |
||
128 | { |
||
129 | return $this->root; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | public function getParent(): ?TaxonInterface |
||
136 | { |
||
137 | return $this->parent; |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | public function setParent(?TaxonInterface $parent): void |
||
144 | { |
||
145 | $this->parent = $parent; |
||
146 | if (null !== $parent) { |
||
147 | $parent->addChild($this); |
||
148 | } |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | public function getAncestors(): Collection |
||
155 | { |
||
156 | $ancestors = []; |
||
157 | |||
158 | for ($ancestor = $this->getParent(); null !== $ancestor; $ancestor = $ancestor->getParent()) { |
||
159 | $ancestors[] = $ancestor; |
||
160 | } |
||
161 | |||
162 | return new ArrayCollection($ancestors); |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | public function getChildren(): Collection |
||
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | public function hasChild(TaxonInterface $taxon): bool |
||
180 | |||
181 | /** |
||
182 | * {@inheritdoc} |
||
183 | */ |
||
184 | public function hasChildren(): bool |
||
188 | |||
189 | /** |
||
190 | * {@inheritdoc} |
||
191 | */ |
||
192 | public function addChild(TaxonInterface $taxon): void |
||
202 | |||
203 | /** |
||
204 | * {@inheritdoc} |
||
205 | */ |
||
206 | public function removeChild(TaxonInterface $taxon): void |
||
214 | |||
215 | /** |
||
216 | * {@inheritdoc} |
||
217 | */ |
||
218 | public function getName(): ?string |
||
222 | |||
223 | /** |
||
224 | * {@inheritdoc} |
||
225 | */ |
||
226 | public function setName(?string $name): void |
||
230 | |||
231 | /** |
||
232 | * {@inheritdoc} |
||
233 | */ |
||
234 | public function getSlug(): ?string |
||
238 | |||
239 | /** |
||
240 | * {@inheritdoc} |
||
241 | */ |
||
242 | public function setSlug(?string $slug): void |
||
246 | |||
247 | /** |
||
248 | * {@inheritdoc} |
||
249 | */ |
||
250 | public function getDescription(): ?string |
||
254 | |||
255 | /** |
||
256 | * {@inheritdoc} |
||
257 | */ |
||
258 | public function setDescription(?string $description): void |
||
262 | |||
263 | /** |
||
264 | * {@inheritdoc} |
||
265 | */ |
||
266 | public function getLeft(): ?int |
||
270 | |||
271 | /** |
||
272 | * {@inheritdoc} |
||
273 | */ |
||
274 | public function setLeft(?int $left): void |
||
278 | |||
279 | /** |
||
280 | * {@inheritdoc} |
||
281 | */ |
||
282 | public function getRight(): ?int |
||
286 | |||
287 | /** |
||
288 | * {@inheritdoc} |
||
289 | */ |
||
290 | public function setRight(?int $right): void |
||
294 | |||
295 | /** |
||
296 | * {@inheritdoc} |
||
297 | */ |
||
298 | public function getLevel(): ?int |
||
302 | |||
303 | /** |
||
304 | * {@inheritdoc} |
||
305 | */ |
||
306 | public function setLevel(?int $level): void |
||
310 | |||
311 | /** |
||
312 | * {@inheritdoc} |
||
313 | */ |
||
314 | public function getPosition(): ?int |
||
318 | |||
319 | /** |
||
320 | * {@inheritdoc} |
||
321 | */ |
||
322 | public function setPosition(?int $position): void |
||
326 | |||
327 | /** |
||
328 | * @param string|null $locale |
||
329 | * |
||
330 | * @return TaxonTranslationInterface |
||
331 | */ |
||
332 | public function getTranslation(?string $locale = null): TranslationInterface |
||
333 | { |
||
334 | /** @var TaxonTranslationInterface $translation */ |
||
335 | $translation = $this->doGetTranslation($locale); |
||
336 | |||
339 | |||
340 | /** |
||
341 | * {@inheritdoc} |
||
342 | */ |
||
343 | protected function createTranslation(): TaxonTranslation |
||
347 | } |
||
348 |