mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
fix uri chat notifications
This commit is contained in:
@ -321,65 +321,73 @@ class ChatModel extends Model
|
||||
$facturaModel = model(FacturaModel::class);
|
||||
$pedidoModel = model(PedidoModel::class);
|
||||
|
||||
$q = $this->db->table("chats")
|
||||
$q = $this->builder()
|
||||
->select([
|
||||
"chats.id as chatId",
|
||||
"chats.chat_department_id as chatDepartmentId",
|
||||
"chats.pedido_id as pedidoId",
|
||||
"chats.presupuesto_id as presupuestoId",
|
||||
"chats.factura_id as facturaId",
|
||||
"chats.chat_department_id as chatDepartmentId",
|
||||
"chat_departments.display as chatDisplay",
|
||||
"chats.title as chatDisplay",
|
||||
])
|
||||
->join("chat_departments", "chat_departments.id = chats.chat_department_id", "left")
|
||||
->join("chat_department_users", "chat_department_users.chat_department_id = chats.chat_department_id", "left")
|
||||
->where("chat_department_users.user_id", auth()->user()->id);
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||
->where("chat_notifications.user_id", auth()->user()->id)
|
||||
->where("chat_notifications.viewed", false)
|
||||
->where("chats.chat_department_id is NOT NULL",NULL,FALSE);
|
||||
|
||||
$rows = $q->get()->getResultObject();
|
||||
$auth_user = auth()->user();
|
||||
$rows_new = [];
|
||||
foreach ($rows as $row) {
|
||||
$messages = $chatMessageModel->get_chat_messages($row->chatId);
|
||||
$count = 0;
|
||||
$chatDeparmentUsers = $chatDeparmentModel->getChatDepartmentUsers($row->chatDepartmentId);
|
||||
$chatDeparmentUsersId = array_map(fn($x) => $x->id, $chatDeparmentUsers);
|
||||
foreach ($messages as $m) {
|
||||
if ($m->viewed == false && $m->sender_id != auth()->user()->id && in_array($m->sender_id, $chatDeparmentUsersId) == false)
|
||||
$count++;
|
||||
}
|
||||
$row->unreadMessages = 0;
|
||||
if ($row->presupuestoId) {
|
||||
$row->model = $presupuestoModel->find($row->presupuestoId);
|
||||
if($auth_user->cliente_id){
|
||||
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||
}else{
|
||||
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||
|
||||
}
|
||||
$row->title = $row->presupuestoId;
|
||||
if($row->chatDepartmentId){
|
||||
$row->chatDisplay = $row->model->titulo;
|
||||
}else{
|
||||
$row->chatDisplay .="[INTERNAL]";
|
||||
}
|
||||
$row->avatar = "PRE";
|
||||
$row->unreadMessages = $count;
|
||||
$row->unreadMessages = $this->countUnreadMessagePresupuesto($row->presupuestoId);
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->pedidoId) {
|
||||
$row->model = $pedidoModel->find($row->pedidoId);
|
||||
$row->uri = "/chat/pedido/" . $row->chatId;
|
||||
$row->title = $row->pedidoId;
|
||||
if($row->chatDepartmentId){
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
}
|
||||
$row->avatar = "P";
|
||||
$row->unreadMessages = $count;
|
||||
$row->unreadMessages = $this->countUnreadMessagePedido($row->pedidoId);
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->facturaId) {
|
||||
$row->model = $facturaModel->find($row->facturaId);
|
||||
$row->uri = "/chat/factura/" . $row->chatId;
|
||||
$row->avatar = "F";
|
||||
if($row->chatDepartmentId){
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
}
|
||||
$row->title = $row->facturaId;
|
||||
$row->unreadMessages = $count;
|
||||
$row->unreadMessages = $this->countUnreadMessageFactura($row->facturaId);
|
||||
$rows_new[] = $row;
|
||||
}
|
||||
}
|
||||
return $rows;
|
||||
return $rows_new;
|
||||
}
|
||||
public function getChatInternalNotifications()
|
||||
{
|
||||
$chatMessageModel = model(ChatMessageModel::class);
|
||||
$presupuestoModel = model(PresupuestoModel::class);
|
||||
$facturaModel = model(FacturaModel::class);
|
||||
$pedidoModel = model(PedidoModel::class);
|
||||
$chatNotificationModel = model(ChatNotification::class);
|
||||
|
||||
$q = $this->db->table("chats")
|
||||
$q = $this->builder()
|
||||
->select([
|
||||
"chats.id as chatId",
|
||||
"chats.chat_department_id as chatDepartmentId",
|
||||
@ -401,9 +409,9 @@ class ChatModel extends Model
|
||||
if ($row->presupuestoId) {
|
||||
$row->model = $presupuestoModel->find($row->presupuestoId);
|
||||
if($auth_user->cliente_id){
|
||||
$row->uri = "/presupuestocliente/edit/" . $row->presupuestoId;
|
||||
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||
}else{
|
||||
$row->uri = "/presupuestoadmin/edit/" . $row->presupuestoId;
|
||||
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||
}
|
||||
$row->title = $row->presupuestoId;
|
||||
if($row->chatDepartmentId){
|
||||
@ -416,7 +424,7 @@ class ChatModel extends Model
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->pedidoId) {
|
||||
$row->model = $pedidoModel->find($row->pedidoId);
|
||||
$row->uri = "/pedidos/edit/" . $row->pedidoId;
|
||||
$row->uri = "/chat/pedido/" . $row->chatId;
|
||||
$row->title = $row->pedidoId;
|
||||
if($row->chatDepartmentId){
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
@ -426,7 +434,7 @@ class ChatModel extends Model
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->facturaId) {
|
||||
$row->model = $facturaModel->find($row->facturaId);
|
||||
$row->uri = "/facturas/edit/" . $row->facturaId;
|
||||
$row->uri = "/chat/factura/" . $row->chatId;
|
||||
$row->avatar = "F";
|
||||
if($row->chatDepartmentId){
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
|
||||
Reference in New Issue
Block a user