ILIAS  release_8 Revision v8.24
LinkList.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ILIAS\GlobalScreen\Scope\MainMenu\Factory\isInterchangeableItemTrait;
32use InvalidArgumentException;
33use ReflectionFunction;
34use ReflectionException;
35use Generator;
36
41class LinkList extends AbstractChildItem implements
47{
50 use isInterchangeableItemTrait;
51
52 protected string $title = '';
56 protected array $links = [];
57 protected bool $supports_async_loading = false;
58
63 public function withTitle(string $title): hasTitle
64 {
65 $clone = clone($this);
66 $clone->title = $title;
67
68 return $clone;
69 }
70
74 public function getTitle(): string
75 {
76 return $this->title;
77 }
78
82 public function withLinks($links): self
83 {
84 if (is_callable($links)) {
85 try {
86 $r = new ReflectionFunction($links);
87 $links = $r->isGenerator() ? iterator_to_array($links()) : $links();
88 } catch (ReflectionException $e) {
89 $links = false;
90 }
91
92 if (!is_array($links)) {
93 throw new InvalidArgumentException("withLinks only accepts arrays of Links or a callable providing them");
94 }
95 }
96 foreach ($links as $link) {
97 if (!$link instanceof Link) {
98 throw new InvalidArgumentException("withLinks only accepts arrays of Links or a callable providing them");
99 }
100 }
101 $clone = clone($this);
102 $clone->links = $links;
103
104 return $clone;
105 }
106
110 public function getLinks(): array
111 {
112 return $this->links;
113 }
114
119 {
120 $clone = clone($this);
121 $clone->supports_async_loading = $supported;
122
123 return $clone;
124 }
125
129 public function supportsAsynchronousLoading(): bool
130 {
132 }
133
134 public function isVisible(): bool
135 {
136 $visible_links = 0;
137 foreach ($this->getLinks() as $link) {
138 if ($link->isVisible()) {
139 $visible_links++;
140 }
141 }
142 return $visible_links > 0 && parent::isVisible();
143 }
144}
Interface hasSymbol Methods for Entries with Symbols.
Definition: hasSymbol.php:33
Interface supportsAsynchronousLoading Types, which implement this interface, can load their content a...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Complex.php:21
trait hasSymbolTrait
Trait hasSymbolTrait.