ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilCheckboxInputGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  protected string $value = "1";
30  protected bool $checked = false;
31  protected string $optiontitle = "";
32  protected string $additional_attributes = '';
33 
34  public function __construct(
35  string $a_title = "",
36  string $a_postvar = ""
37  ) {
38  global $DIC;
39 
40  $this->lng = $DIC->language();
41  parent::__construct($a_title, $a_postvar);
42  $this->setType("checkbox");
43  }
44 
45  public function setValue(string $a_value): void
46  {
47  $this->value = $a_value;
48  }
49 
50  public function getValue(): string
51  {
52  return $this->value;
53  }
54 
55  public function setChecked(bool $a_checked): void
56  {
57  $this->checked = $a_checked;
58  }
59 
60  public function getChecked(): bool
61  {
62  return $this->checked;
63  }
64 
65  public function setOptionTitle(string $a_optiontitle): void
66  {
67  $this->optiontitle = $a_optiontitle;
68  }
69 
70  public function getOptionTitle(): string
71  {
72  return $this->optiontitle;
73  }
74 
75  public function setValueByArray(array $a_values): void
76  {
77  $checked = $a_values[$this->getPostVar()] ?? false;
78  $this->setChecked((bool) $checked);
79  foreach ($this->getSubItems() as $item) {
80  $item->setValueByArray($a_values);
81  }
82  }
83 
84  public function setAdditionalAttributes(string $a_attrs): void
85  {
86  $this->additional_attributes = $a_attrs;
87  }
88 
89  public function getAdditionalAttributes(): string
90  {
92  }
93 
98  public function checkInput(): bool
99  {
100  $ok = $this->checkSubItemsInput();
101 
102  // only not ok, if checkbox not checked
103  if ($this->getInput() == "") {
104  $ok = true;
105  }
106 
107  return $ok;
108  }
109 
110  public function getInput(): string
111  {
112  return $this->str($this->getPostVar());
113  }
114 
115  public function hideSubForm(): bool
116  {
117  return !$this->getChecked();
118  }
119 
120  public function render($a_mode = ''): string
121  {
122  $tpl = new ilTemplate("tpl.prop_checkbox.html", true, true, "components/ILIAS/Form");
123 
124  $tpl->setVariable("POST_VAR", $this->getPostVar());
125  $tpl->setVariable("ID", $this->getFieldId());
126  $tpl->setVariable("PROPERTY_VALUE", $this->getValue());
127  $tpl->setVariable("OPTION_TITLE", $this->getOptionTitle());
128  if (strlen($this->getAdditionalAttributes())) {
129  $tpl->setVariable('PROP_CHECK_ATTRS', $this->getAdditionalAttributes());
130  }
131  if ($this->getChecked()) {
132  $tpl->setVariable(
133  "PROPERTY_CHECKED",
134  'checked="checked"'
135  );
136  }
137  if ($this->getDisabled()) {
138  $tpl->setVariable(
139  "DISABLED",
140  'disabled="disabled"'
141  );
142  }
143 
144  if ($a_mode == "toolbar") {
145  // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
146  // -moz-inline-stack for FF2
147  // zoom 1; *display:inline for IE6 & 7
148  $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline;');
149  }
150 
151  $tpl->setVariable("ARIA_LABEL", ilLegacyFormElementsUtil::prepareFormOutput($this->getTitle()));
152  if ($this->getInfo() !== '') {
153  $tpl->setVariable('DESCRIBED_BY_FIELD_ID', $this->getFieldId());
154  }
155 
156  return $tpl->get();
157  }
158 
159  public function insert(ilTemplate $a_tpl): void
160  {
161  $html = $this->render();
162 
163  $a_tpl->setCurrentBlock("prop_generic");
164  $a_tpl->setVariable("PROP_GENERIC", $html);
165  $a_tpl->parseCurrentBlock();
166  }
167 
168  public function getTableFilterHTML(): string
169  {
170  $html = $this->render();
171  return $html;
172  }
173 
174  public function serializeData(): string
175  {
176  return serialize($this->getChecked());
177  }
178 
179  public function unserializeData(string $a_data): void
180  {
181  $data = unserialize($a_data);
182 
183  if ($data) {
184  $this->setValue((string) $data);
185  $this->setChecked(true);
186  }
187  }
188 
189  public function getToolbarHTML(): string
190  {
191  $html = $this->render('toolbar');
192  return $html;
193  }
194 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setAdditionalAttributes(string $a_attrs)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static prepareFormOutput($a_str, bool $a_strip=false)
checkInput()
Check input, strip slashes etc.
checked()
description: > Example for rendering a Checked Glyph.
Definition: checked.php:25
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
global $DIC
Definition: shib_login.php:26
__construct(string $a_title="", string $a_postvar="")
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
getTableFilterHTML()
Get input item HTML to be inserted into table filters.
__construct(Container $dic, ilPlugin $plugin)
This class represents a property that may include a sub form.
getToolbarHTML()
Get input item HTML to be inserted into ilToolbarGUI.
setValueByArray(array $a_values)
setOptionTitle(string $a_optiontitle)