diff --git a/wire/core/PageFinder.php b/wire/core/PageFinder.php index f91fbbf1..5db3b7a7 100644 --- a/wire/core/PageFinder.php +++ b/wire/core/PageFinder.php @@ -610,6 +610,7 @@ class PageFinder extends Wire { $o['getTotal'] = true; $o['loadPages'] = false; $o['returnVerbose'] = false; + /** @var Selectors $sel */ $sel = clone $selectors; foreach($sel as $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 = $database->escapeTable($tableAlias); - $valueArray = is_array($selector->value) ? $selector->value : array($selector->value); + $valueArray = $selector->values(true); $join = ''; $fieldtype = $field->type; $operator = $selector->operator; @@ -1765,8 +1766,7 @@ class PageFinder extends Wire { */ protected function getQueryNativeField(DatabaseQuerySelect $query, $selector, $fields) { - $value = $selector->value; - $values = is_array($value) ? $value : array($value); + $values = $selector->values(true); $SQL = ''; $database = $this->wire('database'); @@ -1806,7 +1806,7 @@ class PageFinder extends Wire { } $field = 'parent_id'; - if(count($values) == 1 && $selector->getOperator() === '=') { + if(count($values) == 1 && $selector->operator() === '=') { $this->parent_id = reset($values); } @@ -1855,7 +1855,7 @@ class PageFinder extends Wire { // convert templates specified as a name to the numeric template ID // allows selectors like 'template=my_template_name' $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); } diff --git a/wire/core/Selector.php b/wire/core/Selector.php index 051b6c5e..8dbf8090 100644 --- a/wire/core/Selector.php +++ b/wire/core/Selector.php @@ -108,7 +108,7 @@ abstract class Selector extends WireData { * */ 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 * + * @param bool $nonEmpty If empty array will be returned, forces it to return array with one blank item instead (default=false). * @return array * @see Selector::value() * @since 3.0.42 Prior versions just supported the 'values' property. * */ - public function values() { + public function values($nonEmpty = false) { $values = parent::get('value'); - if(is_array($values)) return $values; - if(!is_object($values) && !strlen($values)) return array(); - return array($values); + if(is_array($values)) { + // ok + } 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) { - if($key == 'operator') return $this->getOperator(); + if($key == 'operator') return $this->operator(); if($key == 'str') return $this->__toString(); if($key == 'values') return $this->values(); if($key == 'fields') return $this->fields(); @@ -259,7 +277,7 @@ abstract class Selector extends WireData { * * @param string $key * @param mixed $value - * @return $this + * @return Selector|WireData * */ public function set($key, $value) { @@ -314,7 +332,7 @@ abstract class Selector extends WireData { $matches = false; $values1 = is_array($this->value) ? $this->value : array($this->value); $field = $this->field; - $operator = $this->getOperator(); + $operator = $this->operator(); // prepare the value we are comparing if(is_object($value)) { @@ -402,7 +420,7 @@ abstract class Selector extends WireData { $str = ($this->not ? '!' : '') . (is_null($this->group) ? '' : $this->group . '@') . (is_array($this->field) ? implode('|', $this->field) : $this->field) . - $this->getOperator() . + $this->operator() . (is_array($this->value) ? implode("|", $this->value) : $openingQuote . $this->value . $closingQuote); return $str; }