ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
VisibilityAvailabilityTrait.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\GlobalScreen\Scope;
22 
23 use Closure;
24 
29 {
30  protected ?Closure $available_callable = null;
32 
33  private ?bool $is_visible_static = null;
34 
35  public function withVisibilityCallable(callable $is_visible): self
36  {
37  $clone = clone($this);
38  $clone->visiblility_callable = $is_visible;
39  $clone->is_visible_static = null;
40 
41  return $clone;
42  }
43 
44  public function isVisible(): bool
45  {
46  if (isset($this->is_visible_static)) {
48  }
49  if (!$this->isAvailable()) {
50  return $this->is_visible_static = false;
51  }
52  if (is_callable($this->visiblility_callable)) {
53  $callable = $this->visiblility_callable;
54 
55  $value = (bool) $callable();
56 
57  return $this->is_visible_static = $value;
58  }
59 
60  return $this->is_visible_static = true;
61  }
62 
63  public function withAvailableCallable(callable $is_available): self
64  {
65  $clone = clone($this);
66  $clone->available_callable = $is_available;
67 
68  return $clone;
69  }
70 
71  public function isAvailable(): bool
72  {
73  if ($this->isAlwaysAvailable() === true) {
74  return true;
75  }
76  if (is_callable($this->available_callable)) {
77  $callable = $this->available_callable;
78 
79  return (bool) $callable();
80  }
81 
82  return true;
83  }
84 
85  public function isAlwaysAvailable(): bool
86  {
87  return false;
88  }
89 }
withAvailableCallable(callable $is_available)
withVisibilityCallable(callable $is_visible)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null