From 6f4a76d74e1ab3159eb005504b165dfe18ba4a31 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 14 Aug 2020 15:18:05 -0400 Subject: [PATCH] Minor updates, plus update the inputfields.js triggered events (openReady, opened, closeReady, closed) to include the Inputfield element in the event arguments for simpler access to it vs the event.target. --- wire/core/WireData.php | 4 +-- wire/core/WireSaveableItems.php | 35 ++++++++++++------- .../InputfieldDatetime.module | 1 + wire/templates-admin/scripts/inputfields.js | 8 ++--- .../scripts/inputfields.min.js | 2 +- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/wire/core/WireData.php b/wire/core/WireData.php index c2198382..a3121846 100644 --- a/wire/core/WireData.php +++ b/wire/core/WireData.php @@ -211,7 +211,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess { * - `$this` - If you are setting a value. */ public function data($key = null, $value = null) { - if(is_null($key)) return $this->data; + if($key === null) return $this->data; if(is_array($key)) { if($value === true) { $this->data = $key; @@ -219,7 +219,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess { $this->data = array_merge($this->data, $key); } return $this; - } else if(is_null($value)) { + } else if($value === null) { return isset($this->data[$key]) ? $this->data[$key] : null; } else { $this->data[$key] = $value; diff --git a/wire/core/WireSaveableItems.php b/wire/core/WireSaveableItems.php index 79a14518..f44ea2a5 100644 --- a/wire/core/WireSaveableItems.php +++ b/wire/core/WireSaveableItems.php @@ -105,37 +105,48 @@ abstract class WireSaveableItems extends Wire implements \IteratorAggregate { // nothing provided, load all assumed return $query; } + + // Note: ProcessWire core does not appear to ever reach this point as the + // core does not use selectors to load any of its WireSaveableItems $functionFields = array( 'sort' => '', 'limit' => '', 'start' => '', - ); + ); $item = $this->makeBlankItem(); $fields = array_keys($item->getTableData()); foreach($selectors as $selector) { - if(!$database->isOperator($selector->operator)) - throw new WireException("Operator '{$selector->operator}' may not be used in {$this->className}::load()"); - - if(in_array($selector->field, $functionFields)) { - $functionFields[$selector->field] = $selector->value; - continue; + if(!$database->isOperator($selector->operator)) { + throw new WireException("Operator '$selector->operator' may not be used in {$this->className}::load()"); + } + + if(isset($functionFields[$selector->field])) { + $functionFields[$selector->field] = $selector->value; + continue; } if(!in_array($selector->field, $fields)) { - throw new WireException("Field '{$selector->field}' is not valid for {$this->className}::load()"); + throw new WireException("Field '$selector->field' is not valid for {$this->className}::load()"); } $selectorField = $database->escapeTableCol($selector->field); - $value = $database->escapeStr($selector->value); - $query->where("{$selectorField}{$selector->operator}'$value'"); // QA + $query->where("$selectorField$selector->operator?", $selector->value); // QA } - if($functionFields['sort'] && in_array($functionFields['sort'], $fields)) $query->orderby("$functionFields[sort]"); - if($functionFields['limit']) $query->limit(($functionFields['start'] ? ((int) $functionFields['start']) . "," : '') . $functionFields['limit']); + $sort = $functionFields['sort']; + if($sort && in_array($sort, $fields)) { + $query->orderby($database->escapeCol($sort)); + } + + $limit = (int) $functionFields['limit']; + if($limit) { + $start = $functionFields['start']; + $query->limit(($start ? ((int) $start) . ',' : '') . $limit); + } return $query; diff --git a/wire/modules/Inputfield/InputfieldDatetime/InputfieldDatetime.module b/wire/modules/Inputfield/InputfieldDatetime/InputfieldDatetime.module index c3f6b55f..55ce2a7d 100644 --- a/wire/modules/Inputfield/InputfieldDatetime/InputfieldDatetime.module +++ b/wire/modules/Inputfield/InputfieldDatetime/InputfieldDatetime.module @@ -51,6 +51,7 @@ * @property int $timeInputSelect jQuery UI timeSelect type (requires datepicker)—specify 1 to use a `