Skip to content

Commit

Permalink
ContactGroupForm: Add missing filter and simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jul 4, 2024
1 parent 195ca73 commit d95758b
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions application/forms/ContactGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,31 +252,29 @@ public function editGroup(): void
->columns(['contact_id'])
->where([
'contactgroup_id = ?' => $this->contactgroupId,
'deleted = ?' => 'y',
'contact_id IN (?)' => $toAdd
])
);

$removeDeletedFlagFromIds = [];
$toAdd = array_diff($toAdd, $contactsMarkedAsDeleted);
foreach ($toAdd as $contactId) {
if (in_array($contactId, $contactsMarkedAsDeleted)) {
$removeDeletedFlagFromIds[] = $contactId;
} else {
$this->db->insert(
'contactgroup_member',
[
'contactgroup_id' => $this->contactgroupId,
'contact_id' => $contactId
]
);
}
$this->db->insert(
'contactgroup_member',
[
'contactgroup_id' => $this->contactgroupId,
'contact_id' => $contactId
]
);
}
if (! empty($removeDeletedFlagFromIds)) {

if (! empty($contactsMarkedAsDeleted)) {
$this->db->update(
'contactgroup_member',
['changed_at' => $changedAt, 'deleted' => 'n'],
[
'contactgroup_id = ?' => $this->contactgroupId,
'contact_id IN (?)' => $removeDeletedFlagFromIds
'contact_id IN (?)' => $contactsMarkedAsDeleted
]
);
}
Expand Down

0 comments on commit d95758b

Please sign in to comment.