Fix models database calls and structural updates

This commit is contained in:
Hamza-Ayed
2026-05-21 18:42:33 +03:00
parent 92755472e1
commit 3c695e88fd
5 changed files with 43 additions and 43 deletions

View File

@@ -8,20 +8,20 @@ namespace App\Models;
*/
class ContactGroup extends BaseModel
{
protected string $table = 'contact_groups';
protected static string $table = 'contact_groups';
/**
* Attach a contact to this group
*/
public function attachContact(int $groupId, int $contactId)
public static function attachContact(int $groupId, int $contactId)
{
$exists = $this->db->query(
$exists = \App\Core\Database::selectOne(
"SELECT 1 FROM contact_group_relations WHERE group_id = ? AND contact_id = ?",
[$groupId, $contactId]
)->fetch();
);
if (!$exists) {
$this->db->query(
\App\Core\Database::execute(
"INSERT INTO contact_group_relations (group_id, contact_id) VALUES (?, ?)",
[$groupId, $contactId]
);
@@ -32,9 +32,9 @@ class ContactGroup extends BaseModel
/**
* Remove a contact from this group
*/
public function detachContact(int $groupId, int $contactId)
public static function detachContact(int $groupId, int $contactId)
{
$this->db->query(
\App\Core\Database::execute(
"DELETE FROM contact_group_relations WHERE group_id = ? AND contact_id = ?",
[$groupId, $contactId]
);
@@ -44,13 +44,13 @@ class ContactGroup extends BaseModel
/**
* Get all raw contact records for a group (Decryption needed after fetch)
*/
public function getRawContacts(int $groupId)
public static function getRawContacts(int $groupId)
{
return $this->db->query(
return \App\Core\Database::select(
"SELECT c.* FROM contacts c
JOIN contact_group_relations cgr ON c.id = cgr.contact_id
WHERE cgr.group_id = ?",
[$groupId]
)->fetchAll();
);
}
}