ILIAS  release_8 Revision v8.24
ilNumberInputGUI Class Reference

This class represents a number property in a property form. More...

+ Inheritance diagram for ilNumberInputGUI:
+ Collaboration diagram for ilNumberInputGUI:

Public Member Functions

 __construct (string $a_title="", string $a_postvar="")
 
 setSuffix (string $a_value)
 
 getSuffix ()
 
 setValue (?string $a_value)
 
 getValue ()
 
 unserializeData (string $a_data)
 
 setMaxLength (int $a_maxlength)
 
 getMaxLength ()
 
 setMinvalueShouldBeGreater (bool $a_bool)
 
 minvalueShouldBeGreater ()
 
 setMaxvalueShouldBeLess (bool $a_bool)
 
 maxvalueShouldBeLess ()
 
 setSize (int $a_size)
 
 setValueByArray (array $a_values)
 
 getSize ()
 
 setMinValue (float $a_minvalue, bool $a_display_always=false)
 
 getMinValue ()
 
 setMaxValue (float $a_maxvalue, bool $a_display_always=false)
 
 getMaxValue ()
 
 setDecimals (int $a_decimals)
 
 getDecimals ()
 
 allowDecimals (bool $a_value)
 
 areDecimalsAllowed ()
 
 checkInput ()
 Check input, strip slashes etc. More...
 
 getInput ()
 
 insert (ilTemplate $a_tpl)
 
 render ()
 
 getPostValueForComparison ()
 
 setClientSideValidation (bool $validate)
 
- Public Member Functions inherited from ilSubEnabledFormPropertyGUI
 addSubItem (ilFormPropertyGUI $a_item)
 
 getSubItems ()
 
 getSubInputItemsRecursive ()
 returns a flat array of possibly existing subitems recursively More...
 
 checkSubItemsInput ()
 Check SubItems. More...
 
 getSubForm ()
 
 getItemByPostVar (string $a_post_var)
 Get item by post var. More...
 
- Public Member Functions inherited from ilFormPropertyGUI
 __construct (string $a_title="", string $a_postvar="")
 
 executeCommand ()
 
 getType ()
 
 setTitle (string $a_title)
 
 getTitle ()
 
 setPostVar (string $a_postvar)
 
 getPostVar ()
 
 getFieldId ()
 
 setInfo (string $a_info)
 
 getInfo ()
 
 setAlert (string $a_alert)
 
 getAlert ()
 
 setRequired (bool $a_required)
 
 getRequired ()
 
 setDisabled (bool $a_disabled)
 
 getDisabled ()
 
 checkInput ()
 Check input, strip slashes etc. More...
 
 setParentForm (ilPropertyFormGUI $a_parentform)
 
 getParentForm ()
 
 setParent (ilFormPropertyGUI $a_val)
 
 getParent ()
 
 getSubForm ()
 
 hideSubForm ()
 
 setHiddenTitle (string $a_val)
 
 getHiddenTitle ()
 
 getItemByPostVar (string $a_post_var)
 Get item by post var. More...
 
 serializeData ()
 
 unserializeData (string $a_data)
 
 setParentTable ($a_val)
 Set parent table. More...
 
 getParentTable ()
 Get parent table. More...
 
 writeToSession ()
 
 clearFromSession ()
 
 readFromSession ()
 
 getHiddenTag (string $a_post_var, string $a_value)
 
 setMulti (bool $a_multi, bool $a_sortable=false, bool $a_addremove=true)
 
 getMulti ()
 
 setMultiValues (array $a_values)
 
 getMultiValues ()
 
 getContentOutsideFormTag ()
 Get content that has to reside outside of the parent form tag, e.g. More...
 
 stripSlashesAddSpaceFallback (string $a_str)
 Strip slashes with add space fallback, see https://www.ilias.de/mantis/view.php?id=19727. More...
 
 getTableFilterLabelFor ()
 Get label "for" attribute value for filter. More...
 
 getFormLabelFor ()
 Get label "for" attribute value for form. More...
 
 setRequestParam (string $key, $val)
 This writes the request (aka post) values. More...
 

Protected Attributes

float $value = null
 
int $maxlength = 200
 
int $size = 40
 
string $suffix = ""
 
float $minvalue = null
 
bool $minvalueShouldBeGreater = false
 
bool $minvalue_visible = false
 
float $maxvalue = null
 
bool $maxvalueShouldBeLess = false
 
bool $maxvalue_visible = false
 
int $decimals = 0
 
bool $allow_decimals = false
 
bool $client_side_validation = false
 
- Protected Attributes inherited from ilSubEnabledFormPropertyGUI
array $sub_items = array()
 
- Protected Attributes inherited from ilFormPropertyGUI
array $set_params = []
 
ilTable2GUI $parent_table = null
 
ilFormPropertyGUI $parent_gui = null
 
ilCtrl $ctrl
 
ilLanguage $lng
 
string $type = ""
 
string $title = ""
 
string $postvar = ""
 
string $info = ""
 
string $alert = ""
 
bool $required = false
 
ilPropertyFormGUI $parentform = null
 
string $hidden_title = ""
 
bool $multi = false
 
bool $multi_sortable = false
 
bool $multi_addremove = true
 
array $multi_values = []
 
RequestInterface $request
 
HTTP Services $http
 
Refinery Factory $refinery = null
 
bool $disabled = false
 
ilGlobalTemplateInterface $global_tpl = null
 

Additional Inherited Members

- Static Public Member Functions inherited from ilFormPropertyGUI
static removeProhibitedCharacters (string $a_text)
 Remove prohibited characters see #19159. More...
 
- Protected Member Functions inherited from ilFormPropertyGUI
 setType (string $a_type)
 
 checkParentFormTable ()
 
 getSessionKey ()
 
 getMultiIconsHTML ()
 
 int ($key)
 
 intArray ($key)
 
 str ($key)
 
 raw ($key)
 
 strArray ($key)
 
 arrayArray ($key)
 
 isRequestParamArray (string $key)
 
 getRequestParam (string $key, Refinery\Transformation $t)
 

Detailed Description

This class represents a number property in a property form.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 26 of file class.ilNumberInputGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilNumberInputGUI::__construct ( string  $a_title = "",
string  $a_postvar = "" 
)

Reimplemented from ilFormPropertyGUI.

Definition at line 42 of file class.ilNumberInputGUI.php.

45 {
46 global $DIC;
47
48 $this->lng = $DIC->language();
49 parent::__construct($a_title, $a_postvar);
50 }
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ allowDecimals()

ilNumberInputGUI::allowDecimals ( bool  $a_value)

Definition at line 187 of file class.ilNumberInputGUI.php.

187 : void
188 {
189 $this->allow_decimals = $a_value;
190 }

◆ areDecimalsAllowed()

ilNumberInputGUI::areDecimalsAllowed ( )

Definition at line 192 of file class.ilNumberInputGUI.php.

192 : bool
193 {
195 }

Referenced by setValue().

+ Here is the caller graph for this function:

◆ checkInput()

ilNumberInputGUI::checkInput ( )

Check input, strip slashes etc.

set alert, if input is not ok.

Reimplemented from ilFormPropertyGUI.

Definition at line 197 of file class.ilNumberInputGUI.php.

197 : bool
198 {
200
201 $val = trim($this->str($this->getPostVar()));
202 if ($this->getRequired() && $val == "") {
203 $this->setAlert($lng->txt("msg_input_is_required"));
204 return false;
205 }
206 $val = str_replace(',', '.', $val);
207
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"));
212 return false;
213 }
214
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"));
220 return false;
221 }
222 } else {
223 if ($val != "" &&
224 $this->getMinValue() !== null &&
225 $val < $this->getMinValue()) {
226 $this->minvalue_visible = true;
227 $this->setAlert($lng->txt("form_msg_value_too_low"));
228 return false;
229 }
230 }
231
232 if ($this->maxvalueShouldBeLess()) {
233 if ($val != "" &&
234 $this->getMaxValue() !== null &&
235 $val >= $this->getMaxValue()) {
236 $this->maxvalue_visible = true;
237 $this->setAlert($lng->txt("form_msg_value_too_high"));
238 return false;
239 }
240 } else {
241 if ($val != "" &&
242 $this->getMaxValue() !== null &&
243 $val > $this->getMaxValue()) {
244 $this->maxvalue_visible = true;
245 $this->setAlert($lng->txt("form_msg_value_too_high"));
246 return false;
247 }
248 }
249
250 return $this->checkSubItemsInput();
251 }
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...

References $lng, and ILIAS\Repository\str().

+ Here is the call graph for this function:

◆ getDecimals()

ilNumberInputGUI::getDecimals ( )

Definition at line 182 of file class.ilNumberInputGUI.php.

182 : int
183 {
184 return $this->decimals;
185 }

Referenced by setValue().

+ Here is the caller graph for this function:

◆ getInput()

ilNumberInputGUI::getInput ( )

Definition at line 253 of file class.ilNumberInputGUI.php.

253 : ?float
254 {
255 $value = $this->str($this->getPostVar());
256 if (trim($value) == "") {
257 return null;
258 }
259 return (float) str_replace(',', '.', $value);
260 }

References ILIAS\Repository\str().

+ Here is the call graph for this function:

◆ getMaxLength()

ilNumberInputGUI::getMaxLength ( )

Definition at line 106 of file class.ilNumberInputGUI.php.

106 : int
107 {
108 return $this->maxlength;
109 }

References $maxlength.

◆ getMaxValue()

ilNumberInputGUI::getMaxValue ( )

Definition at line 169 of file class.ilNumberInputGUI.php.

169 : ?float
170 {
171 return $this->maxvalue;
172 }

◆ getMinValue()

ilNumberInputGUI::getMinValue ( )

Definition at line 156 of file class.ilNumberInputGUI.php.

156 : ?float
157 {
158 return $this->minvalue;
159 }

◆ getPostValueForComparison()

ilNumberInputGUI::getPostValueForComparison ( )

Definition at line 349 of file class.ilNumberInputGUI.php.

349 : ?float
350 {
351 return $this->getInput();
352 }

◆ getSize()

ilNumberInputGUI::getSize ( )

Definition at line 143 of file class.ilNumberInputGUI.php.

143 : int
144 {
145 return $this->size;
146 }

References $size.

◆ getSuffix()

ilNumberInputGUI::getSuffix ( )

Definition at line 57 of file class.ilNumberInputGUI.php.

57 : string
58 {
59 return $this->suffix;
60 }

References $suffix.

◆ getValue()

ilNumberInputGUI::getValue ( )

Definition at line 84 of file class.ilNumberInputGUI.php.

84 : ?float
85 {
86 return $this->value;
87 }

References $value.

◆ insert()

ilNumberInputGUI::insert ( ilTemplate  $a_tpl)

Definition at line 262 of file class.ilNumberInputGUI.php.

262 : void
263 {
264 $html = $this->render();
265
266 $a_tpl->setCurrentBlock("prop_generic");
267 $a_tpl->setVariable("PROP_GENERIC", $html);
268 $a_tpl->parseCurrentBlock();
269 }
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)

References ilTemplate\parseCurrentBlock(), ilTemplate\setCurrentBlock(), and HTML_Template_IT\setVariable().

+ Here is the call graph for this function:

◆ maxvalueShouldBeLess()

ilNumberInputGUI::maxvalueShouldBeLess ( )

Definition at line 128 of file class.ilNumberInputGUI.php.

128 : bool
129 {
131 }

References $maxvalueShouldBeLess.

Referenced by setMaxvalueShouldBeLess().

+ Here is the caller graph for this function:

◆ minvalueShouldBeGreater()

ilNumberInputGUI::minvalueShouldBeGreater ( )

Definition at line 117 of file class.ilNumberInputGUI.php.

117 : bool
118 {
120 }

References $minvalueShouldBeGreater.

Referenced by setMinvalueShouldBeGreater().

+ Here is the caller graph for this function:

◆ render()

ilNumberInputGUI::render ( )

Definition at line 271 of file class.ilNumberInputGUI.php.

271 : string
272 {
274
275 $tpl = new ilTemplate("tpl.prop_number.html", true, true, "Services/Form");
276
277 if (strlen((string) $this->getValue())) {
278 $tpl->setCurrentBlock("prop_number_propval");
279 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput((string) $this->getValue()));
280 $tpl->parseCurrentBlock();
281 }
282
283 if ($this->getInfo() !== '') {
284 $tpl->setCurrentBlock('described_by_description');
285 $tpl->setVariable('DESCRIBED_BY_DESCRIPTION_FIELD_ID', $this->getFieldId());
286 $tpl->parseCurrentBlock();
287 }
288
289 // constraints
290 $constraints = "";
291 $delim = "";
292 if ($this->areDecimalsAllowed() && $this->getDecimals() > 0) {
293 $constraints = $lng->txt("form_format") . ": ###." . str_repeat("#", $this->getDecimals());
294 $delim = ", ";
295 }
296 if ($this->getMinValue() !== null && $this->minvalue_visible) {
297 $constraints .= $delim . $lng->txt("form_min_value") . ": " . (($this->minvalueShouldBeGreater()) ? "&gt; " : "") . $this->getMinValue();
298 $delim = ", ";
299 }
300 if ($this->getMaxValue() !== null && $this->maxvalue_visible) {
301 $constraints .= $delim . $lng->txt("form_max_value") . ": " . (($this->maxvalueShouldBeLess()) ? "&lt; " : "") . $this->getMaxValue();
302 $delim = ", ";
303 }
304
305 if ($constraints !== "") {
306 $tpl->setCurrentBlock('described_by_constraint');
307 $tpl->setVariable('DESCRIBED_BY_CONSTRAINT_FIELD_ID', $this->getFieldId());
308 $tpl->parseCurrentBlock();
309 }
310
311 $tpl->setCurrentBlock("prop_number");
312
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());
319 }
320 if ($this->getDisabled()) {
321 $tpl->setVariable(
322 "DISABLED",
323 " disabled=\"disabled\""
324 );
325 }
326
327 if ($this->client_side_validation) {
328 $tpl->setVariable("JS_DECIMALS_ALLOWED", (int) $this->areDecimalsAllowed());
329 $tpl->setVariable("JS_ID", $this->getFieldId());
330 }
331
332 if ($constraints !== '') {
333 $tpl->setVariable("TXT_NUMBER_CONSTRAINTS", $constraints);
334 $tpl->setVariable(
335 "CONSTRAINT_FOR_ID",
336 $this->getFieldId()
337 );
338 }
339
340 if ($this->getRequired()) {
341 $tpl->setVariable("REQUIRED", "required=\"required\"");
342 }
343
344 $tpl->parseCurrentBlock();
345
346 return $tpl->get();
347 }
static prepareFormOutput($a_str, bool $a_strip=false)
special template class to simplify handling of ITX/PEAR
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41

References $lng, $tpl, ILIAS\UI\Implementation\Component\Input\getValue(), and ilLegacyFormElementsUtil\prepareFormOutput().

+ Here is the call graph for this function:

◆ setClientSideValidation()

ilNumberInputGUI::setClientSideValidation ( bool  $validate)

Definition at line 354 of file class.ilNumberInputGUI.php.

354 : void
355 {
356 $this->client_side_validation = $validate;
357 }

◆ setDecimals()

ilNumberInputGUI::setDecimals ( int  $a_decimals)

Definition at line 174 of file class.ilNumberInputGUI.php.

174 : void
175 {
176 $this->decimals = $a_decimals;
177 if ($this->decimals) {
178 $this->allowDecimals(true);
179 }
180 }
allowDecimals(bool $a_value)

◆ setMaxLength()

ilNumberInputGUI::setMaxLength ( int  $a_maxlength)

Definition at line 101 of file class.ilNumberInputGUI.php.

101 : void
102 {
103 $this->maxlength = $a_maxlength;
104 }

◆ setMaxValue()

ilNumberInputGUI::setMaxValue ( float  $a_maxvalue,
bool  $a_display_always = false 
)

Definition at line 161 of file class.ilNumberInputGUI.php.

164 : void {
165 $this->maxvalue = $a_maxvalue;
166 $this->maxvalue_visible = $a_display_always;
167 }

◆ setMaxvalueShouldBeLess()

ilNumberInputGUI::setMaxvalueShouldBeLess ( bool  $a_bool)

Definition at line 123 of file class.ilNumberInputGUI.php.

123 : void
124 {
125 $this->maxvalueShouldBeLess = $a_bool;
126 }

References maxvalueShouldBeLess().

+ Here is the call graph for this function:

◆ setMinValue()

ilNumberInputGUI::setMinValue ( float  $a_minvalue,
bool  $a_display_always = false 
)

Definition at line 148 of file class.ilNumberInputGUI.php.

151 : void {
152 $this->minvalue = $a_minvalue;
153 $this->minvalue_visible = $a_display_always;
154 }

◆ setMinvalueShouldBeGreater()

ilNumberInputGUI::setMinvalueShouldBeGreater ( bool  $a_bool)

Definition at line 112 of file class.ilNumberInputGUI.php.

112 : void
113 {
114 $this->minvalueShouldBeGreater = $a_bool;
115 }

References minvalueShouldBeGreater().

+ Here is the call graph for this function:

◆ setSize()

ilNumberInputGUI::setSize ( int  $a_size)

Definition at line 133 of file class.ilNumberInputGUI.php.

133 : void
134 {
135 $this->size = $a_size;
136 }

◆ setSuffix()

ilNumberInputGUI::setSuffix ( string  $a_value)

Definition at line 52 of file class.ilNumberInputGUI.php.

52 : void
53 {
54 $this->suffix = $a_value;
55 }

◆ setValue()

ilNumberInputGUI::setValue ( ?string  $a_value)

Definition at line 62 of file class.ilNumberInputGUI.php.

62 : void
63 {
64 if ($a_value == "" || is_null($a_value)) {
65 $this->value = null;
66 return;
67 }
68 $this->value = (float) str_replace(',', '.', $a_value);
69
70 // integer
71 if (!$this->areDecimalsAllowed()) {
72 $this->value = round($this->value);
73 }
74 // float
75 elseif ($this->getDecimals() > 0) {
76 // get rid of unwanted decimals
77 $this->value = round($this->value, $this->getDecimals());
78
79 // pad value to specified format
80 $this->value = (float) number_format($this->value, $this->getDecimals(), ".", "");
81 }
82 }

References areDecimalsAllowed(), and getDecimals().

Referenced by setValueByArray(), and unserializeData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setValueByArray()

ilNumberInputGUI::setValueByArray ( array  $a_values)

Definition at line 138 of file class.ilNumberInputGUI.php.

138 : void
139 {
140 $this->setValue((string) ($a_values[$this->getPostVar()] ?? ""));
141 }
setValue(?string $a_value)

References ilFormPropertyGUI\getPostVar(), and setValue().

+ Here is the call graph for this function:

◆ unserializeData()

ilNumberInputGUI::unserializeData ( string  $a_data)

Reimplemented from ilFormPropertyGUI.

Definition at line 89 of file class.ilNumberInputGUI.php.

89 : void
90 {
91 $data = unserialize($a_data);
92
93 // BT 35716: table filters with numeric input fields should accept 0
94 if ($data || $data === 0 || $data === 0. || $data === '0') {
95 $this->setValue((string) $data);
96 } else {
97 $this->setValue(null);
98 }
99 }

References $data, and setValue().

+ Here is the call graph for this function:

Field Documentation

◆ $allow_decimals

bool ilNumberInputGUI::$allow_decimals = false
protected

Definition at line 39 of file class.ilNumberInputGUI.php.

◆ $client_side_validation

bool ilNumberInputGUI::$client_side_validation = false
protected

Definition at line 40 of file class.ilNumberInputGUI.php.

◆ $decimals

int ilNumberInputGUI::$decimals = 0
protected

Definition at line 38 of file class.ilNumberInputGUI.php.

◆ $maxlength

int ilNumberInputGUI::$maxlength = 200
protected

Definition at line 29 of file class.ilNumberInputGUI.php.

Referenced by getMaxLength().

◆ $maxvalue

float ilNumberInputGUI::$maxvalue = null
protected

Definition at line 35 of file class.ilNumberInputGUI.php.

◆ $maxvalue_visible

bool ilNumberInputGUI::$maxvalue_visible = false
protected

Definition at line 37 of file class.ilNumberInputGUI.php.

◆ $maxvalueShouldBeLess

bool ilNumberInputGUI::$maxvalueShouldBeLess = false
protected

Definition at line 36 of file class.ilNumberInputGUI.php.

Referenced by maxvalueShouldBeLess().

◆ $minvalue

float ilNumberInputGUI::$minvalue = null
protected

Definition at line 32 of file class.ilNumberInputGUI.php.

◆ $minvalue_visible

bool ilNumberInputGUI::$minvalue_visible = false
protected

Definition at line 34 of file class.ilNumberInputGUI.php.

◆ $minvalueShouldBeGreater

bool ilNumberInputGUI::$minvalueShouldBeGreater = false
protected

Definition at line 33 of file class.ilNumberInputGUI.php.

Referenced by minvalueShouldBeGreater().

◆ $size

int ilNumberInputGUI::$size = 40
protected

Definition at line 30 of file class.ilNumberInputGUI.php.

Referenced by getSize().

◆ $suffix

string ilNumberInputGUI::$suffix = ""
protected

Definition at line 31 of file class.ilNumberInputGUI.php.

Referenced by getSuffix().

◆ $value

float ilNumberInputGUI::$value = null
protected

Definition at line 28 of file class.ilNumberInputGUI.php.

Referenced by getValue().


The documentation for this class was generated from the following file: