ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
MetaBarMainCollector.php
Go to the documentation of this file.
2 
3 use Closure;
9 
16 {
17 
21  private $providers = [];
25  private $items = [];
26 
27 
33  public function __construct(array $providers)
34  {
35  $this->providers = $providers;
36  }
37 
38 
39  public function collectStructure() : void
40  {
41  $items_to_merge = [];
42  foreach ($this->providers as $provider) {
43  $items_to_merge[] = $provider->getMetaBarItems();
44  }
45  $this->items = array_merge([], ...$items_to_merge);
46  }
47 
48 
49  public function filterItemsByVisibilty(bool $async_only = false) : void
50  {
51  $this->items = array_filter($this->items, $this->getVisibleFilter());
52  }
53 
54 
55  public function prepareItemsForUIRepresentation() : void
56  {
57  // TODO: Implement prepareItemsForUIRepresentation() method.
58  }
59 
60  public function cleanupItemsForUIRepresentation() : void
61  {
62  // TODO: Implement filterItemsByVisibilty() method.
63  }
64 
65  public function sortItemsForUIRepresentation() : void
66  {
67  $this->sortItems($this->items);
68  array_walk($this->items, $this->getChildSorter());
69  }
70 
71 
76  {
77  yield from $this->items;
78  }
79 
80 
84  public function hasItems() : bool
85  {
86  return count($this->items) > 0;
87  }
88 
89 
93  private function sortItems(&$items)
94  {
95  usort($items, $this->getItemSorter());
96  }
97 
98 
102  private function getItemSorter() : Closure
103  {
104  return function (isItem &$a, isItem &$b) {
105  return $a->getPosition() > $b->getPosition();
106  };
107  }
108 
109 
113  private function getChildSorter() : Closure
114  {
115  return function (isItem &$item) {
116  if ($item instanceof isParent) {
117  $children = $item->getChildren();
118  $this->sortItems($children);
119  $item = $item->withChildren($children);
120  }
121  };
122  }
123 
124 
128  protected function getVisibleFilter() : Closure
129  {
130  return static function (isItem $item) {
131  return ($item->isAvailable() && $item->isVisible());
132  };
133  }
134 }
__construct(array $providers)
MetaBarMainCollector constructor.
getPosition()
Return the default position for installation, this will be overridden by the configuration later...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples