ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  ];
96 
97  private string $type;
98  private ?string $action;
99  private string $label;
100  private array $counters;
101  private bool $highlighted;
102  private bool $active = true;
103 
104  public function __construct(string $type, string $label, ?string $action = null)
105  {
106  $this->checkArgIsElement("type", $type, self::$types, "glyph type");
107 
108  $this->type = $type;
109  $this->label = $label;
110  // @deprecated with 10 - parameter $action will be removed; use a Button with a Glyph as label
111  $this->action = $action;
112  $this->counters = array();
113  $this->highlighted = false;
114  }
115 
116  public function getType(): string
117  {
118  return $this->type;
119  }
120 
121  public function getLabel(): string
122  {
123  return $this->label;
124  }
125 
126  public function withLabel(string $label): self
127  {
128  $clone = clone $this;
129  $clone->label = $label;
130  return $clone;
131  }
132 
136  public function getAction(): ?string
137  {
138  return $this->action;
139  }
140 
141  public function getCounters(): array
142  {
143  return array_values($this->counters);
144  }
145 
146  public function withCounter(Counter $counter): C\Symbol\Glyph\Glyph
147  {
148  $clone = clone $this;
149  $clone->counters[$counter->getType()] = $counter;
150  return $clone;
151  }
152 
153  public function isHighlighted(): bool
154  {
155  return $this->highlighted;
156  }
157 
158  public function withHighlight(): C\Symbol\Glyph\Glyph
159  {
160  $clone = clone $this;
161  $clone->highlighted = true;
162  return $clone;
163  }
164 
168  public function isActive(): bool
169  {
170  return $this->active;
171  }
172 
176  public function withUnavailableAction(): C\Symbol\Glyph\Glyph
177  {
178  $clone = clone $this;
179  $clone->active = false;
180  return $clone;
181  }
182 
186  public function withOnClick(Signal $signal): C\Clickable
187  {
188  return $this->withTriggeredSignal($signal, 'click');
189  }
190 
194  public function appendOnClick(Signal $signal): C\Clickable
195  {
196  return $this->appendTriggeredSignal($signal, 'click');
197  }
198 
202  public function withAction($action): C\Symbol\Glyph\Glyph
203  {
204  $clone = clone $this;
205  $clone->action = $action;
206  return $clone;
207  }
208 
212  public function isTabbable(): bool
213  {
214  $has_action = ($this->action !== null && $this->action !== "");
215  $has_signal = isset($this->triggered_signals['click']) && $this->triggered_signals['click'] !== null;
216  return ($has_signal || $has_action) && $this->isActive();
217  }
218 }
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:104