ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
 symbol ()
 
 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
Deprecated:
12 This component will be removed with ILIAS 12

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

Constructor & Destructor Documentation

◆ __construct()

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

Reimplemented from ilFormPropertyGUI.

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

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

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 188 of file class.ilNumberInputGUI.php.

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

◆ areDecimalsAllowed()

ilNumberInputGUI::areDecimalsAllowed ( )

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

193 : bool
194 {
196 }

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 198 of file class.ilNumberInputGUI.php.

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

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

Referenced by setValue().

+ Here is the caller graph for this function:

◆ getInput()

ilNumberInputGUI::getInput ( )

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

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

References ILIAS\Repository\str().

+ Here is the call graph for this function:

◆ getMaxLength()

ilNumberInputGUI::getMaxLength ( )

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

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

References $maxlength.

◆ getMaxValue()

ilNumberInputGUI::getMaxValue ( )

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

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

◆ getMinValue()

ilNumberInputGUI::getMinValue ( )

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

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

◆ getPostValueForComparison()

ilNumberInputGUI::getPostValueForComparison ( )

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

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

◆ getSize()

ilNumberInputGUI::getSize ( )

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

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

References $size.

◆ getSuffix()

ilNumberInputGUI::getSuffix ( )

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

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

References $suffix.

◆ getValue()

ilNumberInputGUI::getValue ( )

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

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

References $value.

◆ insert()

ilNumberInputGUI::insert ( ilTemplate  $a_tpl)

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

263 : void
264 {
265 $html = $this->render();
266
267 $a_tpl->setCurrentBlock("prop_generic");
268 $a_tpl->setVariable("PROP_GENERIC", $html);
269 $a_tpl->parseCurrentBlock();
270 }
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
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 129 of file class.ilNumberInputGUI.php.

129 : bool
130 {
132 }

References $maxvalueShouldBeLess.

Referenced by setMaxvalueShouldBeLess().

+ Here is the caller graph for this function:

◆ minvalueShouldBeGreater()

ilNumberInputGUI::minvalueShouldBeGreater ( )

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

118 : bool
119 {
121 }

References $minvalueShouldBeGreater.

Referenced by setMinvalueShouldBeGreater().

+ Here is the caller graph for this function:

◆ render()

ilNumberInputGUI::render ( )

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

272 : string
273 {
275
276 $tpl = new ilTemplate("tpl.prop_number.html", true, true, "components/ILIAS/Form");
277
278 if (strlen((string) $this->getValue())) {
279 $tpl->setCurrentBlock("prop_number_propval");
280 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput((string) $this->getValue()));
281 $tpl->parseCurrentBlock();
282 }
283
284 if ($this->getInfo() !== '') {
285 $tpl->setCurrentBlock('described_by_description');
286 $tpl->setVariable('DESCRIBED_BY_DESCRIPTION_FIELD_ID', $this->getFieldId());
287 $tpl->parseCurrentBlock();
288 }
289
290 // constraints
291 $constraints = "";
292 $delim = "";
293 if ($this->areDecimalsAllowed() && $this->getDecimals() > 0) {
294 $constraints = $lng->txt("form_format") . ": ###." . str_repeat("#", $this->getDecimals());
295 $delim = ", ";
296 }
297 if ($this->getMinValue() !== null && $this->minvalue_visible) {
298 $constraints .= $delim . $lng->txt("form_min_value") . ": " . (($this->minvalueShouldBeGreater()) ? "&gt; " : "") . $this->getMinValue();
299 $delim = ", ";
300 }
301 if ($this->getMaxValue() !== null && $this->maxvalue_visible) {
302 $constraints .= $delim . $lng->txt("form_max_value") . ": " . (($this->maxvalueShouldBeLess()) ? "&lt; " : "") . $this->getMaxValue();
303 $delim = ", ";
304 }
305
306 if ($constraints !== "") {
307 $tpl->setCurrentBlock('described_by_constraint');
308 $tpl->setVariable('DESCRIBED_BY_CONSTRAINT_FIELD_ID', $this->getFieldId());
309 $tpl->parseCurrentBlock();
310 }
311
312 $tpl->setCurrentBlock("prop_number");
313
314 $tpl->setVariable("POST_VAR", $this->getPostVar());
315 $tpl->setVariable("ID", $this->getFieldId());
316 $tpl->setVariable("SIZE", $this->getSize());
317 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
318 if (strlen($this->getSuffix())) {
319 $tpl->setVariable("INPUT_SUFFIX", $this->getSuffix());
320 }
321 if ($this->getDisabled()) {
322 $tpl->setVariable(
323 "DISABLED",
324 " disabled=\"disabled\""
325 );
326 }
327
328 if ($this->client_side_validation) {
329 $tpl->setVariable("JS_DECIMALS_ALLOWED", (int) $this->areDecimalsAllowed());
330 $tpl->setVariable("JS_ID", $this->getFieldId());
331 }
332
333 if ($constraints !== '') {
334 $tpl->setVariable("TXT_NUMBER_CONSTRAINTS", $constraints);
335 $tpl->setVariable(
336 "CONSTRAINT_FOR_ID",
337 $this->getFieldId()
338 );
339 }
340
341 if ($this->getRequired()) {
342 $tpl->setVariable("REQUIRED", "required=\"required\"");
343 }
344
345 $tpl->parseCurrentBlock();
346
347 return $tpl->get();
348 }
static prepareFormOutput($a_str, bool $a_strip=false)
special template class to simplify handling of ITX/PEAR

References $lng, 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 355 of file class.ilNumberInputGUI.php.

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

◆ setDecimals()

ilNumberInputGUI::setDecimals ( int  $a_decimals)

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

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

◆ setMaxLength()

ilNumberInputGUI::setMaxLength ( int  $a_maxlength)

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

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

◆ setMaxValue()

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

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

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

◆ setMaxvalueShouldBeLess()

ilNumberInputGUI::setMaxvalueShouldBeLess ( bool  $a_bool)

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

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

References maxvalueShouldBeLess().

+ Here is the call graph for this function:

◆ setMinValue()

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

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

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

◆ setMinvalueShouldBeGreater()

ilNumberInputGUI::setMinvalueShouldBeGreater ( bool  $a_bool)

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

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

References minvalueShouldBeGreater().

+ Here is the call graph for this function:

◆ setSize()

ilNumberInputGUI::setSize ( int  $a_size)

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

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

◆ setSuffix()

ilNumberInputGUI::setSuffix ( string  $a_value)

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

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

◆ setValue()

ilNumberInputGUI::setValue ( ?string  $a_value)

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

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

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 139 of file class.ilNumberInputGUI.php.

139 : void
140 {
141 $this->setValue((string) ($a_values[$this->getPostVar()] ?? ""));
142 }
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 90 of file class.ilNumberInputGUI.php.

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

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 40 of file class.ilNumberInputGUI.php.

◆ $client_side_validation

bool ilNumberInputGUI::$client_side_validation = false
protected

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

◆ $decimals

int ilNumberInputGUI::$decimals = 0
protected

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

◆ $maxlength

int ilNumberInputGUI::$maxlength = 200
protected

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

Referenced by getMaxLength().

◆ $maxvalue

float ilNumberInputGUI::$maxvalue = null
protected

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

◆ $maxvalue_visible

bool ilNumberInputGUI::$maxvalue_visible = false
protected

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

◆ $maxvalueShouldBeLess

bool ilNumberInputGUI::$maxvalueShouldBeLess = false
protected

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

Referenced by maxvalueShouldBeLess().

◆ $minvalue

float ilNumberInputGUI::$minvalue = null
protected

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

◆ $minvalue_visible

bool ilNumberInputGUI::$minvalue_visible = false
protected

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

◆ $minvalueShouldBeGreater

bool ilNumberInputGUI::$minvalueShouldBeGreater = false
protected

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

Referenced by minvalueShouldBeGreater().

◆ $size

int ilNumberInputGUI::$size = 40
protected

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

Referenced by getSize().

◆ $suffix

string ilNumberInputGUI::$suffix = ""
protected

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

Referenced by getSuffix().

◆ $value

float ilNumberInputGUI::$value = null
protected

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

Referenced by getValue().


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