mirror of
https://codeberg.org/artfulrobot/contactcats.git
synced 2025-06-25 19:38:05 +02:00
respect withLabels
This commit is contained in:
parent
0b625bcba0
commit
c2546732b5
1 changed files with 43 additions and 33 deletions
|
@ -18,46 +18,56 @@ class Get extends DAOGetAction {
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public function _run(Result $result) {
|
public function _run(Result $result) {
|
||||||
|
if ($this->withLabels) {
|
||||||
|
// Ensure we have search_type.
|
||||||
|
if ($this->select && !in_array('search_type', $this->select)) {
|
||||||
|
$this->addSelect('search_type');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
parent::_run($result);
|
parent::_run($result);
|
||||||
|
|
||||||
$groupIDs = $searchIDs = [];
|
if ($this->withLabels) {
|
||||||
foreach ($result as $idx => $row) {
|
$groupIDs = $searchIDs = [];
|
||||||
if ($row['search_type'] === 'group') {
|
|
||||||
$groupIDs[] = $row['search_data']['group_id'] ?? NULL;
|
|
||||||
}
|
|
||||||
elseif ($row['search_type'] === 'search') {
|
|
||||||
$searchIDs[] = $row['search_data']['saved_search_id'] ?? NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$groupIDs = array_filter($groupIDs);
|
|
||||||
$searchIDs = array_filter($searchIDs);
|
|
||||||
if ($groupIDs) {
|
|
||||||
$groupNames = Group::get()
|
|
||||||
->addWhere('id', 'IN', $groupIDs)
|
|
||||||
->addSelect('title')
|
|
||||||
->execute()->indexBy('id')->column('title');
|
|
||||||
}
|
|
||||||
if ($searchIDs) {
|
|
||||||
$searchNames = SavedSearch::get()
|
|
||||||
->addWhere('id', 'IN', $searchIDs)
|
|
||||||
->addSelect('label')
|
|
||||||
->execute()->indexBy('id')->column('label');
|
|
||||||
}
|
|
||||||
if ($searchNames || $groupNames) {
|
|
||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
if ($row['search_type'] === 'group'
|
if ($row['search_type'] === 'group') {
|
||||||
&& !empty($groupNames[$row['search_data']['group_id'] ?? ''])
|
$groupIDs[] = $row['search_data']['group_id'] ?? NULL;
|
||||||
) {
|
|
||||||
$row['search_source'] = $groupNames[$row['search_data']['group_id'] ?? ''];
|
|
||||||
}
|
}
|
||||||
elseif (($row['search_type'] === 'search')
|
elseif ($row['search_type'] === 'search') {
|
||||||
&& !empty($searchNames[$row['search_data']['saved_search_id'] ?? ''])
|
$searchIDs[] = $row['search_data']['saved_search_id'] ?? NULL;
|
||||||
) {
|
}
|
||||||
$row['search_source'] = $searchNames[$row['search_data']['saved_search_id'] ?? ''];
|
}
|
||||||
|
$groupIDs = array_filter($groupIDs);
|
||||||
|
$searchIDs = array_filter($searchIDs);
|
||||||
|
$groupNames = $searchNames = [];
|
||||||
|
if ($groupIDs) {
|
||||||
|
$groupNames = Group::get()
|
||||||
|
->addWhere('id', 'IN', $groupIDs)
|
||||||
|
->addSelect('title')
|
||||||
|
->execute()->indexBy('id')->column('title');
|
||||||
|
}
|
||||||
|
if ($searchIDs) {
|
||||||
|
$searchNames = SavedSearch::get()
|
||||||
|
->addWhere('id', 'IN', $searchIDs)
|
||||||
|
->addSelect('label')
|
||||||
|
->execute()->indexBy('id')->column('label');
|
||||||
|
}
|
||||||
|
if ($searchNames || $groupNames) {
|
||||||
|
foreach ($result as $idx => $row) {
|
||||||
|
if ($row['search_type'] === 'group'
|
||||||
|
&& !empty($groupNames[$row['search_data']['group_id'] ?? ''])
|
||||||
|
) {
|
||||||
|
$row['search_source'] = $groupNames[$row['search_data']['group_id'] ?? ''];
|
||||||
|
}
|
||||||
|
elseif (($row['search_type'] === 'search')
|
||||||
|
&& !empty($searchNames[$row['search_data']['saved_search_id'] ?? ''])
|
||||||
|
) {
|
||||||
|
$row['search_source'] = $searchNames[$row['search_data']['saved_search_id'] ?? ''];
|
||||||
|
}
|
||||||
|
$result[$idx] = $row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result[$idx] = $row;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue