1: <?php
2: /**
3: * This file contains the QIntegerTextBox class
4: *
5: * @package Controls
6: */
7:
8: /**
9: * A subclass of TextBox with its validate method overridden -- Validate will also ensure
10: * that the Text is a valid integer 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 an integer, 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 SanitizeFilter = FILTER_SANITIZE_NUMBER_INT.
15: *
16: * @package Controls
17: * @property int|null $Value Returns the integer value of the text, sanitized.
18: */
19:
20: class QIntegerTextBox extends QNumericTextBox {
21: //////////
22: // Methods
23: //////////
24: /**
25: * Constructor
26: *
27: * @param QControl|QForm $objParentObject
28: * @param null|string $strControlId
29: */
30: public function __construct($objParentObject, $strControlId = null) {
31: parent::__construct($objParentObject, $strControlId);
32: $this->strLabelForInvalid = QApplication::Translate('Invalid Integer');
33: $this->strDataType = QType::Integer;
34: }
35:
36: public function __get($strName) {
37: switch ($strName) {
38: case "Value":
39: if ($this->strText === null || $this->strText === "") {
40: return null;
41: } else {
42: return (int)filter_var ($this->strText, FILTER_SANITIZE_NUMBER_INT);
43: }
44:
45: default:
46: try {
47: return parent::__get($strName);
48: } catch (QCallerException $objExc) {
49: $objExc->IncrementOffset();
50: throw $objExc;
51: }
52: }
53: }
54:
55: }