mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 09:14:58 +02:00
Update DatabaseQuerySelectFulltext class to suppor OR values when used outside of PageFinder (like when used directly from FieldtypeMulti)
This commit is contained in:
@@ -74,12 +74,14 @@ class DatabaseQuerySelectFulltext extends Wire {
|
||||
* @param string $tableName
|
||||
* @param string $fieldName
|
||||
* @param string $operator
|
||||
* @param string $value
|
||||
* @param string|int|array $value Value to match. Array value support added 3.0.141 (not used by PageFinder)
|
||||
* @return $this
|
||||
* @throws WireException If given $operator argument is not implemented here
|
||||
*
|
||||
*/
|
||||
public function match($tableName, $fieldName, $operator, $value) {
|
||||
|
||||
if(is_array($value)) return $this->matchArrayValue($tableName, $fieldName, $operator, $value);
|
||||
|
||||
$database = $this->wire('database');
|
||||
$query = $this->query;
|
||||
@@ -146,6 +148,37 @@ class DatabaseQuerySelectFulltext extends Wire {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match when given $value is an array
|
||||
*
|
||||
* Note: PageFinder uses its own array-to-value conversion, so this case applies only to other usages outside PageFinder,
|
||||
* such as FieldtypeMulti::getLoadQueryWhere()
|
||||
*
|
||||
* @param string $tableName
|
||||
* @param string $fieldName
|
||||
* @param string $operator
|
||||
* @param array $value
|
||||
* @return $this
|
||||
* @since 3.0.141
|
||||
* @throws WireException
|
||||
*
|
||||
*/
|
||||
protected function matchArrayValue($tableName, $fieldName, $operator, $value) {
|
||||
if($operator === '~=') {
|
||||
throw new WireException("Operator ~= is not supported for $fieldName with OR value condition");
|
||||
}
|
||||
// convert *= operator to %= to make the query possible (avoiding matchContains method)
|
||||
if($operator === '*=') $operator = '%=';
|
||||
$query = $this->query;
|
||||
$this->query = $this->wire(new DatabaseQuerySelect());
|
||||
foreach($value as $v) {
|
||||
$this->match($tableName, $fieldName, $operator, "$v");
|
||||
}
|
||||
$query->where(implode(" OR ", $this->query->where));
|
||||
$this->query = $query;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
* @param string $fieldName
|
||||
|
Reference in New Issue
Block a user