mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
fix : mensajes internos, arreglar total numero mensajes
This commit is contained in:
@ -55,7 +55,7 @@ class ChatDeparmentModel extends Model
|
||||
$userModel = model(UserModel::class);
|
||||
$chatMessageModel = model(ChatMessageModel::class);
|
||||
|
||||
$query = $this->db->table('chat_departments')
|
||||
$query = $this->builder()
|
||||
->select(
|
||||
[
|
||||
|
||||
@ -82,6 +82,7 @@ class ChatDeparmentModel extends Model
|
||||
"left"
|
||||
)
|
||||
->where("chat_departments.type", $type);
|
||||
|
||||
// if (auth()->user()->cliente_id == null) {
|
||||
// $query->where("chat_department_users.user_id", auth()->user()->id);
|
||||
// }
|
||||
@ -89,16 +90,22 @@ class ChatDeparmentModel extends Model
|
||||
$results = $query->get()->getResultArray();
|
||||
// Create the desired structure
|
||||
$departments = [];
|
||||
|
||||
foreach ($results as $row) {
|
||||
$departmentName = $row['name'];
|
||||
$totalMessages = 0;
|
||||
|
||||
// If the department is not yet added to the array, initialize it
|
||||
if (!isset($departments[$departmentName])) {
|
||||
if($row['chatId']){
|
||||
$data["messages"] = $chatMessageModel->get_chat_messages($row['chatId']);
|
||||
$totalMessages = count($data["messages"]);
|
||||
|
||||
}
|
||||
$departments[$departmentName] = [
|
||||
'id' => $row['id'],
|
||||
'name' => $row['name'],
|
||||
'display' => $row['display'],
|
||||
'totalMessages' => $totalMessages,
|
||||
'users' => [] // Initialize users as an empty array
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user