Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
button.php
1<?php
2
3namespace Bitrix\UI\Buttons;
4
5class Button extends BaseButton
6{
8 protected $properties = [];
9
10 protected function init(array $params = [])
11 {
13
14 if (isset($params['baseClassName']))
15 {
16 $this->baseClass = $params['baseClassName'];
17 }
18
19 parent::init($params);
20 }
21
28 protected function isEnumValue($value, $enum)
29 {
30 try
31 {
32 return in_array($value, (new \ReflectionClass($enum))->getConstants(), true);
33 }
34 catch (\ReflectionException $e)
35 {}
36
37 return false;
38 }
39
47 protected function setProperty($propertyName, $value, $enum)
48 {
49 if ($this->isEnumValue($value, $enum))
50 {
51 $this
52 ->removeClass($this->getProperty($propertyName))
53 ->addClass($value)
54 ;
55 $this->properties[$propertyName] = $value;
56 }
57 elseif ($value === null)
58 {
59 $this->removeClass($this->getProperty($propertyName));
60 $this->properties[$propertyName] = $value;
61 }
62
63 return $this;
64 }
65
72 protected function getProperty($name, $defaultValue = null)
73 {
74 if (isset($this->properties[$name]))
75 {
76 return $this->properties[$name];
77 }
78
79 return $defaultValue;
80 }
81
82 protected function buildFromArray($params)
83 {
84 parent::buildFromArray($params);
85
86 if (isset($params['color']))
87 {
88 $this->setColor($params['color']);
89 }
90
91 if (isset($params['icon']))
92 {
93 $this->setIcon($params['icon']);
94 }
95
96 if (isset($params['state']))
97 {
98 $this->setState($params['state']);
99 }
100
101 if (isset($params['size']))
102 {
103 $this->setSize($params['size']);
104 }
105
106 if (isset($params['menu']))
107 {
108 $this->setMenu($params['menu']);
109 }
110
111 if (isset($params['noCaps']))
112 {
113 $this->setNoCaps($params['noCaps']);
114 }
115
116 if (isset($params['round']))
117 {
118 $this->setRound($params['round']);
119 }
120
121 $isDropdown = $params['dropdown'] ?? null;
122 if ($isDropdown || (isset($params['menu']) && $isDropdown !== false))
123 {
124 $this->setDropdown();
125 }
126 elseif ($isDropdown === false)
127 {
128 $this->getAttributeCollection()->addJsonOption('dropdown', false);
129 }
130 }
131
132 public function setIcon($icon)
133 {
134 return $this->setProperty('icon', $icon, Icon::class);
135 }
136
137 public function getIcon()
138 {
139 return $this->getProperty('icon');
140 }
141
148 public function setColor($color)
149 {
150 return $this->setProperty('color', $color, Color::class);
151 }
152
156 public function getColor()
157 {
158 return $this->getProperty('color');
159 }
160
168 public function setSize($size)
169 {
170 return $this->setProperty('size', $size, Size::class);
171 }
172
176 public function getSize()
177 {
178 return $this->getProperty('size');
179 }
180
187 public function setState($state)
188 {
189 return $this->setProperty('state', $state, State::class);
190 }
191
195 public function getState()
196 {
197 return $this->getProperty('state');
198 }
199
205 public function setActive($flag = true)
206 {
207 if ($flag)
208 {
209 $this->setState(State::ACTIVE);
210 }
211 else
212 {
213 $this->setState(null);
214 }
215
216 return $this;
217 }
218
222 public function isActive()
223 {
224 return $this->getState() === State::ACTIVE;
225 }
226
232 public function setHovered($flag = true)
233 {
234 if ($flag)
235 {
236 $this->setState(State::HOVER);
237 }
238 else
239 {
240 $this->setState(null);
241 }
242
243 return $this;
244 }
245
249 public function isHover()
250 {
251 return $this->getState() === State::HOVER;
252 }
253
259 public function setDisabled($flag = true)
260 {
261 if ($flag)
262 {
264 }
265 else
266 {
267 $this->setState(null);
268 }
269
270 return parent::setDisabled($flag);
271 }
272
276 public function isDisabled()
277 {
278 return $this->getState() === State::DISABLED;
279 }
280
286 public function setWaiting($flag = true)
287 {
288 if ($flag)
289 {
290 $this->setState(State::WAITING);
291 parent::setDisabled(true);
292 }
293 else
294 {
295 $this->setState(null);
296 parent::setDisabled(false);
297 }
298
299 return $this;
300 }
301
305 public function isWaiting()
306 {
307 return $this->getState() === State::WAITING;
308 }
309
315 public function setClocking($flag = true)
316 {
317 if ($flag)
318 {
320 parent::setDisabled(true);
321 }
322 else
323 {
324 $this->setState(null);
325 parent::setDisabled(false);
326 }
327
328 return $this;
329 }
330
334 public function isClocking()
335 {
336 return $this->getState() === State::CLOCKING;
337 }
338
343 public function setNoCaps($flag = true)
344 {
345 if ($flag === false)
346 {
348 }
349 else
350 {
351 $this->addClass(Style::NO_CAPS);
352 }
353
354 return $this;
355 }
356
360 public function isNoCaps()
361 {
362 return $this->hasClass(Style::NO_CAPS);
363 }
364
369 public function setRound($flag = true)
370 {
371 if ($flag === false)
372 {
374 }
375 else
376 {
377 $this->addClass(Style::ROUND);
378 }
379
380 return $this;
381 }
382
386 public function isRound()
387 {
388 return $this->hasClass(Style::ROUND);
389 }
390
395 public function setDropdown($flag = true)
396 {
397 if ($flag === false)
398 {
400 }
401 else
402 {
404 }
405
406 return $this;
407 }
408
412 public function isDropdown()
413 {
414 return $this->hasClass(Style::DROPDOWN);
415 }
416
421 public function setCollapsed($flag = true)
422 {
423 if ($flag === false)
424 {
426 }
427 else
428 {
430 }
431
432 return $this;
433 }
434
438 public function isCollapsed()
439 {
440 return $this->hasClass(Style::COLLAPSED);
441 }
442
448 public function setMenu($options)
449 {
450 $this->getAttributeCollection()->addJsonOption('menu', $options);
451
452 return $this;
453 }
454}
setActive($flag=true)
Definition button.php:205
setCollapsed($flag=true)
Definition button.php:421
setClocking($flag=true)
Definition button.php:315
getProperty($name, $defaultValue=null)
Definition button.php:72
setHovered($flag=true)
Definition button.php:232
setNoCaps($flag=true)
Definition button.php:343
setProperty($propertyName, $value, $enum)
Definition button.php:47
setDisabled($flag=true)
Definition button.php:259
setDropdown($flag=true)
Definition button.php:395
isEnumValue($value, $enum)
Definition button.php:28
setWaiting($flag=true)
Definition button.php:286
init(array $params=[])
Definition button.php:10