diff --git a/Editor.php b/Editor.php index 65eca39..e9aa048 100644 --- a/Editor.php +++ b/Editor.php @@ -2297,6 +2297,7 @@ private function _options($refresh) */ private function _optionsSearch($http) { + $values = null; $field = $this->_find_field($http['field'], 'name'); if (!$field) { @@ -2309,7 +2310,11 @@ private function _optionsSearch($http) return; } - $values = $options->search($this->db(), $http['search']); + if (isset($http['search'])) { + $values = $options->search($this->db(), $http['search']); + } elseif (isset($http['values'])) { + $values = $options->find($this->db(), $http['values']); + } if ($values) { $this->_out['data'] = $values; @@ -2441,16 +2446,16 @@ private function _alias($name, $type = 'alias') $a = preg_split('/ as /i', $name); return $type === 'alias' ? - $a[1] : - $a[0]; + $a[1] : + $a[0]; } if (stripos($name, ' ') !== false) { $a = preg_split('/ /i', $name); return $type === 'alias' ? - $a[1] : - $a[0]; + $a[1] : + $a[0]; } return $name; diff --git a/Editor/Options.php b/Editor/Options.php index 9c7a37d..39650de 100644 --- a/Editor/Options.php +++ b/Editor/Options.php @@ -309,10 +309,10 @@ public function where($_ = null) * * @internal */ - public function exec($db, $refresh, $search = null) + public function exec($db, $refresh, $search = null, $find = null) { // If search only, and not a search action, then just return false - if ($this->searchOnly() && $search === null) { + if ($this->searchOnly() && $search === null && $find === null) { return false; } @@ -357,6 +357,10 @@ public function exec($db, $refresh, $search = null) ->get($fields) ->where($this->_where); + if (is_array($find)) { + $q->where_in($value, $find); + } + if (is_string($this->_order)) { // For cases where we are ordering by a field which isn't included in the list // of fields to display, we need to add the ordering field, due to the @@ -375,7 +379,7 @@ public function exec($db, $refresh, $search = null) } $q->order($this->_order); - } else if ($this->_order === true) { + } elseif ($this->_order === true) { // Attempt to do a database order, needed for "limit()"ed results $q->order($this->_label[0]); } @@ -436,6 +440,19 @@ public function exec($db, $refresh, $search = null) return $out; } + /** + * Get the objects for a set of values. + * + * @param Database $db Database connection + * @param array $ids IDs to get + * + * @return array|bool + */ + public function find($db, $ids) + { + return $this->exec($db, false, null, $ids); + } + /** * Do a search for data on the source. *