ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
AbstractBaseItem.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 use Closure;
30 
34 abstract class AbstractBaseItem implements
35  isItem,
37 {
39 
41  protected int $position = 0;
42  protected ?Closure $available_callable = null;
43  protected ?Closure $visiblility_callable = null;
44 
45  public function __construct(protected IdentificationInterface $provider_identification)
46  {
47  $this->renderer = new BaseMetaBarItemRenderer();
48  }
49 
50  public function getRenderer(): MetaBarItemRenderer
51  {
52  return $this->renderer;
53  }
54 
56  {
57  return $this->provider_identification;
58  }
59 
60  public function withVisibilityCallable(callable $is_visible): isItem
61  {
62  $clone = clone($this);
63  $clone->visiblility_callable = $is_visible;
64 
65  return $clone;
66  }
67 
68  public function isVisible(): bool
69  {
70  if (!$this->isAvailable()) {
71  return false;
72  }
73  if (is_callable($this->visiblility_callable)) {
74  $callable = $this->visiblility_callable;
75 
76  return $callable();
77  }
78 
79  return true;
80  }
81 
82  public function withAvailableCallable(callable $is_available): isItem
83  {
84  $clone = clone($this);
85  $clone->available_callable = $is_available;
86 
87  return $clone;
88  }
89 
90  public function isAvailable(): bool
91  {
92  if (is_callable($this->available_callable)) {
93  $callable = $this->available_callable;
94 
95  return $callable();
96  }
97 
98  return true;
99  }
100 
101  public function getPosition(): int
102  {
103  return $this->position;
104  }
105 
106  public function withPosition(int $position): isItem
107  {
108  $clone = clone($this);
109  $clone->position = $position;
110 
111  return $clone;
112  }
113 }
withAvailableCallable(callable $is_available)
Pass a callable which can decide whether your element is available in general, e.g.
getPosition()
Return the default position for installation, this will be overridden by the configuration later...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(protected IdentificationInterface $provider_identification)
withVisibilityCallable(callable $is_visible)
Pass a callable which can decide whether your element is visible for the current user.