Skip to content

Commit

Permalink
Dev: Support for options find action
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanJard committed Nov 21, 2024
1 parent 31aa0f8 commit 1aa5805
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
15 changes: 10 additions & 5 deletions Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,7 @@ private function _options($refresh)
*/
private function _optionsSearch($http)
{
$values = null;
$field = $this->_find_field($http['field'], 'name');

if (!$field) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 20 additions & 3 deletions Editor/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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]);
}
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 1aa5805

Please sign in to comment.