ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTRBLBorderWidthInputGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 protected string $rightvalue = "";
29 protected string $leftvalue = "";
30 protected string $bottomvalue = "";
31 protected string $topvalue = "";
35 protected array $dirs = [];
36 protected string $allvalue = "";
37 protected ilObjUser $user;
38 protected string $value = "";
39
40 public function __construct(string $a_title = "", string $a_postvar = "")
41 {
42 global $DIC;
43
44 $this->lng = $DIC->language();
45 $this->user = $DIC->user();
46 parent::__construct($a_title, $a_postvar);
47 $this->setType("border_width");
48 $this->dirs = array("all", "top", "bottom", "left", "right");
49 }
50
51 public function setAllValue(string $a_allvalue): void
52 {
53 $this->allvalue = $a_allvalue;
54 }
55
56 public function getAllValue(): string
57 {
58 return $this->allvalue;
59 }
60
61 public function setTopValue(string $a_topvalue): void
62 {
63 $this->topvalue = $a_topvalue;
64 }
65
66 public function getTopValue(): string
67 {
68 return $this->topvalue;
69 }
70
71 public function setBottomValue(string $a_bottomvalue): void
72 {
73 $this->bottomvalue = $a_bottomvalue;
74 }
75
76 public function getBottomValue(): string
77 {
78 return $this->bottomvalue;
79 }
80
81 public function setLeftValue(string $a_leftvalue): void
82 {
83 $this->leftvalue = $a_leftvalue;
84 }
85
86 public function getLeftValue(): string
87 {
88 return $this->leftvalue;
89 }
90
91 public function setRightValue(string $a_rightvalue): void
92 {
93 $this->rightvalue = $a_rightvalue;
94 }
95
96 public function getRightValue(): string
97 {
98 return $this->rightvalue;
99 }
100
101 public function checkInput(): bool
102 {
104
105 $input = $this->getInput();
106
107 foreach ($this->dirs as $dir) {
108 $type = $input[$dir]["type"];
109 $num_value = $input[$dir]["num_value"];
110 $num_unit = $input[$dir]["num_unit"];
111 $pre_value = $input[$dir]["pre_value"];
112
113 /*
114 if ($this->getRequired() && trim($num_value) == "")
115 {
116 $this->setAlert($lng->txt("msg_input_is_required"));
117
118 return false;
119 }*/
120
121 if (!is_numeric($num_value) && $num_value != "") {
122 $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
123 return false;
124 }
125
126 $value = "";
127 if ($type == "numeric") {
128 if ($num_value != "") {
129 $value = $num_value . $num_unit;
130 }
131 } else {
132 $value = $pre_value;
133 }
134
135 if (trim($value) != "") {
136 switch ($dir) {
137 case "all": $this->setAllValue($value);
138 break;
139 case "top": $this->setTopValue($value);
140 break;
141 case "bottom": $this->setBottomValue($value);
142 break;
143 case "left": $this->setLeftValue($value);
144 break;
145 case "right": $this->setRightValue($value);
146 break;
147 }
148 }
149 }
150
151 return true;
152 }
153
154 public function getInput(): array
155 {
156 return $this->arrayArray($this->getPostVar());
157 }
158
159 public function insert(ilTemplate $a_tpl): void
160 {
162 $value = "";
163 $current_unit = "";
164 $layout_tpl = new ilTemplate("tpl.prop_trbl_layout.html", true, true, "components/ILIAS/Style/Content");
165
166 foreach ($this->dirs as $dir) {
167 $tpl = new ilTemplate("tpl.prop_trbl_border_width.html", true, true, "components/ILIAS/Style/Content");
169 $pre_options = ilObjStyleSheet::_getStyleParameterValues("border-width");
170
171 switch ($dir) {
172 case "all": $value = strtolower(trim($this->getAllValue()));
173 break;
174 case "top": $value = strtolower(trim($this->getTopValue()));
175 break;
176 case "bottom": $value = strtolower(trim($this->getBottomValue()));
177 break;
178 case "left": $value = strtolower(trim($this->getLeftValue()));
179 break;
180 case "right": $value = strtolower(trim($this->getRightValue()));
181 break;
182 }
183
184 if (in_array($value, $pre_options)) {
185 $current_type = "pre";
186 $tpl->setVariable("PREDEFINED_SELECTED", 'checked="checked"');
187 } else {
188 $current_type = "unit";
189 $tpl->setVariable("NUMERIC_SELECTED", 'checked="checked"');
190
191 $current_unit = "";
192 foreach ($unit_options as $u) {
193 if (substr($value, strlen($value) - strlen($u)) == $u) {
194 $current_unit = $u;
195 }
196 }
197 $disp_val = substr($value, 0, strlen($value) - strlen($current_unit));
198 if ($current_unit == "") {
199 $current_unit = "px";
200 }
201 $tpl->setVariable("VAL_NUM", $disp_val);
202 }
203
204 foreach ($unit_options as $option) {
205 $tpl->setCurrentBlock("unit_option");
206 $tpl->setVariable("VAL_UNIT", $option);
207 $tpl->setVariable("TXT_UNIT", $option);
208 if ($current_type == "unit" && $current_unit == $option) {
209 $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
210 }
211 $tpl->parseCurrentBlock();
212 }
213
214 foreach ($pre_options as $option) {
215 $tpl->setCurrentBlock("pre_option");
216 $tpl->setVariable("VAL_PRE", $option);
217 $tpl->setVariable("TXT_PRE", $option);
218 if ($current_type == "pre" && $value == $option) {
219 $tpl->setVariable("PRE_SELECTED", 'selected="selected"');
220 }
221 $tpl->parseCurrentBlock();
222 }
223
224 $tpl->setVariable("POSTVAR", $this->getPostVar());
225 $tpl->setVariable("TXT_DIR", $lng->txt("sty_$dir"));
226 $tpl->setVariable("DIR", $dir);
227
228 $layout_tpl->setVariable(strtoupper($dir), $tpl->get());
229 }
230 $layout_tpl->setVariable("COLSPAN", "2");
231
232 $a_tpl->setCurrentBlock("prop_generic");
233 $a_tpl->setVariable("PROP_GENERIC", $layout_tpl->get());
234 $a_tpl->parseCurrentBlock();
235 }
236
237 public function setValueByArray(array $a_values): void
238 {
239 if ($a_values[$this->getPostVar()]["all"]["type"] == "predefined") {
240 $this->setAllValue($a_values[$this->getPostVar()]["all"]["pre_value"]);
241 } else {
242 $this->setAllValue($a_values[$this->getPostVar()]["all"]["num_value"] .
243 $a_values[$this->getPostVar()]["all"]["num_unit"]);
244 }
245 if ($a_values[$this->getPostVar()]["bottom"]["type"] == "predefined") {
246 $this->setBottomValue($a_values[$this->getPostVar()]["bottom"]["pre_value"]);
247 } else {
248 $this->setBottomValue($a_values[$this->getPostVar()]["bottom"]["num_value"] .
249 $a_values[$this->getPostVar()]["bottom"]["num_unit"]);
250 }
251 if ($a_values[$this->getPostVar()]["top"]["type"] == "predefined") {
252 $this->setTopValue($a_values[$this->getPostVar()]["top"]["pre_value"]);
253 } else {
254 $this->setTopValue($a_values[$this->getPostVar()]["top"]["num_value"] .
255 $a_values[$this->getPostVar()]["top"]["num_unit"]);
256 }
257 if ($a_values[$this->getPostVar()]["left"]["type"] == "predefined") {
258 $this->setLeftValue($a_values[$this->getPostVar()]["left"]["pre_value"]);
259 } else {
260 $this->setLeftValue($a_values[$this->getPostVar()]["left"]["num_value"] .
261 $a_values[$this->getPostVar()]["left"]["num_unit"]);
262 }
263 if ($a_values[$this->getPostVar()]["right"]["type"] == "predefined") {
264 $this->setRightValue($a_values[$this->getPostVar()]["right"]["pre_value"]);
265 } else {
266 $this->setRightValue($a_values[$this->getPostVar()]["right"]["num_value"] .
267 $a_values[$this->getPostVar()]["right"]["num_unit"]);
268 }
269 }
270}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
This class represents a property in a property form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _getStyleParameterNumericUnits(bool $a_no_percentage=false)
static _getStyleParameterValues(string $par)
User class.
This class represents a border width with all/top/right/bottom/left in a property form.
checkInput()
Check input, strip slashes etc.
__construct(string $a_title="", string $a_postvar="")
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26