ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTRBLNumericStyleValueInputGUI.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 = "";
32 protected string $allvalue = "";
33
37 protected array $dirs;
38 protected ilObjUser $user;
39 protected string $value;
40 protected bool $allowpercentage = true;
41
42 public function __construct(string $a_title = "", string $a_postvar = "")
43 {
44 global $DIC;
45
46 $this->lng = $DIC->language();
47 $this->user = $DIC->user();
48 parent::__construct($a_title, $a_postvar);
49 $this->setType("style_numeric");
50 $this->dirs = array("all", "top", "bottom", "left", "right");
51 }
52
53 public function setAllValue(string $a_allvalue): void
54 {
55 $this->allvalue = $a_allvalue;
56 }
57
58 public function getAllValue(): string
59 {
60 return $this->allvalue;
61 }
62
63 public function setTopValue(string $a_topvalue): void
64 {
65 $this->topvalue = $a_topvalue;
66 }
67
68 public function getTopValue(): string
69 {
70 return $this->topvalue;
71 }
72
73 public function setBottomValue(string $a_bottomvalue): void
74 {
75 $this->bottomvalue = $a_bottomvalue;
76 }
77
78 public function getBottomValue(): string
79 {
80 return $this->bottomvalue;
81 }
82
83 public function setLeftValue(string $a_leftvalue): void
84 {
85 $this->leftvalue = $a_leftvalue;
86 }
87
88 public function getLeftValue(): string
89 {
90 return $this->leftvalue;
91 }
92
93 public function setRightValue(string $a_rightvalue): void
94 {
95 $this->rightvalue = $a_rightvalue;
96 }
97
98 public function getRightValue(): string
99 {
100 return $this->rightvalue;
101 }
102
103 public function setAllowPercentage(bool $a_allowpercentage): void
104 {
105 $this->allowpercentage = $a_allowpercentage;
106 }
107
108 public function getAllowPercentage(): bool
109 {
111 }
112
113 public function checkInput(): bool
114 {
116
117 $input = $this->getInput();
118
119 foreach ($this->dirs as $dir) {
120 $num_value = $input[$dir]["num_value"];
121 $num_unit = $input[$dir]["num_unit"];
122
123 /*
124 if ($this->getRequired() && trim($num_value) == "")
125 {
126 $this->setAlert($lng->txt("msg_input_is_required"));
127
128 return false;
129 }*/
130
131 if (!is_numeric($num_value) && $num_value != "") {
132 $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
133 return false;
134 }
135
136 if (trim($num_value) != "") {
137 switch ($dir) {
138 case "all": $this->setAllValue($num_value . $num_unit);
139 break;
140 case "top": $this->setTopValue($num_value . $num_unit);
141 break;
142 case "bottom": $this->setBottomValue($num_value . $num_unit);
143 break;
144 case "left": $this->setLeftValue($num_value . $num_unit);
145 break;
146 case "right": $this->setRightValue($num_value . $num_unit);
147 break;
148 }
149 }
150 }
151
152 return true;
153 }
154
155 public function getInput(): array
156 {
157 return $this->arrayArray($this->getPostVar());
158 }
159
160 public function insert(ilTemplate $a_tpl): void
161 {
163
164 $value = "";
165 $layout_tpl = new ilTemplate("tpl.prop_trbl_layout.html", true, true, "components/ILIAS/Style/Content");
166
167 foreach ($this->dirs as $dir) {
168 $tpl = new ilTemplate("tpl.prop_trbl_style_numeric.html", true, true, "components/ILIAS/Style/Content");
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 $current_unit = "";
185 foreach ($unit_options as $u) {
186 if (substr($value, strlen($value) - strlen($u)) == $u) {
187 $current_unit = $u;
188 }
189 }
190 $disp_val = substr($value, 0, strlen($value) - strlen($current_unit));
191 if ($current_unit == "") {
192 $current_unit = "px";
193 }
194
195 foreach ($unit_options as $option) {
196 $tpl->setCurrentBlock("unit_option");
197 $tpl->setVariable("VAL_UNIT", $option);
198 $tpl->setVariable("TXT_UNIT", $option);
199 if ($current_unit == $option) {
200 $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
201 }
202 $tpl->parseCurrentBlock();
203 }
204
205 $tpl->setVariable("POSTVAR", $this->getPostVar());
206 $tpl->setVariable("VAL_NUM", $disp_val);
207 $tpl->setVariable("TXT_DIR", $lng->txt("sty_$dir"));
208 $tpl->setVariable("DIR", $dir);
209
210 $layout_tpl->setVariable(strtoupper($dir), $tpl->get());
211 }
212
213 $a_tpl->setCurrentBlock("prop_generic");
214 $a_tpl->setVariable("PROP_GENERIC", $layout_tpl->get());
215 $a_tpl->parseCurrentBlock();
216 }
217
218 public function setValueByArray(array $a_values): void
219 {
220 $this->setAllValue($a_values[$this->getPostVar()]["all"]["num_value"] .
221 $a_values[$this->getPostVar()]["all"]["num_unit"]);
222 $this->setBottomValue($a_values[$this->getPostVar()]["bottom"]["num_value"] .
223 $a_values[$this->getPostVar()]["bottom"]["num_unit"]);
224 $this->setTopValue($a_values[$this->getPostVar()]["top"]["num_value"] .
225 $a_values[$this->getPostVar()]["top"]["num_unit"]);
226 $this->setLeftValue($a_values[$this->getPostVar()]["left"]["num_value"] .
227 $a_values[$this->getPostVar()]["left"]["num_unit"]);
228 $this->setRightValue($a_values[$this->getPostVar()]["right"]["num_value"] .
229 $a_values[$this->getPostVar()]["right"]["num_unit"]);
230 }
231}
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)
User class.
This class represents a numeric style property with all/top/right/bottom/left in a property form.
__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