diff --git a/wire/core/DatabaseQuerySelectFulltext.php b/wire/core/DatabaseQuerySelectFulltext.php index b81e7e2a..2084b5c2 100644 --- a/wire/core/DatabaseQuerySelectFulltext.php +++ b/wire/core/DatabaseQuerySelectFulltext.php @@ -49,11 +49,21 @@ class DatabaseQuerySelectFulltext extends Wire { protected $tableName = ''; /** + * Current field/column name + * * @var $fieldName * */ protected $fieldName = ''; + /** + * All field/column names (if more than one) + * + * @var array + * + */ + protected $fieldNames = array(); + /** * @var string * @@ -256,7 +266,6 @@ class DatabaseQuerySelectFulltext extends Wire { public function match($tableName, $fieldName, $operator, $value) { $this->tableName = $this->database->escapeTable($tableName); - $this->fieldName = $this->database->escapeCol($fieldName); $allowOrder = true; if(strpos($operator, '!') === 0 && $operator !== '!=') { @@ -281,7 +290,22 @@ class DatabaseQuerySelectFulltext extends Wire { if(!$this->method) { throw new WireException("Unimplemented operator in $this::match()"); } + + if(is_array($fieldName) && count($fieldName) < 2) { + $fieldName = reset($fieldName); + } + if(is_array($fieldName)) { + $this->matchArrayFieldName($fieldName, $value); + } else { + $this->matchFieldName($fieldName, $value); + } + + return $this; + } + + protected function matchFieldName($fieldName, $value) { + $this->fieldName = $this->database->escapeCol($fieldName); if(is_array($value)) { $this->matchArrayValue($value); } else { @@ -289,8 +313,28 @@ class DatabaseQuerySelectFulltext extends Wire { $method = $this->method; if(strlen($value)) $this->$method($value); } + } + + /** + * Match when given $fieldName is an array + * + * @param array $fieldNames + * @param mixed $value + * @since 3.0.169 + * + */ + protected function matchArrayFieldName(array $fieldNames, $value) { + $query = $this->query; + $this->query = $this->wire(new DatabaseQuerySelect()); + $this->query->bindOption(true, $query->bindOption(true)); - return $this; + foreach($fieldNames as $fieldName) { + $this->matchFieldName($fieldName, $value); + } + + $query->where('(' . implode(') OR (', $this->query->where) . ')'); + $this->query->copyBindValuesTo($query); + $this->query = $query; } /** diff --git a/wire/core/FieldtypeMulti.php b/wire/core/FieldtypeMulti.php index 4a987451..2722283a 100644 --- a/wire/core/FieldtypeMulti.php +++ b/wire/core/FieldtypeMulti.php @@ -479,9 +479,15 @@ abstract class FieldtypeMulti extends Fieldtype { foreach($filters as $selector) { // @todo add support for OR values of $col or $value - $col = $sanitizer->fieldName($selector->field); + $col = $selector->field; $op = $selector->operator; $value = $selector->value; + + if(is_array($col)) { + foreach($col as $k => $v) $col[$k] = $sanitizer->fieldName($v); + } else { + $col = $sanitizer->fieldName($col); + } if($col === 'sort') { $desc = strpos($value, '-') === 0 ? '-' : '';