ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  self::ENLARGE,
89  self::LIST_VIEW,
90  self::PREVIEW,
91  self::SORT,
92  self::COLUMN_SELECTION,
93  self::TILE_VIEW,
94  self::DRAG_HANDLE,
95  self::CHECKED,
96  self::UNCHECKED,
97  ];
98 
99  private string $type;
100  private ?string $action;
101  private string $label;
102  private array $counters;
103  private bool $highlighted;
104  private bool $active = true;
105 
106  public function __construct(string $type, string $label, ?string $action = null)
107  {
108  $this->checkArgIsElement("type", $type, self::$types, "glyph type");
109 
110  $this->type = $type;
111  $this->label = $label;
112  // @deprecated with 10 - parameter $action will be removed; use a Button with a Glyph as label
113  $this->action = $action;
114  $this->counters = array();
115  $this->highlighted = false;
116  }
117 
118  public function getType(): string
119  {
120  return $this->type;
121  }
122 
123  public function getLabel(): string
124  {
125  return $this->label;
126  }
127 
128  public function withLabel(string $label): self
129  {
130  $clone = clone $this;
131  $clone->label = $label;
132  return $clone;
133  }
134 
138  public function getAction(): ?string
139  {
140  return $this->action;
141  }
142 
143  public function getCounters(): array
144  {
145  return array_values($this->counters);
146  }
147 
148  public function withCounter(Counter $counter): C\Symbol\Glyph\Glyph
149  {
150  $clone = clone $this;
151  $clone->counters[$counter->getType()] = $counter;
152  return $clone;
153  }
154 
155  public function isHighlighted(): bool
156  {
157  return $this->highlighted;
158  }
159 
160  public function withHighlight(): C\Symbol\Glyph\Glyph
161  {
162  $clone = clone $this;
163  $clone->highlighted = true;
164  return $clone;
165  }
166 
170  public function isActive(): bool
171  {
172  return $this->active;
173  }
174 
178  public function withUnavailableAction(): C\Symbol\Glyph\Glyph
179  {
180  $clone = clone $this;
181  $clone->active = false;
182  return $clone;
183  }
184 
188  public function withOnClick(Signal $signal): C\Clickable
189  {
190  return $this->withTriggeredSignal($signal, 'click');
191  }
192 
196  public function appendOnClick(Signal $signal): C\Clickable
197  {
198  return $this->appendTriggeredSignal($signal, 'click');
199  }
200 
204  public function withAction($action): C\Symbol\Glyph\Glyph
205  {
206  $clone = clone $this;
207  $clone->action = $action;
208  return $clone;
209  }
210 
214  public function isTabbable(): bool
215  {
216  $has_action = ($this->action !== null && $this->action !== "");
217  $has_signal = isset($this->triggered_signals['click']) && $this->triggered_signals['click'] !== null;
218  return ($has_signal || $has_action) && $this->isActive();
219  }
220 }
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
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
getType()
Get the type of the counter.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(string $type, string $label, ?string $action=null)
Definition: Glyph.php:106