*/ class LSformRule_compare extends LSformRule { /** * Retourne l'operateur de comparaison. * * @access private * @param string Nom de l'operateur * * @return string Operateur à utiliser */ private static function _findOperator($operator_name) { $_operators = array( 'eq' => '==', 'neq' => '!=', 'gt' => '>', 'gte' => '>=', 'lt' => '<', 'lte' => '<=' ); if (empty($operator_name)) { return '=='; } elseif (isset($this->_operators[$operator_name])) { return $this->_operators[$operator_name]; } elseif (in_array($operator_name, $this->_operators)) { return $operator_name; } else { return '=='; } } /** * Vérification des valeurs. * * @param string $values Valeurs à vérifier * @param array $options Options de validation : * - Operateur : $options['params']['operator'] * @param object $formElement L'objet formElement attaché * * @return boolean true si la valeur est valide, false sinon */ public static function validate ($values,$options=array(),$formElement) { if (!isset($options['params']['operator'])) { LSerror :: addErrorCode('LSformRule_01',array('type' => 'compare', 'param' => 'operator'); return; } $operator = self :: _findOperator($options['params']['operator']); if ('==' != $operator && '!=' != $operator) { $compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);'); } else { $compareFn = create_function('$a, $b', 'return $a ' . $operator . ' $b;'); } return $compareFn($values[0], $values[1]); } }