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