From 4364bc3c07c7bcc000f86474552ff7059004f469 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sat, 15 Feb 2025 17:54:53 +0100 Subject: [PATCH] message service --- ci4/app/Config/Services.php | 5 ++ ci4/app/Services/MessageService.php | 59 +++++++++++++++++++ .../tarifas/extra/viewTarifaextraForm.php | 2 +- .../tarifas/extra/viewTarifaextraList.php | 2 +- 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 ci4/app/Services/MessageService.php diff --git a/ci4/app/Config/Services.php b/ci4/app/Config/Services.php index 8d209990..33330fa1 100755 --- a/ci4/app/Config/Services.php +++ b/ci4/app/Config/Services.php @@ -4,6 +4,7 @@ namespace Config; use App\Services\FTPService; use App\Services\MaquinaService; +use App\Services\MessageService; use App\Services\PapelImpresionService; use CodeIgniter\Config\BaseService; use App\Services\ProductionService; @@ -48,4 +49,8 @@ class Services extends BaseService { return new MaquinaService(); } + public static function messages() + { + return new MessageService(); + } } diff --git a/ci4/app/Services/MessageService.php b/ci4/app/Services/MessageService.php new file mode 100644 index 00000000..54bd9b4f --- /dev/null +++ b/ci4/app/Services/MessageService.php @@ -0,0 +1,59 @@ +chatModel = model(ChatModel::class); + $this->chatMessageModel = model(ChatMessageModel::class); + $this->chatNotificationModel = model(ChatNotification::class); + $this->chatUserModel = model(ChatUser::class); + $this->presupuestoModel = model(PresupuestoModel::class); + $this->chatDepartmentModel = model(ChatDeparmentModel::class); + $this->configVariables = model(ConfigVariableModel::class); + } + public function createErrorMessagePresupuesto(string $error, int $presupuesto_id) + { + $chat_department_name = $this->configVariables->getVariable('send_error_to_chat_department_name'); + $chat_department_id = $this->chatDepartmentModel->where('name', $chat_department_name)->first()?->id; + if ($chat_department_id) { + $existChat = $this->chatModel->existChatPresupuesto($chat_department_id, $presupuesto_id); + if ($existChat == false) { + $chatId = $this->chatModel->createChatPresupuesto($chat_department_id, $presupuesto_id); + } else { + $chat = $this->chatModel->getChatPresupuesto($chat_department_id, $presupuesto_id); + $chatId = $chat->id; + } + $chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $error]); + $dataResponse = $this->chatMessageModel->find($chat_message_id); + $chatDepartmentUsers = $this->chatDepartmentModel->getChatDepartmentUsers($chat_department_id); + foreach ($chatDepartmentUsers as $user) { + if ($user->id != auth()->user()->id) { + $this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]); + } + } + } + } +} diff --git a/ci4/app/Views/themes/vuexy/form/tarifas/extra/viewTarifaextraForm.php b/ci4/app/Views/themes/vuexy/form/tarifas/extra/viewTarifaextraForm.php index 19cea842..66359035 100644 --- a/ci4/app/Views/themes/vuexy/form/tarifas/extra/viewTarifaextraForm.php +++ b/ci4/app/Views/themes/vuexy/form/tarifas/extra/viewTarifaextraForm.php @@ -1,6 +1,6 @@ include("themes/_commonPartialsBs/select2bs5") ?> include("themes/_commonPartialsBs/sweetalert") ?> -extend('themes/vuexy/main/defaultlayout') ?> +extend('themes/vuexy/main/defaultlayout')?> section("content") ?>
diff --git a/ci4/app/Views/themes/vuexy/form/tarifas/extra/viewTarifaextraList.php b/ci4/app/Views/themes/vuexy/form/tarifas/extra/viewTarifaextraList.php index 13b5d264..2f9a4c7c 100644 --- a/ci4/app/Views/themes/vuexy/form/tarifas/extra/viewTarifaextraList.php +++ b/ci4/app/Views/themes/vuexy/form/tarifas/extra/viewTarifaextraList.php @@ -1,6 +1,6 @@ include('themes/_commonPartialsBs/datatables') ?> extend('themes/vuexy/main/defaultlayout') ?> -section('content'); ?> +section('content')?>