| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
class patForms_Rule_MinValue extends patForms_Rule |
|---|
| 28 |
{ |
|---|
| 29 |
|
|---|
| 30 |
* script that will be displayed only once |
|---|
| 31 |
* |
|---|
| 32 |
* @access private |
|---|
| 33 |
* @var array |
|---|
| 34 |
*/ |
|---|
| 35 |
|
|---|
| 36 |
var $globalScript = array( |
|---|
| 37 |
'html' => 'Html/Rule/MinValue.js' |
|---|
| 38 |
); |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
* javascript that will be displayed once per instance |
|---|
| 42 |
* |
|---|
| 43 |
* @access private |
|---|
| 44 |
* @var array |
|---|
| 45 |
*/ |
|---|
| 46 |
var $instanceScript = array( |
|---|
| 47 |
'html' => "var pfr_[RULE::ID] = new pFRC_MinValue('[CONTAINER::NAME]');\n" |
|---|
| 48 |
); |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
* properties that have to be replaced in the instance script. |
|---|
| 52 |
* |
|---|
| 53 |
* @access private |
|---|
| 54 |
* @var array |
|---|
| 55 |
*/ |
|---|
| 56 |
var $scriptPlaceholders = array( |
|---|
| 57 |
'RULE::SOURCE' => '_source', |
|---|
| 58 |
); |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
* name of the rule |
|---|
| 62 |
* |
|---|
| 63 |
* @abstract |
|---|
| 64 |
* @access private |
|---|
| 65 |
*/ |
|---|
| 66 |
var $ruleName = 'MinValue'; |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
* define error codes and messages for the rule |
|---|
| 70 |
* |
|---|
| 71 |
* @access private |
|---|
| 72 |
* @var array $validatorErrorCodes |
|---|
| 73 |
* @todo translate error messages |
|---|
| 74 |
*/ |
|---|
| 75 |
var $validatorErrorCodes = array( |
|---|
| 76 |
"C" => array( |
|---|
| 77 |
1 => "Please enter a number that is greater or equal to [VALUE].", |
|---|
| 78 |
), |
|---|
| 79 |
"de" => array( |
|---|
| 80 |
1 => "Bitte geben Sie eine Zahl größer oder gleich [VALUE] ein.", |
|---|
| 81 |
), |
|---|
| 82 |
"fr" => array( |
|---|
| 83 |
1 => "Veuillez entrer une valeur d'au moins [VALUE].", |
|---|
| 84 |
) |
|---|
| 85 |
); |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
* the value to compare with |
|---|
| 89 |
* @access private |
|---|
| 90 |
* @var string |
|---|
| 91 |
*/ |
|---|
| 92 |
var $_value; |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
* field id that is used |
|---|
| 96 |
* @access private |
|---|
| 97 |
* @var string |
|---|
| 98 |
*/ |
|---|
| 99 |
var $_field; |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
* set the value to compare with |
|---|
| 103 |
* |
|---|
| 104 |
* @access public |
|---|
| 105 |
* @param object patForms |
|---|
| 106 |
*/ |
|---|
| 107 |
|
|---|
| 108 |
function setValue($value) |
|---|
| 109 |
{ |
|---|
| 110 |
$this->_value = $value; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
* prepare the rule |
|---|
| 115 |
* |
|---|
| 116 |
* @access public |
|---|
| 117 |
* @param object patForms |
|---|
| 118 |
*/ |
|---|
| 119 |
function prepareRule(&$container) |
|---|
| 120 |
{ |
|---|
| 121 |
patForms_Rule::prepareRule($container); |
|---|
| 122 |
|
|---|
| 123 |
$onChange = $container->getAttribute('onchange'); |
|---|
| 124 |
$newHandler = sprintf('pfr_%s.validate();', $this->_id); |
|---|
| 125 |
$container->setAttribute('onchange', $newHandler . $onChange); |
|---|
| 126 |
|
|---|
| 127 |
return true; |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
* method called by patForms or any patForms_Element to validate the |
|---|
| 132 |
* element or the form. |
|---|
| 133 |
* |
|---|
| 134 |
* @access public |
|---|
| 135 |
* @param object patForms form object |
|---|
| 136 |
*/ |
|---|
| 137 |
function applyRule(&$element, $type = PATFORMS_RULE_AFTER_VALIDATION) |
|---|
| 138 |
{ |
|---|
| 139 |
if (intval($element->getValue()) >= intval($this->_value)){ |
|---|
| 140 |
return true; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
$this->addValidationError(1, array('value' => $this->_value)); |
|---|
| 144 |
return false; |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
* Registers scripts form this rule to the form |
|---|
| 149 |
* |
|---|
| 150 |
* @access public |
|---|
| 151 |
* @param object patForms form object |
|---|
| 152 |
*/ |
|---|
| 153 |
function registerJavascripts(&$form) |
|---|
| 154 |
{ |
|---|
| 155 |
parent::registerJavascripts($form); |
|---|
| 156 |
|
|---|
| 157 |
$script = sprintf("pfr_%s.setMinValue(%s);\n", $this->_id, $this->_value); |
|---|
| 158 |
$form->registerInstanceJavascript($script); |
|---|
| 159 |
} |
|---|
| 160 |
} |
|---|
| 161 |
?> |
|---|