Skip to content

Commit

Permalink
Merge pull request #22598 from colemanw/searchKitExtract
Browse files Browse the repository at this point in the history
[REF] SearchKit - Function extraction
  • Loading branch information
seamuslee001 authored Jan 22, 2022
2 parents 41e929f + 1bd440f commit bcc256e
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,8 @@ public function _run(\Civi\Api4\Generic\Result $result) {
throw new UnauthorizedException('Access denied');
}
$this->loadSavedSearch();
if (is_string($this->display)) {
$this->display = SearchDisplay::get(FALSE)
->setSelect(['*', 'type:name'])
->addWhere('name', '=', $this->display)
->addWhere('saved_search_id', '=', $this->savedSearch['id'])
->execute()->single();
}
elseif (is_null($this->display)) {
$this->display = SearchDisplay::getDefault(FALSE)
->addSelect('*', 'type:name')
->setSavedSearch($this->savedSearch)
->execute()->first();
}
$this->loadSearchDisplay();

// Displays with acl_bypass must be embedded on an afform which the user has access to
if (
$this->checkPermissions && !empty($this->display['acl_bypass']) &&
Expand Down Expand Up @@ -1029,4 +1018,25 @@ private function addFilterLabel($fieldName, $value) {
}
}

/**
* Loads display if not already an array
*/
private function loadSearchDisplay(): void {
// Display name given
if (is_string($this->display)) {
$this->display = SearchDisplay::get(FALSE)
->setSelect(['*', 'type:name'])
->addWhere('name', '=', $this->display)
->addWhere('saved_search_id', '=', $this->savedSearch['id'])
->execute()->single();
}
// Null given - use default display
elseif (is_null($this->display)) {
$this->display = SearchDisplay::getDefault(FALSE)
->addSelect('*', 'type:name')
->setSavedSearch($this->savedSearch)
->execute()->first();
}
}

}

0 comments on commit bcc256e

Please sign in to comment.