function matrix_handler_filter::op_word in Matrix field 8.2
Same name in this branch
- 8.2 views/matrix_handler_filter.inc \matrix_handler_filter::op_word()
- 8.2 src/matrix_handler_filter.php \Drupal\matrix\matrix_handler_filter::op_word()
Same name and namespace in other branches
- 7.2 views/matrix_handler_filter.inc \matrix_handler_filter::op_word()
File
- views/
matrix_handler_filter.inc, line 221
Class
- matrix_handler_filter
- Basic textfield filter to handle string filtering commands including equality, like, not like, etc.
Code
function op_word($field) {
list($row, $col, $value) = explode('_____', $this->value);
$where = $this->operator == 'word' ? db_or() : db_and();
preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $value, $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) {
$placeholder = $this
->placeholder();
$where
->where($field . "value LIKE {$placeholder}", array(
$placeholder => '%' . db_like(trim($word, " ,!?")) . '%',
));
}
}
if (!$where) {
return;
}
// previously this was a call_user_func_array but that's unnecessary
// as views will unpack an array that is a single arg.
$this->query
->add_where($this->options['group'], $where);
$this->query
->add_where($this->options['group'], $field . 'row', $row, '=');
$this->query
->add_where($this->options['group'], $field . 'col', $col, '=');
}