You are here

public function contextual_range_filter_plugin_argument_validate_numeric_range::validate_argument in Views Contextual Range Filter 7

Validate the argument.

Overrides views_plugin_argument_validate::validate_argument

File

views/contextual_range_filter_plugin_argument_validate_numeric_range.inc, line 22
Contains the numeric argument range validator plugin.

Class

contextual_range_filter_plugin_argument_validate_numeric_range
Validate whether an argument is a number or a numeric range or not.

Code

public function validate_argument($argument) {

  // The character '+' may arrive as space.
  $ranges = preg_split('/[+ ]/', $argument);
  foreach ($ranges as $range) {
    $minmax = explode(CONTEXTUAL_RANGE_FILTER_SEPARATOR1, $range);
    if (count($minmax) < 2) {
      $minmax = explode(CONTEXTUAL_RANGE_FILTER_SEPARATOR2, $range);
    }
    if (count($minmax) < 2) {

      // Not a range but single value. Must be numeric.
      if (is_numeric($range)) {
        continue;
      }
      return FALSE;
    }
    if (!(is_numeric($minmax[0]) && is_numeric($minmax[1]) && $minmax[0] <= $minmax[1] || empty($minmax[0]) && is_numeric($minmax[1]) || empty($minmax[1]) && is_numeric($minmax[0]))) {
      return FALSE;
    }
  }
  return TRUE;
}