mirror of
https://codeberg.org/artfulrobot/contactcats.git
synced 2025-06-25 16:18:05 +02:00
respect withLabels
This commit is contained in:
parent
0b625bcba0
commit
c2546732b5
1 changed files with 43 additions and 33 deletions
|
@ -18,10 +18,18 @@ class Get extends DAOGetAction {
|
|||
/**
|
||||
*/
|
||||
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);
|
||||
|
||||
if ($this->withLabels) {
|
||||
$groupIDs = $searchIDs = [];
|
||||
foreach ($result as $idx => $row) {
|
||||
foreach ($result as $row) {
|
||||
if ($row['search_type'] === 'group') {
|
||||
$groupIDs[] = $row['search_data']['group_id'] ?? NULL;
|
||||
}
|
||||
|
@ -31,6 +39,7 @@ class Get extends DAOGetAction {
|
|||
}
|
||||
$groupIDs = array_filter($groupIDs);
|
||||
$searchIDs = array_filter($searchIDs);
|
||||
$groupNames = $searchNames = [];
|
||||
if ($groupIDs) {
|
||||
$groupNames = Group::get()
|
||||
->addWhere('id', 'IN', $groupIDs)
|
||||
|
@ -44,7 +53,7 @@ class Get extends DAOGetAction {
|
|||
->execute()->indexBy('id')->column('label');
|
||||
}
|
||||
if ($searchNames || $groupNames) {
|
||||
foreach ($result as $row) {
|
||||
foreach ($result as $idx => $row) {
|
||||
if ($row['search_type'] === 'group'
|
||||
&& !empty($groupNames[$row['search_data']['group_id'] ?? ''])
|
||||
) {
|
||||
|
@ -55,9 +64,10 @@ class Get extends DAOGetAction {
|
|||
) {
|
||||
$row['search_source'] = $searchNames[$row['search_data']['saved_search_id'] ?? ''];
|
||||
}
|
||||
}
|
||||
}
|
||||
$result[$idx] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue