ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
AdministrativeNotification.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
21 
26 use Closure;
27 
34 {
35  public const DENOTATION_NEUTRAL = 'neutral';
36  public const DENOTATION_IMPORTANT = 'important';
37  public const DENOTATION_BREAKING = 'breaking';
38 
39  private bool $is_visible_static;
40 
42 
43  protected string $title;
44 
45  protected string $summary;
46 
47  protected ?Closure $available_callable = null;
48  protected ?Closure $visiblility_callable = null;
49  protected bool $is_always_available = false;
50  protected string $denotation = self::DENOTATION_NEUTRAL;
51 
56  {
57  return new AdministrativeNotificationRenderer($factory);
58  }
59 
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 withSummary(string $summary): isItem
83  {
84  $clone = clone $this;
85  $clone->summary = $summary;
86 
87  return $clone;
88  }
89 
93  public function getSummary(): string
94  {
95  return $this->summary;
96  }
97 
98  public function withVisibilityCallable(callable $is_visible): self
99  {
100  $clone = clone($this);
101  $clone->visiblility_callable = $is_visible;
102 
103  return $clone;
104  }
105 
106  public function isVisible(): bool
107  {
108  if (isset($this->is_visible_static)) {
110  }
111  if (!$this->isAvailable()) {
112  return $this->is_visible_static = false;
113  }
114  if (is_callable($this->visiblility_callable)) {
115  $callable = $this->visiblility_callable;
116 
117  $value = $callable();
118 
119  return $this->is_visible_static = $value;
120  }
121 
122  return $this->is_visible_static = true;
123  }
124 
125  public function isAvailable(): bool
126  {
127  if (is_callable($this->available_callable)) {
128  $callable = $this->available_callable;
129 
130  return $callable();
131  }
132 
133  return true;
134  }
135 
136  public function withAvailableCallable(callable $is_available): self
137  {
138  $clone = clone($this);
139  $clone->available_callable = $is_available;
140 
141  return $clone;
142  }
143 
144  public function withNeutralDenotation(): self
145  {
146  $clone = clone($this);
147  $clone->denotation = self::DENOTATION_NEUTRAL;
148 
149  return $clone;
150  }
151 
152  public function withImportantDenotation(): self
153  {
154  $clone = clone($this);
155  $clone->denotation = self::DENOTATION_IMPORTANT;
156 
157  return $clone;
158  }
159 
160  public function withBreakingDenotation(): self
161  {
162  $clone = clone($this);
163  $clone->denotation = self::DENOTATION_BREAKING;
164 
165  return $clone;
166  }
167 
168  public function getDenotation(): string
169  {
170  return $this->denotation ?? self::DENOTATION_NEUTRAL;
171  }
172 }
Interface NotificationRenderer Every Notification should have a renderer, if you won&#39;t provide on in ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$factory
Definition: metadata.php:75