Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] SearchKit - Function extraction #22598

Merged
merged 1 commit into from
Jan 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}

}