ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
AbstractBaseItem.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 use Closure;
29 
34 abstract class AbstractBaseItem implements isItem
35 {
37 
38  protected int $position = 0;
39 
40  private ?bool $is_visible_static = null;
41 
43  protected ?Closure $available_callable = null;
44  protected ?Closure $active_callable = null;
45  protected ?Closure $visiblility_callable = null;
46  protected bool $is_always_available = false;
48  protected ?Legacy $non_available_reason = null;
49 
54  public function __construct(IdentificationInterface $provider_identification)
55  {
56  $this->provider_identification = $provider_identification;
57  }
58 
63  {
65  }
66 
70  public function withVisibilityCallable(callable $is_visible): isItem
71  {
72  $clone = clone($this);
73  $clone->visiblility_callable = $is_visible;
74  $clone->is_visible_static = null;
75 
76  return $clone;
77  }
78 
82  public function isVisible(): bool
83  {
84  if (isset($this->is_visible_static)) {
86  }
87  if (!$this->isAvailable()) {
88  return $this->is_visible_static = false;
89  }
90  if (is_callable($this->visiblility_callable)) {
91  $callable = $this->visiblility_callable;
92 
93  $value = (bool) $callable();
94 
95  return $this->is_visible_static = $value;
96  }
97 
98  return $this->is_visible_static = true;
99  }
100 
104  public function withAvailableCallable(callable $is_available): isItem
105  {
106  $clone = clone($this);
107  $clone->available_callable = $is_available;
108 
109  return $clone;
110  }
111 
115  public function isAvailable(): bool
116  {
117  if ($this->isAlwaysAvailable() === true) {
118  return true;
119  }
120  if (is_callable($this->available_callable)) {
121  $callable = $this->available_callable;
122 
123  return (bool) $callable();
124  }
125 
126  return true;
127  }
128 
132  public function withNonAvailableReason(Legacy $element): isItem
133  {
134  $clone = clone $this;
135  $clone->non_available_reason = $element;
136 
137  return $clone;
138  }
139 
143  public function getNonAvailableReason(): Legacy
144  {
145  global $DIC;
146 
147  return $this->non_available_reason instanceof Legacy ? $this->non_available_reason : $DIC->ui()->factory()->legacy("");
148  }
149 
153  public function isAlwaysAvailable(): bool
154  {
156  }
157 
161  public function withAlwaysAvailable(bool $always_active): isItem
162  {
163  $clone = clone($this);
164  $clone->is_always_available = $always_active;
165 
166  return $clone;
167  }
168 
172  public function getPosition(): int
173  {
174  return $this->position;
175  }
176 
180  public function withPosition(int $position): isItem
181  {
182  $clone = clone($this);
183  $clone->position = $position;
184 
185  return $clone;
186  }
187 
191  public function setTypeInformation(TypeInformation $information): isItem
192  {
193  $this->type_information = $information;
194 
195  return $this;
196  }
197 
202  {
204  }
205 
206  public function isTop(): bool
207  {
208  if ($this instanceof isInterchangeableItem) {
209  $changed = $this->hasChanged();
210  if ($this instanceof isChild) {
211  return $changed;
212  } elseif ($this instanceof isTopItem) {
213  return !$changed;
214  }
215  }
216 
217  return $this instanceof isTopItem;
218  }
219 }
__construct(IdentificationInterface $provider_identification)
AbstractBaseItem constructor.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...