ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
AbstractBaseItem.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 use Closure;
29 
33 abstract class AbstractBaseItem implements
34  isItem,
36 {
38 
40  protected int $position = 0;
43 
44  public function __construct(protected IdentificationInterface $provider_identification)
45  {
46  $this->renderer = new BaseMetaBarItemRenderer();
47  }
48 
49  public function getRenderer(): MetaBarItemRenderer
50  {
51  return $this->renderer;
52  }
53 
55  {
56  return $this->provider_identification;
57  }
58 
59  public function withVisibilityCallable(callable $is_visible): isItem
60  {
61  $clone = clone($this);
62  $clone->visiblility_callable = $is_visible;
63 
64  return $clone;
65  }
66 
67  public function isVisible(): bool
68  {
69  if (!$this->isAvailable()) {
70  return false;
71  }
72  if (is_callable($this->visiblility_callable)) {
73  $callable = $this->visiblility_callable;
74 
75  return $callable();
76  }
77 
78  return true;
79  }
80 
81  public function withAvailableCallable(callable $is_available): isItem
82  {
83  $clone = clone($this);
84  $clone->available_callable = $is_available;
85 
86  return $clone;
87  }
88 
89  public function isAvailable(): bool
90  {
91  if (is_callable($this->available_callable)) {
92  $callable = $this->available_callable;
93 
94  return $callable();
95  }
96 
97  return true;
98  }
99 
100  public function getPosition(): int
101  {
102  return $this->position;
103  }
104 
105  public function withPosition(int $position): isItem
106  {
107  $clone = clone($this);
108  $clone->position = $position;
109 
110  return $clone;
111  }
112 }
withAvailableCallable(callable $is_available)
Pass a callable which can decide whether your element is available in general, e.g.
renderer()
getPosition()
Return the default position for installation, this will be overridden by the configuration later...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(protected IdentificationInterface $provider_identification)
withVisibilityCallable(callable $is_visible)
Pass a callable which can decide whether your element is visible for the current user.