You are here

function views_handler_filter_regex::query in Views Hacks 7

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides views_handler_filter::query

File

views_block/handlers/views_handler_filter_regex.inc, line 32

Class

views_handler_filter_regex
Filter based on regular expression.

Code

function query() {
  $db_type = Database::getConnection()
    ->databaseType();
  switch ($db_type) {
    case 'mysql':
      $match = 'REGEXP';
      $nomatch = 'NOT REGEXP';
      break;
    case 'pgsql':
      $match = '*~';

      // case insensitive match
      $nomatch = '!*~';
      break;
    default:
      $operators =& drupal_static(__METHOD__);
      if (empty($operators)) {
        $operators = module_invoke_all('views_regex_operators', $db_type);
      }
      if (empty($operators)) {
        watchdog('views_regex', 'No regex operators found for database type %type.', array(
          '%type' => $db_type,
        ));
        return array();
      }
      $match = $operators['match'];
      $nomatch = $operators['not match'];
  }
  $this->operator = $this->operator === 'match' ? $match : $nomatch;
  parent::query();
}