mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
message service
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
59
ci4/app/Services/MessageService.php
Normal file
59
ci4/app/Services/MessageService.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Controllers\Configuracion\ConfigVariables;
|
||||
use App\Models\Chat\ChatDeparmentModel;
|
||||
use App\Models\Chat\ChatMessageModel;
|
||||
use App\Models\Chat\ChatModel;
|
||||
use App\Models\ChatNotification;
|
||||
use App\Models\ChatUser;
|
||||
use App\Models\Configuracion\ConfigVariableModel;
|
||||
use App\Models\Presupuestos\PresupuestoModel;
|
||||
use CodeIgniter\Config\BaseService;
|
||||
|
||||
|
||||
|
||||
class MessageService extends BaseService
|
||||
{
|
||||
protected ChatModel $chatModel;
|
||||
protected ChatMessageModel $chatMessageModel;
|
||||
protected ChatUser $chatUserModel;
|
||||
protected ChatNotification $chatNotificationModel;
|
||||
protected PresupuestoModel $presupuestoModel;
|
||||
protected ChatDeparmentModel $chatDepartmentModel;
|
||||
protected ConfigVariableModel $configVariables;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?=$this->include('themes/_commonPartialsBs/datatables') ?>
|
||||
<?=$this->extend('themes/vuexy/main/defaultlayout') ?>
|
||||
<?=$this->section('content'); ?>
|
||||
<?=$this->section('content')?>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user