ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
LinkList.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
35 use Generator;
36 
41 class LinkList extends AbstractChildItem implements
42  hasTitle,
44  hasSymbol,
46  isChild
47 {
49  use hasSymbolTrait;
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  if ($r->isGenerator()) {
88  $links = iterator_to_array($links());
89  } else {
90  $links = $links();
91  }
92  } catch (ReflectionException $e) {
93  $links = false;
94  }
95 
96  if (!is_array($links)) {
97  throw new InvalidArgumentException("withLinks only accepts arrays of Links or a callable providing them");
98  }
99  }
100  foreach ($links as $link) {
101  if (!$link instanceof Link) {
102  throw new InvalidArgumentException("withLinks only accepts arrays of Links or a callable providing them");
103  }
104  }
105  $clone = clone($this);
106  $clone->links = $links;
107 
108  return $clone;
109  }
110 
114  public function getLinks(): array
115  {
116  return $this->links;
117  }
118 
123  {
124  $clone = clone($this);
125  $clone->supports_async_loading = $supported;
126 
127  return $clone;
128  }
129 
133  public function supportsAsynchronousLoading(): bool
134  {
136  }
137 
138  public function isVisible(): bool
139  {
140  $visible_links = 0;
141  foreach ($this->getLinks() as $link) {
142  if ($link->isVisible()) {
143  $visible_links++;
144  }
145  }
146  return $visible_links > 0 && parent::isVisible();
147  }
148 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Complex.php:21
Interface supportsAsynchronousLoading Types, which implement this interface, can load their content a...
Interface hasSymbol Methods for Entries with Symbols.
Definition: hasSymbol.php:32
trait hasSymbolTrait
Trait hasSymbolTrait.
$r