ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 ($a_title="", $a_postvar="")
 Constructor. More...
 
 setSuffix ($a_value)
 Set suffix. More...
 
 getSuffix ()
 Get suffix. More...
 
 setValue ($a_value)
 Set Value. More...
 
 getValue ()
 Get Value. More...
 
 setMaxLength ($a_maxlength)
 Set Max Length. More...
 
 getMaxLength ()
 Get Max Length. More...
 
 setMinvalueShouldBeGreater ($a_bool)
 Set minvalueShouldBeGreater. More...
 
 minvalueShouldBeGreater ()
 Get minvalueShouldBeGreater. More...
 
 setMaxvalueShouldBeLess ($a_bool)
 Set maxvalueShouldBeLess. More...
 
 maxvalueShouldBeLess ()
 Get maxvalueShouldBeLess. More...
 
 setSize ($a_size)
 Set Size. More...
 
 setValueByArray ($a_values)
 Set value by array. More...
 
 getSize ()
 Get Size. More...
 
 setMinValue ($a_minvalue, $a_display_always=false)
 Set Minimum Value. More...
 
 getMinValue ()
 Get Minimum Value. More...
 
 setMaxValue ($a_maxvalue, $a_display_always=false)
 Set Maximum Value. More...
 
 getMaxValue ()
 Get Maximum Value. More...
 
 setDecimals ($a_decimals)
 Set Decimal Places. More...
 
 getDecimals ()
 Get Decimal Places. More...
 
 allowDecimals ($a_value)
 Toggle Decimals. More...
 
 areDecimalsAllowed ()
 
 checkInput ()
 Check input, strip slashes etc. More...
 
 insert (&$a_tpl)
 Insert property html. More...
 
 render ()
 Insert property html. More...
 
 getPostValueForComparison ()
 parse post value to make it comparable More...
 
- Public Member Functions inherited from ilSubEnabledFormPropertyGUI
 addSubItem ($a_item)
 Add Subitem. More...
 
 getSubItems ()
 Get Subitems. More...
 
 getSubInputItemsRecursive ()
 returns a flat array of possibly existing subitems recursively More...
 
 checkSubItemsInput ()
 Check SubItems. More...
 
 getSubForm ()
 Get sub form html. More...
 
 getItemByPostVar ($a_post_var)
 Get item by post var. More...
 
- Public Member Functions inherited from ilFormPropertyGUI
 __construct ($a_title="", $a_postvar="")
 Constructor. More...
 
executeCommand ()
 Execute command. More...
 
 getType ()
 Get Type. More...
 
 setTitle ($a_title)
 Set Title. More...
 
 getTitle ()
 Get Title. More...
 
 setPostVar ($a_postvar)
 Set Post Variable. More...
 
 getPostVar ()
 Get Post Variable. More...
 
 getFieldId ()
 Get Post Variable. More...
 
 setInfo ($a_info)
 Set Information Text. More...
 
 getInfo ()
 Get Information Text. More...
 
 setAlert ($a_alert)
 Set Alert Text. More...
 
 getAlert ()
 Get Alert Text. More...
 
 setRequired ($a_required)
 Set Required. More...
 
 getRequired ()
 Get Required. More...
 
 setDisabled ($a_disabled)
 Set Disabled. More...
 
 getDisabled ()
 Get Disabled. More...
 
 checkInput ()
 Check input, strip slashes etc. More...
 
 setParentForm ($a_parentform)
 Set Parent Form. More...
 
 getParentForm ()
 Get Parent Form. More...
 
 setParent ($a_val)
 Set Parent GUI object. More...
 
 getParent ()
 Get Parent GUI object. More...
 
 getSubForm ()
 Get sub form html. More...
 
 hideSubForm ()
 Sub form hidden on init? More...
 
 setHiddenTitle ($a_val)
 Set hidden title (for screenreaders) More...
 
 getHiddenTitle ()
 Get hidden title. More...
 
 getItemByPostVar ($a_post_var)
 Get item by post var. More...
 
 serializeData ()
 serialize data More...
 
 unserializeData ($a_data)
 unserialize data More...
 
 writeToSession ()
 Write to session. More...
 
 clearFromSession ()
 Clear session value. More...
 
 readFromSession ()
 Read from session. More...
 
 getHiddenTag ($a_post_var, $a_value)
 Get hidden tag (used for disabled properties) More...
 
 setMulti ($a_multi, $a_sortable=false, $a_addremove=true)
 Set Multi. More...
 
 getMulti ()
 Get Multi. More...
 
 setMultiValues (array $a_values)
 Set multi values. More...
 
 getMultiValues ()
 Get multi values. More...
 
 getContentOutsideFormTag ()
 Get content that has to reside outside of the parent form tag, e.g. More...
 
 removeProhibitedCharacters ($a_text)
 Remove prohibited characters see #19159. More...
 
 stripSlashesAddSpaceFallback ($a_str)
 Strip slashes with add space fallback, see https://www.ilias.de/mantis/view.php?id=19727. More...
 

Protected Attributes

 $value
 
 $maxlength = 200
 
 $size = 40
 
 $suffix
 
 $minvalue = false
 
 $minvalueShouldBeGreater = false
 
 $minvalue_visible = false
 
 $maxvalue = false
 
 $maxvalueShouldBeLess = false
 
 $maxvalue_visible = false
 
 $decimals
 
 $allow_decimals = false
 
- Protected Attributes inherited from ilSubEnabledFormPropertyGUI
 $sub_items = array()
 
- Protected Attributes inherited from ilFormPropertyGUI
 $type
 
 $title
 
 $postvar
 
 $info
 
 $alert
 
 $required = false
 
 $parentgui
 
 $parentform
 
 $hidden_title = ""
 
 $multi = false
 
 $multi_sortable = false
 
 $multi_addremove = true
 
 $multi_values
 

Additional Inherited Members

- Protected Member Functions inherited from ilFormPropertyGUI
 setType ($a_type)
 Set Type. More...
 
 getMultiIconsHTML ()
 Get HTML for multiple value icons. More...
 

Detailed Description

This class represents a number property in a property form.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Parameters
string$a_titleTitle
string$a_postvarPost Variable

Reimplemented from ilFormPropertyGUI.

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

36 {
37 parent::__construct($a_title, $a_postvar);
38 }

Member Function Documentation

◆ allowDecimals()

ilNumberInputGUI::allowDecimals (   $a_value)

Toggle Decimals.

Parameters
bool$a_value

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

263 {
264 $this->allow_decimals = (bool)$a_value;
265 }

Referenced by setDecimals().

+ Here is the caller graph for this function:

◆ areDecimalsAllowed()

ilNumberInputGUI::areDecimalsAllowed ( )
Returns
bool

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

References $allow_decimals.

Referenced by render(), and setValue().

+ Here is the caller graph for this function:

◆ checkInput()

ilNumberInputGUI::checkInput ( )

Check input, strip slashes etc.

set alert, if input is not ok.

Returns
boolean Input ok, true/false

Reimplemented from ilFormPropertyGUI.

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

283 {
284 global $lng;
285
287 if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
288 {
289 $this->setAlert($lng->txt("msg_input_is_required"));
290 return false;
291 }
292
293 if (trim($_POST[$this->getPostVar()]) != "" &&
294 ! is_numeric(str_replace(',', '.', $_POST[$this->getPostVar()])))
295 {
296 $this->minvalue_visible = true;
297 $this->maxvalue_visible = true;
298 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
299 return false;
300 }
301
302 if ($this->minvalueShouldBeGreater())
303 {
304 if (trim($_POST[$this->getPostVar()]) != "" &&
305 $this->getMinValue() !== false &&
306 $_POST[$this->getPostVar()] <= $this->getMinValue())
307 {
308 $this->minvalue_visible = true;
309 $this->setAlert($lng->txt("form_msg_value_too_low"));
310 return false;
311 }
312 }
313 else
314 {
315 if (trim($_POST[$this->getPostVar()]) != "" &&
316 $this->getMinValue() !== false &&
317 $_POST[$this->getPostVar()] < $this->getMinValue())
318 {
319 $this->minvalue_visible = true;
320 $this->setAlert($lng->txt("form_msg_value_too_low"));
321 return false;
322 }
323 }
324
325 if ($this->maxvalueShouldBeLess())
326 {
327 if (trim($_POST[$this->getPostVar()]) != "" &&
328 $this->getMaxValue() !== false &&
329 $_POST[$this->getPostVar()] >= $this->getMaxValue())
330 {
331 $this->maxvalue_visible = true;
332 $this->setAlert($lng->txt("form_msg_value_too_high"));
333 return false;
334 }
335 }
336 else
337 {
338 if (trim($_POST[$this->getPostVar()]) != "" &&
339 $this->getMaxValue() !== false &&
340 $_POST[$this->getPostVar()] > $this->getMaxValue())
341 {
342 $this->maxvalue_visible = true;
343 $this->setAlert($lng->txt("form_msg_value_too_high"));
344 return false;
345 }
346 }
347
348 return $this->checkSubItemsInput();
349 }
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
minvalueShouldBeGreater()
Get minvalueShouldBeGreater.
getMinValue()
Get Minimum Value.
maxvalueShouldBeLess()
Get maxvalueShouldBeLess.
getMaxValue()
Get Maximum Value.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$_POST['username']
Definition: cron.php:12
global $lng
Definition: privfeed.php:40

References $_POST, $lng, ilSubEnabledFormPropertyGUI\checkSubItemsInput(), getMaxValue(), getMinValue(), ilFormPropertyGUI\getPostVar(), ilFormPropertyGUI\getRequired(), maxvalueShouldBeLess(), minvalueShouldBeGreater(), ilFormPropertyGUI\setAlert(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ getDecimals()

ilNumberInputGUI::getDecimals ( )

Get Decimal Places.

Returns
int Decimal Places

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

253 {
254 return $this->decimals;
255 }

References $decimals.

Referenced by render(), and setValue().

+ Here is the caller graph for this function:

◆ getMaxLength()

ilNumberInputGUI::getMaxLength ( )

Get Max Length.

Returns
int Max Length

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

115 {
116 return $this->maxlength;
117 }

References $maxlength.

Referenced by render().

+ Here is the caller graph for this function:

◆ getMaxValue()

ilNumberInputGUI::getMaxValue ( )

Get Maximum Value.

Returns
float Maximum Value

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

229 {
230 return $this->maxvalue;
231 }

References $maxvalue.

Referenced by checkInput(), and render().

+ Here is the caller graph for this function:

◆ getMinValue()

ilNumberInputGUI::getMinValue ( )

Get Minimum Value.

Returns
float Minimum Value

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

207 {
208 return $this->minvalue;
209 }

References $minvalue.

Referenced by checkInput(), and render().

+ Here is the caller graph for this function:

◆ getPostValueForComparison()

ilNumberInputGUI::getPostValueForComparison ( )

parse post value to make it comparable

used by combination input gui

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

429 {
431 if($value != "")
432 {
433 return (int)$value;
434 }
435 }

References $_POST, $value, ilFormPropertyGUI\getPostVar(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ getSize()

ilNumberInputGUI::getSize ( )

Get Size.

Returns
int Size

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

185 {
186 return $this->size;
187 }

References $size.

Referenced by render().

+ Here is the caller graph for this function:

◆ getSuffix()

ilNumberInputGUI::getSuffix ( )

Get suffix.

Returns
string suffix

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

References $suffix.

Referenced by render().

+ Here is the caller graph for this function:

◆ getValue()

ilNumberInputGUI::getValue ( )

Get Value.

Returns
string Value

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

95 {
96 return $this->value;
97 }

References $value.

Referenced by render().

+ Here is the caller graph for this function:

◆ insert()

ilNumberInputGUI::insert ( $a_tpl)

Insert property html.

Returns
int Size

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

357 {
358 $html = $this->render();
359
360 $a_tpl->setCurrentBlock("prop_generic");
361 $a_tpl->setVariable("PROP_GENERIC", $html);
362 $a_tpl->parseCurrentBlock();
363 }
render()
Insert property html.
$html
Definition: example_001.php:87

References $html, and render().

+ Here is the call graph for this function:

◆ maxvalueShouldBeLess()

ilNumberInputGUI::maxvalueShouldBeLess ( )

Get maxvalueShouldBeLess.

Returns
boolean true if the maximum value should be less than maxvalue

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

References $maxvalueShouldBeLess.

Referenced by checkInput(), render(), and setMaxvalueShouldBeLess().

+ Here is the caller graph for this function:

◆ minvalueShouldBeGreater()

ilNumberInputGUI::minvalueShouldBeGreater ( )

Get minvalueShouldBeGreater.

Returns
boolean true if the minimum value should be greater than minvalue

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

References $minvalueShouldBeGreater.

Referenced by checkInput(), render(), and setMinvalueShouldBeGreater().

+ Here is the caller graph for this function:

◆ render()

ilNumberInputGUI::render ( )

Insert property html.

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

369 {
370 global $lng;
371
372 $tpl = new ilTemplate("tpl.prop_number.html", true, true, "Services/Form");
373
374 if (strlen($this->getValue()))
375 {
376 $tpl->setCurrentBlock("prop_number_propval");
377 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
378 $tpl->parseCurrentBlock();
379 }
380 $tpl->setCurrentBlock("prop_number");
381
382 $tpl->setVariable("POST_VAR", $this->getPostVar());
383 $tpl->setVariable("ID", $this->getFieldId());
384 $tpl->setVariable("SIZE", $this->getSize());
385 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
386 if (strlen($this->getSuffix())) $tpl->setVariable("INPUT_SUFFIX", $this->getSuffix());
387 if ($this->getDisabled())
388 {
389 $tpl->setVariable("DISABLED",
390 " disabled=\"disabled\"");
391 }
392
393 /*
394 $tpl->setVariable("JS_DECIMALS_ALLOWED", (int)$this->areDecimalsAllowed());
395 */
396
397 // constraints
398 if ($this->areDecimalsAllowed() && $this->getDecimals() > 0)
399 {
400 $constraints = $lng->txt("form_format").": ###.".str_repeat("#", $this->getDecimals());
401 $delim = ", ";
402 }
403 if ($this->getMinValue() !== false && $this->minvalue_visible)
404 {
405 $constraints.= $delim.$lng->txt("form_min_value").": ".(($this->minvalueShouldBeGreater()) ? "&gt; " : "").$this->getMinValue();
406 $delim = ", ";
407 }
408 if ($this->getMaxValue() !== false && $this->maxvalue_visible)
409 {
410 $constraints.= $delim.$lng->txt("form_max_value").": ".(($this->maxvalueShouldBeLess()) ? "&lt; " : "").$this->getMaxValue();
411 $delim = ", ";
412 }
413 if ($constraints != "")
414 {
415 $tpl->setVariable("TXT_NUMBER_CONSTRAINTS", $constraints);
416 }
417
418 $tpl->parseCurrentBlock();
419
420 return $tpl->get();
421 }
global $tpl
Definition: ilias.php:8
getFieldId()
Get Post Variable.
getMaxLength()
Get Max Length.
getDecimals()
Get Decimal Places.
special template class to simplify handling of ITX/PEAR
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public

References $lng, $maxvalue_visible, $tpl, areDecimalsAllowed(), getDecimals(), ilFormPropertyGUI\getDisabled(), ilFormPropertyGUI\getFieldId(), getMaxLength(), getMaxValue(), getMinValue(), ilFormPropertyGUI\getPostVar(), getSize(), getSuffix(), getValue(), maxvalueShouldBeLess(), minvalueShouldBeGreater(), and ilUtil\prepareFormOutput().

Referenced by insert().

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

◆ setDecimals()

ilNumberInputGUI::setDecimals (   $a_decimals)

Set Decimal Places.

Parameters
int$a_decimalsDecimal Places

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

239 {
240 $this->decimals = (int)$a_decimals;
241 if($this->decimals)
242 {
243 $this->allowDecimals(true);
244 }
245 }
allowDecimals($a_value)
Toggle Decimals.

References allowDecimals().

+ Here is the call graph for this function:

◆ setMaxLength()

ilNumberInputGUI::setMaxLength (   $a_maxlength)

Set Max Length.

Parameters
int$a_maxlengthMax Length

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

105 {
106 $this->maxlength = $a_maxlength;
107 }

◆ setMaxValue()

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

Set Maximum Value.

Parameters
float$a_maxvalueMaximum Value
bool$a_display_always

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

218 {
219 $this->maxvalue = $a_maxvalue;
220 $this->maxvalue_visible = (bool)$a_display_always;
221 }

◆ setMaxvalueShouldBeLess()

ilNumberInputGUI::setMaxvalueShouldBeLess (   $a_bool)

Set maxvalueShouldBeLess.

Parameters
boolean$a_booltrue if the maximum value should be less than maxvalue

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

145 {
146 $this->maxvalueShouldBeLess = $a_bool;
147 }

References maxvalueShouldBeLess().

+ Here is the call graph for this function:

◆ setMinValue()

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

Set Minimum Value.

Parameters
float$a_minvalueMinimum Value
bool$a_display_always

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

196 {
197 $this->minvalue = $a_minvalue;
198 $this->minvalue_visible = (bool)$a_display_always;
199 }

◆ setMinvalueShouldBeGreater()

ilNumberInputGUI::setMinvalueShouldBeGreater (   $a_bool)

Set minvalueShouldBeGreater.

Parameters
boolean$a_booltrue if the minimum value should be greater than minvalue

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

125 {
126 $this->minvalueShouldBeGreater = $a_bool;
127 }

References minvalueShouldBeGreater().

+ Here is the call graph for this function:

◆ setSize()

ilNumberInputGUI::setSize (   $a_size)

Set Size.

Parameters
int$a_sizeSize

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

165 {
166 $this->size = $a_size;
167 }

◆ setSuffix()

ilNumberInputGUI::setSuffix (   $a_value)

Set suffix.

Parameters
string$a_valuesuffix

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

46 {
47 $this->suffix = $a_value;
48 }

◆ setValue()

ilNumberInputGUI::setValue (   $a_value)

Set Value.

Parameters
string$a_valueValue

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

66 {
67 $this->value = str_replace(',', '.', $a_value);
68
69 // empty strings are allowed
70 if($this->value != "")
71 {
72 // integer
73 if(!$this->areDecimalsAllowed())
74 {
75 $this->value = round($this->value);
76 }
77 // float
78 else if($this->getDecimals() > 0)
79 {
80 // get rid of unwanted decimals
81 $this->value = round($this->value, $this->getDecimals());
82
83 // pad value to specified format
84 $this->value = number_format($this->value, $this->getDecimals(), ".", "");
85 }
86 }
87 }

References areDecimalsAllowed(), and getDecimals().

Referenced by setValueByArray().

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

◆ setValueByArray()

ilNumberInputGUI::setValueByArray (   $a_values)

Set value by array.

Parameters
array$a_valuesvalue array

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

175 {
176 $this->setValue($a_values[$this->getPostVar()]);
177 }
setValue($a_value)
Set Value.

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

+ Here is the call graph for this function:

Field Documentation

◆ $allow_decimals

ilNumberInputGUI::$allow_decimals = false
protected

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

Referenced by areDecimalsAllowed().

◆ $decimals

ilNumberInputGUI::$decimals
protected

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

Referenced by getDecimals().

◆ $maxlength

ilNumberInputGUI::$maxlength = 200
protected

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

Referenced by getMaxLength().

◆ $maxvalue

ilNumberInputGUI::$maxvalue = false
protected

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

Referenced by getMaxValue().

◆ $maxvalue_visible

ilNumberInputGUI::$maxvalue_visible = false
protected

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

Referenced by render().

◆ $maxvalueShouldBeLess

ilNumberInputGUI::$maxvalueShouldBeLess = false
protected

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

Referenced by maxvalueShouldBeLess().

◆ $minvalue

ilNumberInputGUI::$minvalue = false
protected

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

Referenced by getMinValue().

◆ $minvalue_visible

ilNumberInputGUI::$minvalue_visible = false
protected

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

◆ $minvalueShouldBeGreater

ilNumberInputGUI::$minvalueShouldBeGreater = false
protected

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

Referenced by minvalueShouldBeGreater().

◆ $size

ilNumberInputGUI::$size = 40
protected

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

Referenced by getSize().

◆ $suffix

ilNumberInputGUI::$suffix
protected

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

Referenced by getSuffix().

◆ $value

ilNumberInputGUI::$value
protected

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

Referenced by getPostValueForComparison(), and getValue().


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