ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 use Engageable;
20
24 protected $action_off = null;
25
29 protected $action_on = null;
30
34 public function __construct($label, $action_on, $action_off, $is_on, Signal $click = null)
35 {
36 $this->checkStringOrSignalArg("action", $action_on);
37 $this->checkStringOrSignalArg("action_off", $action_off);
38 $this->checkBoolArg("is_on", $is_on);
39
40 // no way to resolve conflicting string actions
41 $button_action = (is_null($click)) ? "" : $click;
42
43 parent::__construct($label, $button_action);
44
45 if (is_string($action_on)) {
46 $this->action_on = $action_on;
47 } else {
48 $this->setTriggeredSignal($action_on, "toggle_on");
49 }
50
51 if (is_string($action_off)) {
52 $this->action_off = $action_off;
53 } else {
54 $this->setTriggeredSignal($action_off, "toggle_off");
55 }
56
57 $this->is_engageable = true;
58 $this->engaged = $is_on;
59 }
60
64 public function getActionOff()
65 {
66 if ($this->action_off !== null) {
67 return $this->action_off;
68 }
69
70 return $this->getTriggeredSignalsFor("toggle_off");
71 }
72
76 public function getActionOn()
77 {
78 if ($this->action_on !== null) {
79 return $this->action_on;
80 }
81
82 return $this->getTriggeredSignalsFor("toggle_on");
83 }
84
89 {
90 return $this->appendTriggeredSignal($signal, "toggle_on");
91 }
92
97 {
98 return $this->appendTriggeredSignal($signal, "toggle_off");
99 }
100}
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:34
A component is the most general form of an entity in the UI.
Definition: Component.php:14
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
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 ChatMainBarProvider \MainMenu\Provider.
Class Factory.