### Eclipse Workspace Patch 1.0 #P views Index: handlers/views_handler_argument_string.inc =================================================================== RCS file: /cvs/drupal/contributions/modules/views/handlers/views_handler_argument_string.inc,v retrieving revision 1.5 diff -u -r1.5 views_handler_argument_string.inc --- handlers/views_handler_argument_string.inc 25 Jun 2009 21:58:17 -0000 1.5 +++ handlers/views_handler_argument_string.inc 9 Aug 2010 21:14:11 -0000 @@ -83,6 +83,25 @@ '#default_value' => $this->options['path_case'], ); + $form['operator'] = array( + '#type' => 'select', + '#title' => t('String Operator'), + '#description' => t('Choose how to handle the string'), + '#options' => array( + 'op_equal' => t('Is equal to'), + 'op_nequal' => t('Is not equal to'), + 'op_contains' => t('Contains'), + //'op_contains_any_word' => t('Contains any words'), + //'op_contains_all_words' => t('Contains all words'), + 'op_start_with' => t('Start with'), + 'op_nstart_with' => t('Does not start with'), + 'op_ends_with' => t('Ends with'), + 'op_nends_with' => t('Does not end with'), + 'op_ncontains' => t('Does not contain') + ), + '#default_value' => $this->options['operator'], + ); + $form['transform_dash'] = array( '#type' => 'checkbox', '#title' => t('Transform spaces to dashes in URL'), @@ -167,7 +186,76 @@ $field = $this->get_formula(); } - $this->query->add_where(0, "$field = '%s'", $argument); + switch ($this->options['operator']) { + case 'op_equal': + $this->query->add_where(0, "$field = '%s'", $argument); + break; + case 'op_nequal': + $this->query->add_where(0, "$field != '%s'", $argument); + break; + case 'op_contains': + $this->query->add_where(0, "$field LIKE '%%%s%%'", $argument); + break; + case 'op_contains_any_word': + // Still work to do on that part + $where = array(); + preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $argument, $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $phrase = false; + // Strip off phrase quotes + if ($match[2]{0} == '"') { + $match[2] = substr($match[2], 1, -1); + $phrase = true; + } + $words = trim($match[2], ',?!();:-'); + $words = $phrase ? array($words) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY); + foreach ($words as $word) { + $where[] = "$upper($field) LIKE $upper('%%%s%%')"; + $values[] = trim($word, " ,!?"); + } + } + + $where = '(' . implode(' OR ', $where) . ')'; + $this->query->add_where(0, $where, $argument); + break; + case 'op_contains_all_words': + // Still work to do on that part + $where = array(); + preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $argument, $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $phrase = false; + // Strip off phrase quotes + if ($match[2]{0} == '"') { + $match[2] = substr($match[2], 1, -1); + $phrase = true; + } + $words = trim($match[2], ',?!();:-'); + $words = $phrase ? array($words) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY); + foreach ($words as $word) { + $where[] = "$upper($field) LIKE $upper('%%%s%%')"; + $values[] = trim($word, " ,!?"); + } + } + + $where = implode(' AND ', $where); + $this->query->add_where(0, $where, $argument); + break; + case 'op_start_with': + $this->query->add_where(0, "$field LIKE '%s%%'", $argument); + break; + case 'op_nstart_with': + $this->query->add_where(0, "$field NOT LIKE '%s%%'", $argument); + break; + case 'op_ends_with': + $this->query->add_where(0, "$field LIKE '%%%s'", $argument); + break; + case 'op_nends_with': + $this->query->add_where(0, "$field NOT LIKE '%%%s'", $argument); + break; + case 'op_ncontains': + $this->query->add_where(0, "$field NOT LIKE '%%%s%%'", $argument); + break; + } } function summary_argument($data) {