mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
feat : mensajes internos module
This commit is contained in:
@ -53,13 +53,17 @@ class ChatDeparmentModel extends Model
|
||||
public function getChatDepartments(string $type = "general"): array
|
||||
{
|
||||
$userModel = model(UserModel::class);
|
||||
$chatMessageModel = model(ChatMessageModel::class);
|
||||
|
||||
$query = $this->db->table('chat_departments')
|
||||
->select(
|
||||
[
|
||||
|
||||
'chat_departments.id',
|
||||
'chat_departments.name',
|
||||
'chat_departments.display',
|
||||
'chat_department_users.user_id',
|
||||
'chats.id as chatId',
|
||||
]
|
||||
)
|
||||
->join(
|
||||
@ -67,22 +71,28 @@ class ChatDeparmentModel extends Model
|
||||
"chat_department_users.chat_department_id = chat_departments.id",
|
||||
'left'
|
||||
)
|
||||
->join("chats", "chats.chat_department_id = chat_departments.id", "left")
|
||||
->join(
|
||||
"users",
|
||||
"chat_department_users.user_id = users.id",
|
||||
'left'
|
||||
)->where("chat_departments.type",$type);
|
||||
if(auth()->user()->cliente_id == null){
|
||||
$query->where("chat_department_users.user_id",auth()->user()->id);
|
||||
}
|
||||
|
||||
)->join(
|
||||
"chat_messages",
|
||||
"chat_messages.chat_id = chats.id",
|
||||
"left"
|
||||
)
|
||||
->where("chat_departments.type", $type);
|
||||
if (auth()->user()->cliente_id == null) {
|
||||
$query->where("chat_department_users.user_id", auth()->user()->id);
|
||||
}
|
||||
|
||||
$results = $query->get()->getResultArray();
|
||||
// Create the desired structure
|
||||
$departments = [];
|
||||
|
||||
foreach ($results as $row) {
|
||||
$departmentName = $row['name'];
|
||||
|
||||
|
||||
// If the department is not yet added to the array, initialize it
|
||||
if (!isset($departments[$departmentName])) {
|
||||
$departments[$departmentName] = [
|
||||
@ -117,9 +127,8 @@ class ChatDeparmentModel extends Model
|
||||
"users",
|
||||
"chat_department_users.user_id = users.id",
|
||||
'left'
|
||||
)->where("chat_departments.id",$chat_deparment_id)
|
||||
)->where("chat_departments.id", $chat_deparment_id)
|
||||
->get()->getResultObject();
|
||||
return $result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user