ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Toggle.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2018 Thomas Famula <famula@leifos.de> Extended GPL, see docs/LICENSE */
4
6
13
14class Toggle extends Button implements C\Button\Toggle
15{
18 use Triggerer;
19
23 protected $is_on;
24
28 protected $action_off = null;
29
33 protected $action_on = null;
34
38 public function __construct($label, $action_on, $action_off, $is_on, Signal $click = null)
39 {
40 $this->checkStringOrSignalArg("action", $action_on);
41 $this->checkStringOrSignalArg("action_off", $action_off);
42 $this->checkBoolArg("is_on", $is_on);
43
44 // no way to resolve conflicting string actions
45 $button_action = (is_null($click)) ? "" : $click;
46
47 parent::__construct($label, $button_action);
48
49 if (is_string($action_on)) {
50 $this->action_on = $action_on;
51 } else {
52 $this->setTriggeredSignal($action_on, "toggle_on");
53 }
54
55 if (is_string($action_off)) {
56 $this->action_off = $action_off;
57 } else {
58 $this->setTriggeredSignal($action_off, "toggle_off");
59 }
60
61 $this->is_on = $is_on;
62 }
63
67 public function isOn() : bool
68 {
69 return $this->is_on;
70 }
71
75 public function getActionOff()
76 {
77 if ($this->action_off !== null) {
78 return $this->action_off;
79 }
80
81 return $this->getTriggeredSignalsFor("toggle_off");
82 }
83
87 public function getActionOn()
88 {
89 if ($this->action_on !== null) {
90 return $this->action_on;
91 }
92
93 return $this->getTriggeredSignalsFor("toggle_on");
94 }
95
100 {
101 return $this->appendTriggeredSignal($signal, "toggle_on");
102 }
103
108 {
109 return $this->appendTriggeredSignal($signal, "toggle_off");
110 }
111}
An exception for terminatinating execution or to throw for unit testing.
__construct($label, $action_on, $action_off, $is_on, Signal $click=null)
Definition: Toggle.php:38
A component is the most general form of an entity in the UI.
Definition: Component.php:14
checkStringOrSignalArg($which, $value)
Throw an InvalidArgumentException if $value is no string or Signal.
appendTriggeredSignal(Component\Signal $signal, $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:31
setTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any othe signals registered on the same event.
Definition: Triggerer.php:65
getTriggeredSignalsFor($event)
Get signals that are triggered for a certain event.
Definition: Triggerer.php:85
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
checkBoolArg($which, $value)
Throw an InvalidArgumentException if $value is not a bool.
trait ComponentHelper
Provides common functionality for component implementations.
Class BaseForm.
Class Factory.