ILIAS  release_8 Revision v8.24
class.ilCSSRectInputGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
28 protected string $top = "";
29 protected string $left = "";
30 protected string $right = "";
31 protected string $bottom = "";
32 protected int $size = 0;
33 protected bool $useUnits = false;
34
41 public function __construct($a_title = "", $a_postvar = "")
42 {
43 global $DIC;
44
45 $this->lng = $DIC->language();
46 parent::__construct($a_title, $a_postvar);
47 $this->size = 6;
48 $this->useUnits = true;
49 }
50
51 public function setValue(array $valueArray): void
52 {
53 $this->top = $valueArray['top'];
54 $this->left = $valueArray['left'];
55 $this->right = $valueArray['right'];
56 $this->bottom = $valueArray['bottom'];
57 }
58
59 public function setUseUnits(bool $a_value): void
60 {
61 $this->useUnits = $a_value;
62 }
63
64 public function useUnits(): bool
65 {
66 return $this->useUnits;
67 }
68
69 public function setTop(string $a_value): void
70 {
71 $this->top = $a_value;
72 }
73
74 public function getTop(): string
75 {
76 return $this->top;
77 }
78
79 public function setBottom(string $a_value): void
80 {
81 $this->bottom = $a_value;
82 }
83
84 public function getBottom(): string
85 {
86 return $this->bottom;
87 }
88
89 public function setLeft(string $a_value): void
90 {
91 $this->left = $a_value;
92 }
93
94 public function getLeft(): string
95 {
96 return $this->left;
97 }
98
99 public function setRight(string $a_value): void
100 {
101 $this->right = $a_value;
102 }
103
104 public function getRight(): string
105 {
106 return $this->right;
107 }
108
109 public function setSize(int $a_size): void
110 {
111 $this->size = $a_size;
112 }
113
114 public function setValueByArray(array $a_values): void
115 {
116 $postVar = $this->getPostVar();
117
118 $positions = ['top', 'left', 'right', 'bottom'];
119 $values = [
120 'top' => '',
121 'bottom' => '',
122 'right' => '',
123 'left' => '',
124 ];
125
126 foreach ($positions as $position) {
127 if (isset($a_values[$postVar . '_' . $position])) {
128 $values[$position] = $a_values[$postVar . '_' . $position];
129 } elseif (isset($a_values[$postVar][$position])) {
130 $values[$position] = $a_values[$postVar][$position];
131 }
132 }
133
134 $this->setValue($values);
135 }
136
137 public function getSize(): int
138 {
139 return $this->size;
140 }
141
142 public function checkInput(): bool
143 {
145
146 $val = $this->getInput();
147 if (
148 $this->getRequired() &&
149 (
150 ($val[$this->getPostVar() . '_top'] == "")
151 || ($val[$this->getPostVar() . '_bottom'] == "")
152 || ($val[$this->getPostVar() . '_left'] == "")
153 || ($val[$this->getPostVar() . '_right'] == "")
154 )
155 ) {
156 $this->setAlert($lng->txt("msg_input_is_required"));
157 return false;
158 }
159
160 if ($this->useUnits()) {
161 if ((!preg_match('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*))|0)(cm|mm|in|pt|pc|px|em)$/is', $val[$this->getPostVar() . '_top'])) ||
162 (!preg_match('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*))|0)(cm|mm|in|pt|pc|px|em)$/is', $val[$this->getPostVar() . '_right'])) ||
163 (!preg_match('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*))|0)(cm|mm|in|pt|pc|px|em)$/is', $val[$this->getPostVar() . '_bottom'])) ||
164 (!preg_match('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*))|0)(cm|mm|in|pt|pc|px|em)$/is', $val[$this->getPostVar() . '_left']))) {
165 $this->setAlert($lng->txt("msg_unit_is_required"));
166 return false;
167 }
168 }
169 return $this->checkSubItemsInput();
170 }
171
172 public function getInput(): array
173 {
174 $val = $this->strArray($this->getPostVar());
175 $ret[$this->getPostVar() . '_top'] = trim($val['top']);
176 $ret[$this->getPostVar() . '_right'] = trim($val['right']);
177 $ret[$this->getPostVar() . '_bottom'] = trim($val['bottom']);
178 $ret[$this->getPostVar() . '_left'] = trim($val['left']);
179 return $ret;
180 }
181
182 public function insert(ilTemplate $a_tpl): void
183 {
185
186 if (strlen($this->getTop())) {
187 $a_tpl->setCurrentBlock("cssrect_value_top");
188 $a_tpl->setVariable("CSSRECT_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($this->getTop()));
189 $a_tpl->parseCurrentBlock();
190 }
191 if (strlen($this->getBottom())) {
192 $a_tpl->setCurrentBlock("cssrect_value_bottom");
193 $a_tpl->setVariable("CSSRECT_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($this->getBottom()));
194 $a_tpl->parseCurrentBlock();
195 }
196 if (strlen($this->getLeft())) {
197 $a_tpl->setCurrentBlock("cssrect_value_left");
198 $a_tpl->setVariable("CSSRECT_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($this->getLeft()));
199 $a_tpl->parseCurrentBlock();
200 }
201 if (strlen($this->getRight())) {
202 $a_tpl->setCurrentBlock("cssrect_value_right");
203 $a_tpl->setVariable("CSSRECT_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($this->getRight()));
204 $a_tpl->parseCurrentBlock();
205 }
206 $a_tpl->setCurrentBlock("cssrect");
207 $a_tpl->setVariable("ID", $this->getFieldId());
208 $a_tpl->setVariable("SIZE", $this->getSize());
209 $a_tpl->setVariable("POST_VAR", $this->getPostVar());
210 $a_tpl->setVariable("TEXT_TOP", $lng->txt("pos_top"));
211 $a_tpl->setVariable("TEXT_RIGHT", $lng->txt("pos_right"));
212 $a_tpl->setVariable("TEXT_BOTTOM", $lng->txt("pos_bottom"));
213 $a_tpl->setVariable("TEXT_LEFT", $lng->txt("pos_left"));
214 if ($this->getDisabled()) {
215 $a_tpl->setVariable(
216 "DISABLED",
217 " disabled=\"disabled\""
218 );
219 }
220 $a_tpl->parseCurrentBlock();
221 }
222}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setValueByArray(array $a_values)
__construct($a_title="", $a_postvar="")
Constructor.
insert(ilTemplate $a_tpl)
setValue(array $valueArray)
setBottom(string $a_value)
checkInput()
Check input, strip slashes etc.
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 prepareFormOutput($a_str, bool $a_strip=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc