ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AbstractParentItem.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27abstract class AbstractParentItem extends AbstractBaseItem implements isParent
28{
32 protected array $children = [];
33 protected int $amount = 0;
34
38 public function getChildren(): array
39 {
40 return $this->children;
41 }
42
46 public function withChildren(array $children): isParent
47 {
48 $clone = clone($this);
49 $clone->children = $children;
50
51 return $clone;
52 }
53
57 public function appendChild(isItem $child): isParent
58 {
59 $this->children[] = $child;
60
61 return $this;
62 }
63
67 public function hasChildren(): bool
68 {
69 return ($this->children !== []);
70 }
71
75 public function removeChild(isItem $child_to_remove): isParent
76 {
77 $this->children = array_filter($this->children, static fn(isItem $item): bool => $item !== $child_to_remove);
78
79 return $this;
80 }
81
82 public function calculateAmountOfChildren(): void
83 {
84 $this->amount = count($this->children);
85 }
86
87 public function getAmountOfChildren(bool $including_dropped = true): int
88 {
89 if ($including_dropped) {
90 return $this->amount;
91 }
92 return count($this->children);
93 }
94
95}