add client to chat

This commit is contained in:
amazuecos
2025-03-17 06:50:35 +01:00
parent 55157d23aa
commit 3662613ba5
7 changed files with 248 additions and 108 deletions

View File

@ -89,7 +89,7 @@ class ChatDeparmentModel extends Model
$departmentName = $row['name'];
// If the department is not yet added to the array, initialize it
if (!isset($departments[$departmentName])) {
$departments[$departmentName] = [
'id' => $row['id'],
'name' => $row['name'],
@ -105,9 +105,10 @@ class ChatDeparmentModel extends Model
}
return $departments;
}
public function getChatDepartmentUsers(int $chat_deparment_id)
public function getChatDeparmentUserQuery(int $chat_deparment_id)
{
$result = $this->builder()
$query = $this->builder()
->select(
[
"users.*"
@ -123,12 +124,42 @@ class ChatDeparmentModel extends Model
"chat_department_users.user_id = users.id",
'left'
)->where("chat_departments.id", $chat_deparment_id)
->where("chat_department_users.deleted_at",null)
->where("users.deleted_at",null)
->where("chat_department_users.deleted_at", null)
->where("users.deleted_at", null);
return $query;
}
public function getChatDepartmentUsers(int $chat_deparment_id)
{
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
->where('chat_department_users.presupuesto_id', null)
->where('chat_department_users.pedido_id', null)
->where('chat_department_users.factura_id', null)
->get()->getResultObject();
return $result;
}
public function getDisplay(int $chat_deparment_id) : string
public function getChatDeparmentPresupuestoUsers(int $chat_deparment_id, int $presupuesto_id)
{
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
->where('chat_department_users.presupuesto_id', $presupuesto_id)
->get()->getResultObject();
return $result;
}
public function getChatDeparmentPedidoUsers(int $chat_deparment_id, int $pedido_id)
{
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
->where('chat_department_users.pedido_id', $pedido_id)
->get()->getResultObject();
return $result;
}
public function getChatDeparmentFacturaUsers(int $chat_deparment_id, int $factura_id)
{
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
->where('chat_department_users.factura_id', $factura_id)
->get()->getResultObject();
return $result;
}
public function getDisplay(int $chat_deparment_id): string
{
return $this->find($chat_deparment_id)->display;
}
@ -139,9 +170,9 @@ class ChatDeparmentModel extends Model
"display as name",
"description"
]);
if($query){
$q->orLike("display",$query)
->orLike("name",$query);
if ($query) {
$q->orLike("display", $query)
->orLike("name", $query);
}
return $q;
}