Deploy: 2026-05-21 15:33:14
This commit is contained in:
56
backend/app/Models/ContactGroup.php
Normal file
56
backend/app/Models/ContactGroup.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* ContactGroup Model
|
||||
* Manages groupings/lists of contacts for broadcast campaigns.
|
||||
*/
|
||||
class ContactGroup extends BaseModel
|
||||
{
|
||||
protected string $table = 'contact_groups';
|
||||
|
||||
/**
|
||||
* Attach a contact to this group
|
||||
*/
|
||||
public function attachContact(int $groupId, int $contactId)
|
||||
{
|
||||
$exists = $this->db->query(
|
||||
"SELECT 1 FROM contact_group_relations WHERE group_id = ? AND contact_id = ?",
|
||||
[$groupId, $contactId]
|
||||
)->fetch();
|
||||
|
||||
if (!$exists) {
|
||||
$this->db->query(
|
||||
"INSERT INTO contact_group_relations (group_id, contact_id) VALUES (?, ?)",
|
||||
[$groupId, $contactId]
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a contact from this group
|
||||
*/
|
||||
public function detachContact(int $groupId, int $contactId)
|
||||
{
|
||||
$this->db->query(
|
||||
"DELETE FROM contact_group_relations WHERE group_id = ? AND contact_id = ?",
|
||||
[$groupId, $contactId]
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all raw contact records for a group (Decryption needed after fetch)
|
||||
*/
|
||||
public function getRawContacts(int $groupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
"SELECT c.* FROM contacts c
|
||||
JOIN contact_group_relations cgr ON c.id = cgr.contact_id
|
||||
WHERE cgr.group_id = ?",
|
||||
[$groupId]
|
||||
)->fetchAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user