1: <?php
2: /**
3: * This file contains the QFloatTextBox class.
4: *
5: * @package Controls
6: */
7:
8: /**
9: * A subclass of QNumericTextBox -- Validate will also ensure
10: * that the Text is a valid float and (if applicable) is in the range of Minimum <= x <= Maximum
11: *
12: * We do not use the sanitize capability of QTextBox here. Sanitizing the data will change the data, and
13: * if the user does not type in a valid float, we will not be able to put up a warning telling the user they made
14: * a mistake. You can easily change this behavior by setting the following:
15: * SanitizeFilter = FILTER_SANITIZE_NUMBER_FLOAT
16: * SanitizeFilterOptions = FILTER_FLAG_ALLOW_FRACTION
17: *
18: * @package Controls
19: * @property int|null $Value Returns the integer value of the text, sanitized.
20: *
21: */
22: class QFloatTextBox extends QNumericTextBox {
23: //////////
24: // Methods
25: //////////
26: /**
27: * Constructor
28: *
29: * @param QControl|QForm $objParentObject
30: * @param null|string $strControlId
31: */
32: public function __construct($objParentObject, $strControlId = null) {
33: parent::__construct($objParentObject, $strControlId);
34: $this->strLabelForInvalid = QApplication::Translate('Invalid Float');
35: $this->strDataType = QType::Float;
36: }
37:
38: public function __get($strName) {
39: switch ($strName) {
40: case "Value":
41: if ($this->strText === null || $this->strText === "") {
42: return null;
43: } else {
44: return (float)filter_var ($this->strText, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
45: }
46:
47: default:
48: try {
49: return parent::__get($strName);
50: } catch (QCallerException $objExc) {
51: $objExc->IncrementOffset();
52: throw $objExc;
53: }
54: }
55: }
56: }