ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
7 use ILIAS\UI\Component as C;
13 
14 class Toggle extends Button implements C\Button\Toggle
15 {
16  use ComponentHelper;
18  use Triggerer;
19 
23  protected $action_off = null;
24 
28  protected $action_on = null;
29 
33  public function __construct($label, $action_on, $action_off, $is_on, Signal $click = null)
34  {
35  $this->checkStringOrSignalArg("action", $action_on);
36  $this->checkStringOrSignalArg("action_off", $action_off);
37  $this->checkBoolArg("is_on", $is_on);
38 
39  // no way to resolve conflicting string actions
40  $button_action = (is_null($click)) ? "" : $click;
41 
42  parent::__construct($label, $button_action);
43 
44  if (is_string($action_on)) {
45  $this->action_on = $action_on;
46  } else {
47  $this->setTriggeredSignal($action_on, "toggle_on");
48  }
49 
50  if (is_string($action_off)) {
51  $this->action_off = $action_off;
52  } else {
53  $this->setTriggeredSignal($action_off, "toggle_off");
54  }
55 
56  $this->is_engageable = true;
57  $this->engaged = $is_on;
58  }
59 
63  public function getActionOff()
64  {
65  if ($this->action_off !== null) {
66  return $this->action_off;
67  }
68 
69  return $this->getTriggeredSignalsFor("toggle_off");
70  }
71 
75  public function getActionOn()
76  {
77  if ($this->action_on !== null) {
78  return $this->action_on;
79  }
80 
81  return $this->getTriggeredSignalsFor("toggle_on");
82  }
83 
88  {
89  return $this->appendTriggeredSignal($signal, "toggle_on");
90  }
91 
96  {
97  return $this->appendTriggeredSignal($signal, "toggle_off");
98  }
99 }
__construct($label, $action_on, $action_off, $is_on, Signal $click=null)
Definition: Toggle.php:33
Class Factory.
engaged()
Definition: engaged.php:2
Class ChatMainBarProvider .
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
trait ComponentHelper
Provides common functionality for component implementations.
getTriggeredSignalsFor($event)
Get signals that are triggered for a certain event.
Definition: Triggerer.php:85
setTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any othe signals registered on the same event.
Definition: Triggerer.php:65
checkBoolArg($which, $value)
Throw an InvalidArgumentException if $value is not a bool.
appendTriggeredSignal(Component\Signal $signal, $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:31
checkStringOrSignalArg($which, $value)
Throw an InvalidArgumentException if $value is no string or Signal.
__construct(Container $dic, ilPlugin $plugin)