19declare(strict_types=1);
44 string $a_postvar =
""
48 $this->
lng = $DIC->language();
54 $this->suffix = $a_value;
62 public function setValue(?
string $a_value): void
64 if ($a_value ==
"" || is_null($a_value)) {
68 $this->value = (float) str_replace(
',',
'.', $a_value);
72 $this->value = round($this->value);
77 $this->value = round($this->value, $this->
getDecimals());
80 $this->value = (float) number_format($this->value, $this->
getDecimals(),
".",
"");
91 $data = unserialize($a_data);
103 $this->maxlength = $a_maxlength;
135 $this->size = $a_size;
150 bool $a_display_always =
false
152 $this->minvalue = $a_minvalue;
153 $this->minvalue_visible = $a_display_always;
158 return $this->minvalue;
163 bool $a_display_always =
false
165 $this->maxvalue = $a_maxvalue;
166 $this->maxvalue_visible = $a_display_always;
171 return $this->maxvalue;
176 $this->decimals = $a_decimals;
177 if ($this->decimals) {
178 $this->allowDecimals(
true);
184 return $this->decimals;
189 $this->allow_decimals = $a_value;
194 return $this->allow_decimals;
201 $val = trim($this->
str($this->getPostVar()));
202 if ($this->getRequired() && $val ==
"") {
203 $this->setAlert(
$lng->txt(
"msg_input_is_required"));
206 $val = str_replace(
',',
'.', $val);
208 if ($val !=
"" && !is_numeric($val)) {
209 $this->minvalue_visible =
true;
210 $this->maxvalue_visible =
true;
211 $this->setAlert(
$lng->txt(
"form_msg_numeric_value_required"));
215 if ($this->minvalueShouldBeGreater()) {
216 if ($val !=
"" && $this->getMinValue() !==
null &&
217 $val <= $this->getMinValue()) {
218 $this->minvalue_visible =
true;
219 $this->setAlert(
$lng->txt(
"form_msg_value_too_low"));
224 $this->getMinValue() !==
null &&
225 $val < $this->getMinValue()) {
226 $this->minvalue_visible =
true;
227 $this->setAlert(
$lng->txt(
"form_msg_value_too_low"));
232 if ($this->maxvalueShouldBeLess()) {
234 $this->getMaxValue() !==
null &&
235 $val >= $this->getMaxValue()) {
236 $this->maxvalue_visible =
true;
237 $this->setAlert(
$lng->txt(
"form_msg_value_too_high"));
242 $this->getMaxValue() !==
null &&
243 $val > $this->getMaxValue()) {
244 $this->maxvalue_visible =
true;
245 $this->setAlert(
$lng->txt(
"form_msg_value_too_high"));
250 return $this->checkSubItemsInput();
255 $value = $this->
str($this->getPostVar());
256 if (trim($value) ==
"") {
259 return (
float) str_replace(
',',
'.', $value);
264 $html = $this->render();
275 $tpl =
new ilTemplate(
"tpl.prop_number.html",
true,
true,
"Services/Form");
277 if (strlen((
string) $this->
getValue())) {
278 $tpl->setCurrentBlock(
"prop_number_propval");
280 $tpl->parseCurrentBlock();
283 if ($this->getInfo() !==
'') {
284 $tpl->setCurrentBlock(
'described_by_description');
285 $tpl->setVariable(
'DESCRIBED_BY_DESCRIPTION_FIELD_ID', $this->getFieldId());
286 $tpl->parseCurrentBlock();
292 if ($this->areDecimalsAllowed() && $this->getDecimals() > 0) {
293 $constraints =
$lng->txt(
"form_format") .
": ###." . str_repeat(
"#", $this->getDecimals());
296 if ($this->getMinValue() !==
null && $this->minvalue_visible) {
297 $constraints .= $delim .
$lng->txt(
"form_min_value") .
": " . (($this->minvalueShouldBeGreater()) ?
"> " :
"") . $this->getMinValue();
300 if ($this->getMaxValue() !==
null && $this->maxvalue_visible) {
301 $constraints .= $delim .
$lng->txt(
"form_max_value") .
": " . (($this->maxvalueShouldBeLess()) ?
"< " :
"") . $this->getMaxValue();
305 if ($constraints !==
"") {
306 $tpl->setCurrentBlock(
'described_by_constraint');
307 $tpl->setVariable(
'DESCRIBED_BY_CONSTRAINT_FIELD_ID', $this->getFieldId());
308 $tpl->parseCurrentBlock();
311 $tpl->setCurrentBlock(
"prop_number");
313 $tpl->setVariable(
"POST_VAR", $this->getPostVar());
314 $tpl->setVariable(
"ID", $this->getFieldId());
315 $tpl->setVariable(
"SIZE", $this->getSize());
316 $tpl->setVariable(
"MAXLENGTH", $this->getMaxLength());
317 if (strlen($this->getSuffix())) {
318 $tpl->setVariable(
"INPUT_SUFFIX", $this->getSuffix());
320 if ($this->getDisabled()) {
323 " disabled=\"disabled\""
327 if ($this->client_side_validation) {
328 $tpl->setVariable(
"JS_DECIMALS_ALLOWED", (
int) $this->areDecimalsAllowed());
329 $tpl->setVariable(
"JS_ID", $this->getFieldId());
332 if ($constraints !==
'') {
333 $tpl->setVariable(
"TXT_NUMBER_CONSTRAINTS", $constraints);
340 if ($this->getRequired()) {
341 $tpl->setVariable(
"REQUIRED",
"required=\"required\"");
344 $tpl->parseCurrentBlock();
351 return $this->getInput();
356 $this->client_side_validation = $validate;
setVariable($variable, $value='')
Sets a variable value.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc