mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
send email
This commit is contained in:
@ -28,7 +28,7 @@ class Email extends BaseConfig
|
|||||||
/**
|
/**
|
||||||
* SMTP Server Hostname
|
* SMTP Server Hostname
|
||||||
*/
|
*/
|
||||||
public string $SMTPHost = 'smtp.ionos.es';
|
public string $SMTPHost = 'localhost';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP Username
|
* SMTP Username
|
||||||
@ -38,7 +38,7 @@ class Email extends BaseConfig
|
|||||||
/**
|
/**
|
||||||
* SMTP Password
|
* SMTP Password
|
||||||
*/
|
*/
|
||||||
public string $SMTPPass = 'H%5&qDkDkWnfLTGN';
|
public string $SMTPPass = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP Port
|
* SMTP Port
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use App\Services\PapelImpresionService;
|
|||||||
use CodeIgniter\Config\BaseService;
|
use CodeIgniter\Config\BaseService;
|
||||||
use App\Services\ProductionService;
|
use App\Services\ProductionService;
|
||||||
use App\Services\TarifaMaquinaService;
|
use App\Services\TarifaMaquinaService;
|
||||||
|
use CodeIgniter\Email\Email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Services Configuration file.
|
* Services Configuration file.
|
||||||
@ -36,6 +37,7 @@ class Services extends BaseService
|
|||||||
* return new \CodeIgniter\Example();
|
* return new \CodeIgniter\Example();
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static function production(){
|
public static function production(){
|
||||||
return new ProductionService();
|
return new ProductionService();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,6 +60,8 @@ return [
|
|||||||
"subscribe_admin_chat_wrong" => "Tienes que seleccionar un usuario.",
|
"subscribe_admin_chat_wrong" => "Tienes que seleccionar un usuario.",
|
||||||
"help_select_chat_department_user" => "Solamente son listados los usuarios que pertenecen al personal. Los clientes no son listados, para añadirlos a la conversación se realiza desde la sección de mensajería de las diferentes secciones(presupuesto,pedido,factura ...)",
|
"help_select_chat_department_user" => "Solamente son listados los usuarios que pertenecen al personal. Los clientes no son listados, para añadirlos a la conversación se realiza desde la sección de mensajería de las diferentes secciones(presupuesto,pedido,factura ...)",
|
||||||
"store_department" => "Crear departamento",
|
"store_department" => "Crear departamento",
|
||||||
|
"mail" => [
|
||||||
|
"mail_subject" => "Nuevo mensaje"
|
||||||
|
]
|
||||||
|
|
||||||
];
|
];
|
||||||
@ -17,12 +17,13 @@ use App\Models\Configuracion\ConfigVariableModel;
|
|||||||
use App\Models\Presupuestos\PresupuestoModel;
|
use App\Models\Presupuestos\PresupuestoModel;
|
||||||
use App\Models\Usuarios\UserModel;
|
use App\Models\Usuarios\UserModel;
|
||||||
use CodeIgniter\Config\BaseService;
|
use CodeIgniter\Config\BaseService;
|
||||||
|
use CodeIgniter\Email\Email;
|
||||||
|
|
||||||
|
|
||||||
class ChatService extends BaseService
|
class ChatService extends BaseService
|
||||||
{
|
{
|
||||||
protected ?ChatEntity $chatEntity;
|
protected ?ChatEntity $chatEntity;
|
||||||
|
protected Email $emailService;
|
||||||
|
protected UserModel $userModel;
|
||||||
protected ChatModel $chatModel;
|
protected ChatModel $chatModel;
|
||||||
protected ChatMessageModel $chatMessageModel;
|
protected ChatMessageModel $chatMessageModel;
|
||||||
protected ChatUser $chatUserModel;
|
protected ChatUser $chatUserModel;
|
||||||
@ -39,6 +40,8 @@ class ChatService extends BaseService
|
|||||||
protected array $modelClassMap;
|
protected array $modelClassMap;
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$this->emailService = service('email');
|
||||||
|
$this->userModel = model(UserModel::class);
|
||||||
$this->chatModel = model(ChatModel::class);
|
$this->chatModel = model(ChatModel::class);
|
||||||
$this->chatMessageModel = model(ChatMessageModel::class);
|
$this->chatMessageModel = model(ChatMessageModel::class);
|
||||||
$this->chatNotificationModel = model(ChatNotification::class);
|
$this->chatNotificationModel = model(ChatNotification::class);
|
||||||
@ -87,6 +90,12 @@ class ChatService extends BaseService
|
|||||||
}
|
}
|
||||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $this->chatEntity->id, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $this->chatEntity->id, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||||
$chatMessageEntity = $this->chatMessageModel->find($chat_message_id);
|
$chatMessageEntity = $this->chatMessageModel->find($chat_message_id);
|
||||||
|
if ($data["client"]) {
|
||||||
|
$userClient = $this->userModel->find($data['client']);
|
||||||
|
if ($userClient) {
|
||||||
|
$this->sendMessageNotificationEmail($chatMessageEntity, $userClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
return $chatMessageEntity;
|
return $chatMessageEntity;
|
||||||
}
|
}
|
||||||
public function createChat(int $chatDepartmentId, string $model, int $modelId): bool|int|string
|
public function createChat(int $chatDepartmentId, string $model, int $modelId): bool|int|string
|
||||||
@ -112,9 +121,9 @@ class ChatService extends BaseService
|
|||||||
{
|
{
|
||||||
$chatDepartments = $this->chatDepartmentModel->getModelChatDepartments($this->modelFkMap[$model], $modelId);
|
$chatDepartments = $this->chatDepartmentModel->getModelChatDepartments($this->modelFkMap[$model], $modelId);
|
||||||
$departmentWithChat = array_map(fn($q) => $q["name"], $chatDepartments);
|
$departmentWithChat = array_map(fn($q) => $q["name"], $chatDepartments);
|
||||||
if(count($departmentWithChat) > 0){
|
if (count($departmentWithChat) > 0) {
|
||||||
$departmentWithoutChat = $this->chatDepartmentModel->whereNotIn('name', $departmentWithChat)->findAll();
|
$departmentWithoutChat = $this->chatDepartmentModel->whereNotIn('name', $departmentWithChat)->findAll();
|
||||||
}else{
|
} else {
|
||||||
$departmentWithoutChat = $this->chatDepartmentModel->findAll();
|
$departmentWithoutChat = $this->chatDepartmentModel->findAll();
|
||||||
}
|
}
|
||||||
foreach ($departmentWithoutChat as $value) {
|
foreach ($departmentWithoutChat as $value) {
|
||||||
@ -153,18 +162,18 @@ class ChatService extends BaseService
|
|||||||
->where($this->modelFkMap[$model], $modelId)
|
->where($this->modelFkMap[$model], $modelId)
|
||||||
->findAll();
|
->findAll();
|
||||||
foreach ($chats as $c) {
|
foreach ($chats as $c) {
|
||||||
$this->chatModel->setAsViewedChatUserNotifications($c->id,auth()->user()->id);
|
$this->chatModel->setAsViewedChatUserNotifications($c->id, auth()->user()->id);
|
||||||
}
|
}
|
||||||
$chatWithHebraData = array_map(fn(ChatEntity $c) => $c->withHebra(), $chats);
|
$chatWithHebraData = array_map(fn(ChatEntity $c) => $c->withHebra(), $chats);
|
||||||
return $chatWithHebraData ?? [];
|
return $chatWithHebraData ?? [];
|
||||||
}
|
}
|
||||||
public function getAuthUserNotifications(): array
|
public function getAuthUserNotifications(): array
|
||||||
{
|
{
|
||||||
$departmentNotifications = $this->chatModel->getChatDepartmentNotifications();
|
$departmentNotifications = $this->chatModel->getChatDepartmentNotifications();
|
||||||
$internalNotifications = $this->chatModel->getChatInternalNotifications();
|
$internalNotifications = $this->chatModel->getChatInternalNotifications();
|
||||||
$totalMessages = 0;
|
$totalMessages = 0;
|
||||||
$countNotificiationDepartments = array_map(fn($n) => $n->unreadMessages,$departmentNotifications);
|
$countNotificiationDepartments = array_map(fn($n) => $n->unreadMessages, $departmentNotifications);
|
||||||
$countNotificationInternal = array_map(fn($n) => $n->unreadMessages,$internalNotifications);
|
$countNotificationInternal = array_map(fn($n) => $n->unreadMessages, $internalNotifications);
|
||||||
$totalMessages = array_sum($countNotificiationDepartments) + array_sum($countNotificationInternal);
|
$totalMessages = array_sum($countNotificiationDepartments) + array_sum($countNotificationInternal);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -173,4 +182,14 @@ class ChatService extends BaseService
|
|||||||
"totalMessages" => $totalMessages
|
"totalMessages" => $totalMessages
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
public function sendMessageNotificationEmail(ChatMessageEntity $chatMessageEntity, UserEntity $user): bool
|
||||||
|
{
|
||||||
|
$users = auth()->getProvider();
|
||||||
|
$toEmail = $users->find($user->id)->getEmail();
|
||||||
|
$this->emailService->setTo($toEmail);
|
||||||
|
$subject = '[Safekat]' . lang('Chat.mail.mail_subject') . '-' . $chatMessageEntity->chat()->title;
|
||||||
|
$this->emailService->setSubject($subject);
|
||||||
|
$this->emailService->setMessage(view('themes/vuexy/mail/messageNotification', ["header" => lang('Chat.mail.mail_subject'), "data" => $chatMessageEntity->withUser()]));
|
||||||
|
return $this->emailService->send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,11 +10,11 @@
|
|||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="nav-tabs-shadow nav-align-top">
|
<div class="nav-tabs-shadow nav-align-top">
|
||||||
<ul class="nav nav-tabs" role="tablist">
|
<ul class="nav nav-tabs" role="tablist">
|
||||||
<li class="nav-item">
|
<!-- <li class="nav-item">
|
||||||
<button type="button" class="nav-link active" role="tab" id="navs-top-align-directos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-directos">Directos</button>
|
<button type="button" class="nav-link active" role="tab" id="navs-top-align-directos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-directos">Directos</button>
|
||||||
</li>
|
</li> -->
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-presupuestos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-presupuestos">Presupuestos</button>
|
<button type="button" class="nav-link active" role="tab" id="navs-top-align-presupuestos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-presupuestos">Presupuestos</button>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button type="button" class="nav-link" role="tab" id="navs-top-align-pedidos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-pedidos">Pedidos</button>
|
<button type="button" class="nav-link" role="tab" id="navs-top-align-pedidos-tab" data-bs-toggle="tab" data-bs-target="#navs-top-align-pedidos">Pedidos</button>
|
||||||
@ -25,18 +25,8 @@
|
|||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content" id="message-datatables-container">
|
<div class="tab-content" id="message-datatables-container">
|
||||||
<div class="tab-pane fade show active" id="navs-top-align-directos">
|
|
||||||
<?php if (auth()->user()->inGroup('admin')) { ?>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-12 d-flex justify-content-start">
|
|
||||||
<button class="btn btn-primary" id="btn-new-message"><span class="ti ti-md ti-plus"></span>Nuevo mensaje</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?php } ?>
|
|
||||||
|
|
||||||
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tableMessages"]) ?>
|
<div class="tab-pane fade show active" id="navs-top-align-presupuestos">
|
||||||
</div>
|
|
||||||
<div class="tab-pane fade show" id="navs-top-align-presupuestos">
|
|
||||||
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tablePresupuestoMessages"]) ?>
|
<?= view("themes/vuexy/components/tables/messages_table", ["id" => "tablePresupuestoMessages"]) ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane fade show" id="navs-top-align-pedidos">
|
<div class="tab-pane fade show" id="navs-top-align-pedidos">
|
||||||
|
|||||||
84
ci4/app/Views/themes/vuexy/mail/mail_layout.php
Normal file
84
ci4/app/Views/themes/vuexy/mail/mail_layout.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html
|
||||||
|
class="h-100 light-style layout-navbar-fixed layout-menu-fixed"
|
||||||
|
dir="ltr"
|
||||||
|
data-theme="theme-default"
|
||||||
|
data-assets-path="<?= site_url('themes/vuexy/') ?>"
|
||||||
|
data-template="vertical-menu-template-no-customizer">
|
||||||
|
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
|
||||||
|
|
||||||
|
<meta name="description" content="" />
|
||||||
|
<!-- Icons -->
|
||||||
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/fonts/fontawesome.css') ?>" />
|
||||||
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/fonts/tabler-icons.css') ?>" />
|
||||||
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/fonts/flag-icons.css') ?>" />
|
||||||
|
|
||||||
|
<!-- Core CSS -->
|
||||||
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/rtl/core.css') ?>" />
|
||||||
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/rtl/theme-semi-dark.css') ?>" />
|
||||||
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/safekat.css') ?>" />
|
||||||
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/css/pages/app-chat.css') ?>">
|
||||||
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/flatpickr/flatpickr.css') ?>" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Vendors CSS -->
|
||||||
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/perfect-scrollbar/perfect-scrollbar.css') ?>" />
|
||||||
|
|
||||||
|
<!-- Page CSS -->
|
||||||
|
<?= $this->renderSection('css') ?>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/safekat.css') ?>" />
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="layout-container">
|
||||||
|
<div class="layout-page">
|
||||||
|
<div class="content-wrapper">
|
||||||
|
<div class="container-fluid flex-grow-1 container-p-y">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card card-info">
|
||||||
|
<div class="card-header">
|
||||||
|
<div class="d-flex aling-items-center justify-content-between">
|
||||||
|
<h3 class="card-title"><?= $header ?></h3>
|
||||||
|
<span class="app-brand-logo">
|
||||||
|
<img src="http://localhost:8000/themes/vuexy/img/safekat/logos/sk-logo.png" width="150px">
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--//.card-header -->
|
||||||
|
<div class="card-body">
|
||||||
|
<?= $this->renderSection('content') ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<footer class="content-footer footer bg-footer-theme">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="footer-container d-flex align-items-center justify-content-center py-2 flex-md-row flex-column">
|
||||||
|
<div>
|
||||||
|
<a href="#" target="_blank" class="fw-semibold">Safekat</a> © <?= date('Y'); ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
30
ci4/app/Views/themes/vuexy/mail/messageNotification.php
Normal file
30
ci4/app/Views/themes/vuexy/mail/messageNotification.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?= $this->extend('themes/vuexy/mail/mail_layout') ?>
|
||||||
|
|
||||||
|
<?= $this->section('content'); ?>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="card email-card-last mx-sm-4 mx-3 mt-4">
|
||||||
|
<div class="card-header d-flex flex-wrap">
|
||||||
|
<h6 class="m-0"><?= $data->chat()->title ?></h6>
|
||||||
|
</div>
|
||||||
|
<div class="card-header d-flex justify-content-between align-items-center flex-wrap">
|
||||||
|
<div class="d-flex align-items-center mb-sm-0 mb-3">
|
||||||
|
<img src="https://gravatar.com/avatar/<?= $data->user->avatar ?>s=40" alt="user-avatar" class="flex-shrink-0 rounded-circle me-3" height="30" width="30">
|
||||||
|
<div class="flex-grow-1 ms-1">
|
||||||
|
<h6 class="m-0"><?= $data->user->first_name . " " . $data->user->last_name ?></h6>
|
||||||
|
<!-- <small class="text-muted"></small> -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<p class="mb-0 me-3 text-muted"><?= $data->created_at ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="chat-message chat-message">
|
||||||
|
<div class="chat-message-wrapper flex-grow-1">
|
||||||
|
<p><?= $data->message ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?= $this->endSection() ?>
|
||||||
Reference in New Issue
Block a user