ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
AbstractParentItem.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
21 
26 abstract class AbstractParentItem extends AbstractBaseItem implements isParent
27 {
31  protected array $children = [];
32 
36  public function getChildren(): array
37  {
38  return $this->children;
39  }
40 
44  public function withChildren(array $children): isParent
45  {
46  $clone = clone($this);
47  $clone->children = $children;
48 
49  return $clone;
50  }
51 
55  public function appendChild(isItem $child): isParent
56  {
57  $this->children[] = $child;
58 
59  return $this;
60  }
61 
65  public function hasChildren(): bool
66  {
67  return (count($this->children) > 0);
68  }
69 
73  public function removeChild(isItem $child_to_remove): isParent
74  {
75  $this->children = array_filter($this->children, static function (isItem $item) use ($child_to_remove): bool {
76  return $item !== $child_to_remove;
77  });
78 
79  return $this;
80  }
81 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...