1: <?php
  2: 
  3:   4:   5: 
  6: class Quform_Validator_GreaterThan extends Quform_Validator_Abstract
  7: {
  8:     const INVALID = 'greaterThanInvalid';
  9:     const NOT_NUMERIC = 'greaterThanNotNumeric';
 10:     const NOT_GREATER = 'notGreaterThan';
 11:     const NOT_GREATER_INCLUSIVE = 'notGreaterThanInclusive';
 12: 
 13:      14:  15:  16:  17:  18: 
 19:     public function isValid($value)
 20:     {
 21:         $this->reset();
 22: 
 23:         if ( ! is_string($value)) {
 24:             $this->error(self::INVALID);
 25:             return false;
 26:         }
 27: 
 28:         if ( ! is_numeric($value)) {
 29:             $this->error(self::NOT_NUMERIC);
 30:             return false;
 31:         }
 32: 
 33:         $min = is_numeric($this->config('min')) ? $this->config('min') : 0;
 34: 
 35:         if ($this->config('inclusive')) {
 36:             if ($min > $value) {
 37:                 $this->error(self::NOT_GREATER_INCLUSIVE, compact('min', 'value'));
 38:                 return false;
 39:             }
 40:         } else {
 41:             if ($min >= $value) {
 42:                 $this->error(self::NOT_GREATER, compact('min', 'value'));
 43:                 return false;
 44:             }
 45:         }
 46: 
 47:         return true;
 48:     }
 49: 
 50:      51:  52:  53:  54:  55: 
 56:     public static function getMessageTemplates($key = null)
 57:     {
 58:         $messageTemplates = array(
 59:             self::INVALID => __('Invalid data type, string expected', 'quform'),
 60:             self::NOT_NUMERIC => __('A numeric value is required', 'quform'),
 61:             self::NOT_GREATER => __("The value is not greater than '%min%'", 'quform'),
 62:             self::NOT_GREATER_INCLUSIVE => __("The value is not greater than or equal to '%min%'", 'quform')
 63:         );
 64: 
 65:         if (is_string($key)) {
 66:             return array_key_exists($key, $messageTemplates) ? $messageTemplates[$key] : null;
 67:         }
 68: 
 69:         return $messageTemplates;
 70:     }
 71: 
 72:      73:  74:  75:  76:  77: 
 78:     public static function getDefaultConfig($key = null)
 79:     {
 80:         $config = apply_filters('quform_default_config_validator_greater_than', array(
 81:             'min' => '0',
 82:             'inclusive' => false,
 83:             'messages' => array(
 84:                 self::INVALID => '',
 85:                 self::NOT_NUMERIC => '',
 86:                 self::NOT_GREATER => '',
 87:                 self::NOT_GREATER_INCLUSIVE => ''
 88:             )
 89:         ));
 90: 
 91:         $config['type'] = 'greaterThan';
 92: 
 93:         if (Quform::isNonEmptyString($key)) {
 94:             return Quform::get($config, $key);
 95:         }
 96: 
 97:         return $config;
 98:     }
 99: }
100: