mirror of
https://github.com/processwire/processwire.git
synced 2025-08-16 03:34:33 +02:00
Update DatabaseQuerySelectFulltext class to support multiple (array-based) field names when used outside PageFinder context. This enables use of field1|field2|field3*=value selectors in some places that didn't previously support it, like $page->page_ref_field_name('selector');
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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 ? '-' : '';
|
||||
|
Reference in New Issue
Block a user