ILIAS  release_8 Revision v8.24
class.ilTRBLBorderWidthInputGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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); break;
138 case "top": $this->setTopValue($value); break;
139 case "bottom": $this->setBottomValue($value); break;
140 case "left": $this->setLeftValue($value); break;
141 case "right": $this->setRightValue($value); break;
142 }
143 }
144 }
145
146 return true;
147 }
148
149 public function getInput(): array
150 {
151 return $this->arrayArray($this->getPostVar());
152 }
153
154 public function insert(ilTemplate $a_tpl): void
155 {
157 $value = "";
158 $current_unit = "";
159 $layout_tpl = new ilTemplate("tpl.prop_trbl_layout.html", true, true, "Services/Style/Content");
160
161 foreach ($this->dirs as $dir) {
162 $tpl = new ilTemplate("tpl.prop_trbl_border_width.html", true, true, "Services/Style/Content");
164 $pre_options = ilObjStyleSheet::_getStyleParameterValues("border-width");
165
166 switch ($dir) {
167 case "all": $value = strtolower(trim($this->getAllValue())); break;
168 case "top": $value = strtolower(trim($this->getTopValue())); break;
169 case "bottom": $value = strtolower(trim($this->getBottomValue())); break;
170 case "left": $value = strtolower(trim($this->getLeftValue())); break;
171 case "right": $value = strtolower(trim($this->getRightValue())); break;
172 }
173
174 if (in_array($value, $pre_options)) {
175 $current_type = "pre";
176 $tpl->setVariable("PREDEFINED_SELECTED", 'checked="checked"');
177 } else {
178 $current_type = "unit";
179 $tpl->setVariable("NUMERIC_SELECTED", 'checked="checked"');
180
181 $current_unit = "";
182 foreach ($unit_options as $u) {
183 if (substr($value, strlen($value) - strlen($u)) == $u) {
184 $current_unit = $u;
185 }
186 }
187 $disp_val = substr($value, 0, strlen($value) - strlen($current_unit));
188 if ($current_unit == "") {
189 $current_unit = "px";
190 }
191 $tpl->setVariable("VAL_NUM", $disp_val);
192 }
193
194 foreach ($unit_options as $option) {
195 $tpl->setCurrentBlock("unit_option");
196 $tpl->setVariable("VAL_UNIT", $option);
197 $tpl->setVariable("TXT_UNIT", $option);
198 if ($current_type == "unit" && $current_unit == $option) {
199 $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
200 }
201 $tpl->parseCurrentBlock();
202 }
203
204 foreach ($pre_options as $option) {
205 $tpl->setCurrentBlock("pre_option");
206 $tpl->setVariable("VAL_PRE", $option);
207 $tpl->setVariable("TXT_PRE", $option);
208 if ($current_type == "pre" && $value == $option) {
209 $tpl->setVariable("PRE_SELECTED", 'selected="selected"');
210 }
211 $tpl->parseCurrentBlock();
212 }
213
214 $tpl->setVariable("POSTVAR", $this->getPostVar());
215 $tpl->setVariable("TXT_DIR", $lng->txt("sty_$dir"));
216 $tpl->setVariable("DIR", $dir);
217
218 $layout_tpl->setVariable(strtoupper($dir), $tpl->get());
219 }
220 $layout_tpl->setVariable("COLSPAN", "2");
221
222 $a_tpl->setCurrentBlock("prop_generic");
223 $a_tpl->setVariable("PROP_GENERIC", $layout_tpl->get());
224 $a_tpl->parseCurrentBlock();
225 }
226
227 public function setValueByArray(array $a_values): void
228 {
229 if ($a_values[$this->getPostVar()]["all"]["type"] == "predefined") {
230 $this->setAllValue($a_values[$this->getPostVar()]["all"]["pre_value"]);
231 } else {
232 $this->setAllValue($a_values[$this->getPostVar()]["all"]["num_value"] .
233 $a_values[$this->getPostVar()]["all"]["num_unit"]);
234 }
235 if ($a_values[$this->getPostVar()]["bottom"]["type"] == "predefined") {
236 $this->setBottomValue($a_values[$this->getPostVar()]["bottom"]["pre_value"]);
237 } else {
238 $this->setBottomValue($a_values[$this->getPostVar()]["bottom"]["num_value"] .
239 $a_values[$this->getPostVar()]["bottom"]["num_unit"]);
240 }
241 if ($a_values[$this->getPostVar()]["top"]["type"] == "predefined") {
242 $this->setTopValue($a_values[$this->getPostVar()]["top"]["pre_value"]);
243 } else {
244 $this->setTopValue($a_values[$this->getPostVar()]["top"]["num_value"] .
245 $a_values[$this->getPostVar()]["top"]["num_unit"]);
246 }
247 if ($a_values[$this->getPostVar()]["left"]["type"] == "predefined") {
248 $this->setLeftValue($a_values[$this->getPostVar()]["left"]["pre_value"]);
249 } else {
250 $this->setLeftValue($a_values[$this->getPostVar()]["left"]["num_value"] .
251 $a_values[$this->getPostVar()]["left"]["num_unit"]);
252 }
253 if ($a_values[$this->getPostVar()]["right"]["type"] == "predefined") {
254 $this->setRightValue($a_values[$this->getPostVar()]["right"]["pre_value"]);
255 } else {
256 $this->setRightValue($a_values[$this->getPostVar()]["right"]["num_value"] .
257 $a_values[$this->getPostVar()]["right"]["num_unit"]);
258 }
259 }
260}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc