mirror of
https://github.com/processwire/processwire.git
synced 2025-08-13 18:24:57 +02:00
Fix issue processwire/processwire-issues#354 where a.b.c='' selector was not working right
This commit is contained in:
@@ -610,6 +610,7 @@ class PageFinder extends Wire {
|
|||||||
$o['getTotal'] = true;
|
$o['getTotal'] = true;
|
||||||
$o['loadPages'] = false;
|
$o['loadPages'] = false;
|
||||||
$o['returnVerbose'] = false;
|
$o['returnVerbose'] = false;
|
||||||
|
/** @var Selectors $sel */
|
||||||
$sel = clone $selectors;
|
$sel = clone $selectors;
|
||||||
foreach($sel as $s) {
|
foreach($sel as $s) {
|
||||||
if($s->field == 'limit' || $s->field == 'start') $sel->remove($s);
|
if($s->field == 'limit' || $s->field == 'start') $sel->remove($s);
|
||||||
@@ -1023,7 +1024,7 @@ class PageFinder extends Wire {
|
|||||||
$tableAlias = $field->table . ($fieldCnt[$field->table] ? $fieldCnt[$field->table] : '');
|
$tableAlias = $field->table . ($fieldCnt[$field->table] ? $fieldCnt[$field->table] : '');
|
||||||
$tableAlias = $database->escapeTable($tableAlias);
|
$tableAlias = $database->escapeTable($tableAlias);
|
||||||
|
|
||||||
$valueArray = is_array($selector->value) ? $selector->value : array($selector->value);
|
$valueArray = $selector->values(true);
|
||||||
$join = '';
|
$join = '';
|
||||||
$fieldtype = $field->type;
|
$fieldtype = $field->type;
|
||||||
$operator = $selector->operator;
|
$operator = $selector->operator;
|
||||||
@@ -1765,8 +1766,7 @@ class PageFinder extends Wire {
|
|||||||
*/
|
*/
|
||||||
protected function getQueryNativeField(DatabaseQuerySelect $query, $selector, $fields) {
|
protected function getQueryNativeField(DatabaseQuerySelect $query, $selector, $fields) {
|
||||||
|
|
||||||
$value = $selector->value;
|
$values = $selector->values(true);
|
||||||
$values = is_array($value) ? $value : array($value);
|
|
||||||
$SQL = '';
|
$SQL = '';
|
||||||
$database = $this->wire('database');
|
$database = $this->wire('database');
|
||||||
|
|
||||||
@@ -1806,7 +1806,7 @@ class PageFinder extends Wire {
|
|||||||
}
|
}
|
||||||
$field = 'parent_id';
|
$field = 'parent_id';
|
||||||
|
|
||||||
if(count($values) == 1 && $selector->getOperator() === '=') {
|
if(count($values) == 1 && $selector->operator() === '=') {
|
||||||
$this->parent_id = reset($values);
|
$this->parent_id = reset($values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1855,7 +1855,7 @@ class PageFinder extends Wire {
|
|||||||
// convert templates specified as a name to the numeric template ID
|
// convert templates specified as a name to the numeric template ID
|
||||||
// allows selectors like 'template=my_template_name'
|
// allows selectors like 'template=my_template_name'
|
||||||
$field = 'templates_id';
|
$field = 'templates_id';
|
||||||
if(count($values) == 1 && $selector->getOperator() === '=') $this->templates_id = reset($values);
|
if(count($values) == 1 && $selector->operator() === '=') $this->templates_id = reset($values);
|
||||||
if(!ctype_digit("$value")) $value = (($template = $this->wire('templates')->get($value)) ? $template->id : 0);
|
if(!ctype_digit("$value")) $value = (($template = $this->wire('templates')->get($value)) ? $template->id : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -108,7 +108,7 @@ abstract class Selector extends WireData {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function operator() {
|
public function operator() {
|
||||||
return self::getOperator();
|
return static::getOperator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -181,20 +181,38 @@ abstract class Selector extends WireData {
|
|||||||
/**
|
/**
|
||||||
* Return array of value(s) for this Selector
|
* Return array of value(s) for this Selector
|
||||||
*
|
*
|
||||||
|
* @param bool $nonEmpty If empty array will be returned, forces it to return array with one blank item instead (default=false).
|
||||||
* @return array
|
* @return array
|
||||||
* @see Selector::value()
|
* @see Selector::value()
|
||||||
* @since 3.0.42 Prior versions just supported the 'values' property.
|
* @since 3.0.42 Prior versions just supported the 'values' property.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function values() {
|
public function values($nonEmpty = false) {
|
||||||
$values = parent::get('value');
|
$values = parent::get('value');
|
||||||
if(is_array($values)) return $values;
|
if(is_array($values)) {
|
||||||
if(!is_object($values) && !strlen($values)) return array();
|
// ok
|
||||||
return array($values);
|
} else if(is_string($values)) {
|
||||||
|
$values = strlen($values) ? array($values) : array();
|
||||||
|
} else if(is_object($values)) {
|
||||||
|
$values = $values instanceof WireArray ? $values->getArray() : array($values);
|
||||||
|
} else if($values) {
|
||||||
|
$values = array($values);
|
||||||
|
} else {
|
||||||
|
$values = array();
|
||||||
|
}
|
||||||
|
if($nonEmpty && !count($values)) $values = array('');
|
||||||
|
return $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a property
|
||||||
|
*
|
||||||
|
* @param string $key Property name
|
||||||
|
* @return array|mixed|null|string Property value
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function get($key) {
|
public function get($key) {
|
||||||
if($key == 'operator') return $this->getOperator();
|
if($key == 'operator') return $this->operator();
|
||||||
if($key == 'str') return $this->__toString();
|
if($key == 'str') return $this->__toString();
|
||||||
if($key == 'values') return $this->values();
|
if($key == 'values') return $this->values();
|
||||||
if($key == 'fields') return $this->fields();
|
if($key == 'fields') return $this->fields();
|
||||||
@@ -259,7 +277,7 @@ abstract class Selector extends WireData {
|
|||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return $this
|
* @return Selector|WireData
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function set($key, $value) {
|
public function set($key, $value) {
|
||||||
@@ -314,7 +332,7 @@ abstract class Selector extends WireData {
|
|||||||
$matches = false;
|
$matches = false;
|
||||||
$values1 = is_array($this->value) ? $this->value : array($this->value);
|
$values1 = is_array($this->value) ? $this->value : array($this->value);
|
||||||
$field = $this->field;
|
$field = $this->field;
|
||||||
$operator = $this->getOperator();
|
$operator = $this->operator();
|
||||||
|
|
||||||
// prepare the value we are comparing
|
// prepare the value we are comparing
|
||||||
if(is_object($value)) {
|
if(is_object($value)) {
|
||||||
@@ -402,7 +420,7 @@ abstract class Selector extends WireData {
|
|||||||
$str = ($this->not ? '!' : '') .
|
$str = ($this->not ? '!' : '') .
|
||||||
(is_null($this->group) ? '' : $this->group . '@') .
|
(is_null($this->group) ? '' : $this->group . '@') .
|
||||||
(is_array($this->field) ? implode('|', $this->field) : $this->field) .
|
(is_array($this->field) ? implode('|', $this->field) : $this->field) .
|
||||||
$this->getOperator() .
|
$this->operator() .
|
||||||
(is_array($this->value) ? implode("|", $this->value) : $openingQuote . $this->value . $closingQuote);
|
(is_array($this->value) ? implode("|", $this->value) : $openingQuote . $this->value . $closingQuote);
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user