ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Glyph.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\UI\Component as C;
29 
30 class Glyph implements C\Symbol\Glyph\Glyph
31 {
32  use ComponentHelper;
34  use Triggerer;
35 
36  private static array $types = [
37  self::SETTINGS,
38  self::COLLAPSE,
39  self::COLLAPSE_HORIZONTAL,
40  self::EXPAND,
41  self::ADD,
42  self::REMOVE,
43  self::UP,
44  self::DOWN,
45  self::BACK,
46  self::NEXT,
47  self::SORT_ASCENDING,
48  self::SORT_DESCENDING,
49  self::USER,
50  self::MAIL,
51  self::NOTIFICATION,
52  self::TAG,
53  self::NOTE,
54  self::COMMENT,
55  self::BRIEFCASE,
56  self::LIKE,
57  self::LOVE,
58  self::DISLIKE,
59  self::LAUGH,
60  self::ASTOUNDED,
61  self::SAD,
62  self::ANGRY,
63  self::EYEOPEN,
64  self::EYECLOSED,
65  self::ATTACHMENT,
66  self::RESET,
67  self::APPLY,
68  self::SEARCH,
69  self::HELP,
70  self::CALENDAR,
71  self::TIME,
72  self::CLOSE,
73  self::MORE,
74  self::DISCLOSURE,
75  self::LANGUAGE,
76  self::LOGIN,
77  self::LOGOUT,
78  self::BULLETLIST,
79  self::NUMBEREDLIST,
80  self::LISTINDENT,
81  self::LISTOUTDENT,
82  self::FILTER,
83  self::HEADER,
84  self::ITALIC,
85  self::BOLD,
86  self::LINK,
87  self::LAUNCH
88  ];
89 
90  private string $type;
91  private ?string $action;
92  private string $label;
93  private array $counters;
94  private bool $highlighted;
95  private bool $active = true;
96 
97  public function __construct(string $type, string $label, string $action = null)
98  {
99  $this->checkArgIsElement("type", $type, self::$types, "glyph type");
100 
101  $this->type = $type;
102  $this->label = $label;
103  $this->action = $action;
104  $this->counters = array();
105  $this->highlighted = false;
106  }
107 
111  public function getType(): string
112  {
113  return $this->type;
114  }
115 
119  public function getLabel(): string
120  {
121  return $this->label;
122  }
123 
127  public function getAction(): ?string
128  {
129  return $this->action;
130  }
131 
135  public function getCounters(): array
136  {
137  return array_values($this->counters);
138  }
139 
143  public function withCounter(Counter $counter): C\Symbol\Glyph\Glyph
144  {
145  $clone = clone $this;
146  $clone->counters[$counter->getType()] = $counter;
147  return $clone;
148  }
149 
153  public function isHighlighted(): bool
154  {
155  return $this->highlighted;
156  }
157 
161  public function withHighlight(): C\Symbol\Glyph\Glyph
162  {
163  $clone = clone $this;
164  $clone->highlighted = true;
165  return $clone;
166  }
167 
171  public function isActive(): bool
172  {
173  return $this->active;
174  }
175 
179  public function withUnavailableAction(): C\Symbol\Glyph\Glyph
180  {
181  $clone = clone $this;
182  $clone->active = false;
183  return $clone;
184  }
185 
189  public function withOnClick(Signal $signal): C\Clickable
190  {
191  return $this->withTriggeredSignal($signal, 'click');
192  }
193 
197  public function appendOnClick(Signal $signal): C\Clickable
198  {
199  return $this->appendTriggeredSignal($signal, 'click');
200  }
201 
205  public function withAction($action): C\Symbol\Glyph\Glyph
206  {
207  $clone = clone $this;
208  $clone->action = $action;
209  return $clone;
210  }
211 
215  public function isTabbable(): bool
216  {
217  $has_action = ($this->action !== null && $this->action !== "");
218  $has_signal = isset($this->triggered_signals['click']) && $this->triggered_signals['click'] !== null;
219  return ($has_signal || $has_action) && $this->isActive();
220  }
221 }
appendTriggeredSignal(C\Signal $signal, string $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:47
This tags a counter object.
Definition: Counter.php:28
withTriggeredSignal(C\Signal $signal, string $event)
Add a triggered signal, replacing any other signals registered on the same event. ...
Definition: Triggerer.php:62
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
__construct(string $type, string $label, string $action=null)
Definition: Glyph.php:97
getType()
Get the type of the counter.