ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Glyph.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
13
14class Glyph implements C\Glyph\Glyph
15{
18 use Triggerer;
19
23 private $type;
24
28 private $action;
29
33 private $aria_label;
34
38 private $counters;
39
43 private $highlighted = false;
44
48 private $active = true;
49
50 private static $types = array(self::SETTINGS
51 , self::COLLAPSE
52 , self::EXPAND
53 , self::ADD
54 , self::REMOVE
55 , self::UP
56 , self::DOWN
57 , self::BACK
58 , self::NEXT
59 , self::SORT_ASCENDING
60 , self::SORT_DESCENDING
61 , self::SORT
62 , self::USER
63 , self::MAIL
64 , self::NOTIFICATION
65 , self::TAG
66 , self::NOTE
67 , self::COMMENT
68 , self::BRIEFCASE
69 , self::LIKE
70 , self::LOVE
71 , self::DISLIKE
72 , self::LAUGH
73 , self::ASTOUNDED
74 , self::SAD
75 , self::ANGRY
76 , self::EYEOPEN
77 , self::EYECLOSED
78 , self::ATTACHMENT
79 , self::RESET
80 , self::APPLY
81 );
82
83
88 public function __construct($type, $aria_label, $action = null)
89 {
90 $this->checkArgIsElement("type", $type, self::$types, "glyph type");
91 $this->checkStringArg("string", $aria_label);
92
93 if ($action !== null) {
94 $this->checkStringArg("action", $action);
95 }
96 $this->type = $type;
97 $this->aria_label = $aria_label;
98 $this->action = $action;
99 $this->counters = array();
100 $this->highlighted = false;
101 }
102
106 public function getType()
107 {
108 return $this->type;
109 }
113 public function getAriaLabel()
114 {
115 return $this->aria_label;
116 }
117
121 public function getAction()
122 {
123 return $this->action;
124 }
125
129 public function getCounters()
130 {
131 return array_values($this->counters);
132 }
133
137 public function withCounter(Counter $counter)
138 {
139 $clone = clone $this;
140 $clone->counters[$counter->getType()] = $counter;
141 return $clone;
142 }
143
147 public function isHighlighted()
148 {
149 return $this->highlighted;
150 }
151
155 public function withHighlight()
156 {
157 $clone = clone $this;
158 $clone->highlighted = true;
159 return $clone;
160 }
161
165 public function isActive()
166 {
167 return $this->active;
168 }
169
173 public function withUnavailableAction()
174 {
175 $clone = clone $this;
176 $clone->active = false;
177 return $clone;
178 }
179
180
184 public function withOnClick(Signal $signal)
185 {
186 return $this->withTriggeredSignal($signal, 'click');
187 }
188
192 public function appendOnClick(Signal $signal)
193 {
194 return $this->appendTriggeredSignal($signal, 'click');
195 }
196}
An exception for terminatinating execution or to throw for unit testing.
__construct($type, $aria_label, $action=null)
Definition: Glyph.php:88
This tags a counter object.
Definition: Counter.php:11
getType()
Get the type of the counter.
withTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any other signals registered on the same event.
Definition: Triggerer.php:48
checkStringArg($which, $value)
Throw an InvalidArgumentException if $value is no string.
appendTriggeredSignal(Component\Signal $signal, $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:31
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
trait ComponentHelper
Provides common functionality for component implementations.
checkArgIsElement($which, $value, $array, $name)
Throw an InvalidArgumentException if $value is not an element of array.