ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilNumericStyleValueInputGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 protected ilObjUser $user;
29 protected string $value = "";
30 protected bool $allowpercentage = true;
31
32 public function __construct(string $a_title = "", string $a_postvar = "")
33 {
34 global $DIC;
35
36 $this->lng = $DIC->language();
37 $this->user = $DIC->user();
38 parent::__construct($a_title, $a_postvar);
39 $this->setType("style_numeric");
40 }
41
42 public function setValue(string $a_value): void
43 {
44 $this->value = $a_value;
45 }
46
47 public function getValue(): string
48 {
49 return $this->value;
50 }
51
52 public function setAllowPercentage(bool $a_allowpercentage): void
53 {
54 $this->allowpercentage = $a_allowpercentage;
55 }
56
57 public function getAllowPercentage(): bool
58 {
60 }
61
62 public function checkInput(): bool
63 {
65
66 $input = $this->getInput();
67 $num_value = $input["num_value"];
68 $num_unit = $input["num_unit"];
69
70 if ($this->getRequired() && trim($num_value) == "") {
71 $this->setAlert($lng->txt("msg_input_is_required"));
72
73 return false;
74 }
75
76 if (!is_numeric($num_value) && $num_value != "") {
77 $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
78
79 return false;
80 }
81
82 if (trim($num_value) != "") {
83 $this->setValue($num_value . $num_unit);
84 }
85
86 return true;
87 }
88
89 public function getInput(): array
90 {
91 return $this->strArray($this->getPostVar());
92 }
93
94 public function insert(ilTemplate $a_tpl): void
95 {
96 $tpl = new ilTemplate("tpl.prop_style_numeric.html", true, true, "components/ILIAS/Style/Content");
97
98 $tpl->setVariable("POSTVAR", $this->getPostVar());
99
101
102 $value = strtolower(trim($this->getValue()));
103
104 $current_unit = "";
105 foreach ($unit_options as $u) {
106 if (substr($value, strlen($value) - strlen($u)) == $u) {
107 $current_unit = $u;
108 }
109 }
110 $tpl->setVariable(
111 "VAL_NUM",
112 substr($value, 0, strlen($value) - strlen($current_unit))
113 );
114 if ($current_unit == "") {
115 $current_unit = "px";
116 }
117
118 foreach ($unit_options as $option) {
119 $tpl->setCurrentBlock("unit_option");
120 $tpl->setVariable("VAL_UNIT", $option);
121 $tpl->setVariable("TXT_UNIT", $option);
122 if ($current_unit == $option) {
123 $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
124 }
125 $tpl->parseCurrentBlock();
126 }
127
128 $a_tpl->setCurrentBlock("prop_generic");
129 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
130 $a_tpl->parseCurrentBlock();
131 }
132
133 public function setValueByArray(array $a_values): void
134 {
135 $this->setValue($a_values[$this->getPostVar()]["num_value"] .
136 $a_values[$this->getPostVar()]["num_unit"]);
137 }
138}
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...
This class represents a numeric style property in a property form.
__construct(string $a_title="", string $a_postvar="")
checkInput()
Check input, strip slashes etc.
static _getStyleParameterNumericUnits(bool $a_no_percentage=false)
User class.
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