mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-18 00:09:06 +01:00
LSformRule_compare: code cleaning
This commit is contained in:
parent
fed9acfedd
commit
26c0026cfc
1 changed files with 19 additions and 16 deletions
|
@ -17,7 +17,6 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,11 +26,24 @@
|
||||||
*/
|
*/
|
||||||
class LSformRule_compare extends LSformRule {
|
class LSformRule_compare extends LSformRule {
|
||||||
|
|
||||||
|
// Validate values one by one or all together
|
||||||
|
const validate_one_by_one = False;
|
||||||
|
|
||||||
// CLI parameters autocompleters
|
// CLI parameters autocompleters
|
||||||
protected static $cli_params_autocompleters = array(
|
protected static $cli_params_autocompleters = array(
|
||||||
'operator' => null,
|
'operator' => null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Operators mapping
|
||||||
|
static protected $_operators = array(
|
||||||
|
'eq' => '==',
|
||||||
|
'neq' => '!=',
|
||||||
|
'gt' => '>',
|
||||||
|
'gte' => '>=',
|
||||||
|
'lt' => '<',
|
||||||
|
'lte' => '<='
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne l'operateur de comparaison.
|
* Retourne l'operateur de comparaison.
|
||||||
*
|
*
|
||||||
|
@ -42,20 +54,11 @@ class LSformRule_compare extends LSformRule {
|
||||||
*/
|
*/
|
||||||
private static function _findOperator($operator_name) {
|
private static function _findOperator($operator_name) {
|
||||||
|
|
||||||
$_operators = array(
|
if (empty(self :: $operator_name)) {
|
||||||
'eq' => '==',
|
|
||||||
'neq' => '!=',
|
|
||||||
'gt' => '>',
|
|
||||||
'gte' => '>=',
|
|
||||||
'lt' => '<',
|
|
||||||
'lte' => '<='
|
|
||||||
);
|
|
||||||
|
|
||||||
if (empty($operator_name)) {
|
|
||||||
return '==';
|
return '==';
|
||||||
} elseif (isset($_operators[$operator_name])) {
|
} elseif (isset(self :: $_operators[$operator_name])) {
|
||||||
return $_operators[$operator_name];
|
return self :: $_operators[$operator_name];
|
||||||
} elseif (in_array($operator_name, $_operators)) {
|
} elseif (in_array($operator_name, self :: $_operators)) {
|
||||||
return $operator_name;
|
return $operator_name;
|
||||||
} else {
|
} else {
|
||||||
return '==';
|
return '==';
|
||||||
|
@ -72,7 +75,7 @@ class LSformRule_compare extends LSformRule {
|
||||||
*
|
*
|
||||||
* @return boolean true si la valeur est valide, false sinon
|
* @return boolean true si la valeur est valide, false sinon
|
||||||
*/
|
*/
|
||||||
public static function validate($value, $options=array(), &$formElement) {
|
public static function validate($values, $options=array(), &$formElement) {
|
||||||
$operator = LSconfig :: get('params.operator', null, 'string', $options);
|
$operator = LSconfig :: get('params.operator', null, 'string', $options);
|
||||||
if (!$operator) {
|
if (!$operator) {
|
||||||
LSerror :: addErrorCode('LSformRule_01',array('type' => 'compare', 'param' => 'operator'));
|
LSerror :: addErrorCode('LSformRule_01',array('type' => 'compare', 'param' => 'operator'));
|
||||||
|
|
Loading…
Reference in a new issue