messages departments section

This commit is contained in:
amazuecos
2025-03-20 08:20:50 +01:00
parent d417db18e2
commit 6e96beeec8
26 changed files with 1045 additions and 306 deletions

View File

@ -133,6 +133,9 @@ $routes->group('configuracion', ['namespace' => 'App\Controllers\Configuracion']
$routes->get('edit/(:num)', 'MaquinaTarea::viewForm/$1', ['as' => 'maquinaTareaViewForm']);
$routes->get('datatable', 'MaquinaTarea::datatable', ['as' => 'maquinaTareaDatatable']);
});
$routes->group("messages", ["namespace" => 'App\Controllers\Chat'], function ($routes) {
$routes->get('', 'ChatController::config_view', ['as' => 'configMessagesIndex']);
});
});
@ -892,17 +895,25 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route
$routes->post('direct/messages/unread/(:num)', 'ChatController::update_chat_direct_message_unread/$1', ['as' => 'updateChatDirectMessageUnread']);
$routes->post('department', 'ChatController::store_chat_department', ['as' => 'storeChatDepartment']);
$routes->delete('department/(:num)', 'ChatController::delete_chat_department/$1', ['as' => 'deleteChatDepartment']);
$routes->post('department/update/(:num)', 'ChatController::update_chat_department/$1', ['as' => 'updateChatDepartment']);
$routes->get('departments', 'ChatController::get_chat_departments', ['as' => 'getChatDepartments']);
$routes->get('departments/select', 'ChatController::get_chat_department_select', ['as' => 'getChatDepartmentSelect']);
$routes->get('department/presupuesto/(:num)/(:num)', 'ChatController::get_chat_presupuesto/$1/$2', ['as' => 'getChatPresupuesto']);
$routes->get('department/pedido/(:num)/(:num)', 'ChatController::get_chat_pedido/$1/$2', ['as' => 'getChatPedido']);
$routes->get('department/factura/(:num)/(:num)', 'ChatController::get_chat_factura/$1/$2', ['as' => 'getChatFactura']);
$routes->get('department/users/presupuesto/(:num)/(:num)', 'ChatController::get_chat_department_presupuesto_users/$1/$2', ['as' => 'getPresupuestoChatDepartmentUsers']);
$routes->get('department/datatable', 'ChatController::chat_department_datatable', ['as' => 'chatDepartmentDatatable']);
$routes->get('department/edit/(:num)', 'ChatController::chat_department_edit/$1', ['as' => 'chatDepartmentEditView']);
$routes->get('department/users/datatable/(:num)', 'ChatController::chat_department_user_datatable/$1', ['as' => 'chatDepartmentUsersDatatable']);
$routes->get('department/users/pedido/(:num)/(:num)', 'ChatController::get_chat_department_pedido_users/$1/$2', ['as' => 'getPedidoChatDepartmentUsers']);
$routes->get('department/users/factura/(:num)/(:num)', 'ChatController::get_chat_department_factura_users/$1/$2', ['as' => 'getFacturaChatDepartmentUsers']);
$routes->get('department/users/select/add/(:num)', 'ChatController::select_users_not_in_chat_department/$1', ['as' => 'selectUsersNotInChatDepartment']);
$routes->post('department/user', 'ChatController::subscribe_to_chat_deparment/$1', ['as' => 'subscribeToChatDepartment']);
$routes->post('department/subscribe/admin/user', 'ChatController::subscribe_admin_to_department', ['as' => 'subscribeAdminToChatDepartment']);
$routes->delete('department/user/(:num)', 'ChatController::delete_user_from_department/$1', ['as' => 'deleteUserFromDepartment']);
$routes->delete('department/admin/user/(:num)/(:num)', 'ChatController::delete_user_admin_from_department/$1/$2', ['as' => 'deleteUserAdminFromDepartment']);
$routes->get('(:num)', 'ChatController::get_chat/$1', ['as' => 'getChat']);

View File

@ -162,4 +162,15 @@ class Validation extends BaseConfig
],
];
public array $chat_department =
[
"display" => [
"rules" => "required|string",
"label" => "tarifa acabado",
],
"description" => [
"rules" => "permit_empty",
"label" => "maquina",
],
];
}

View File

@ -21,6 +21,7 @@ use CodeIgniter\Log\Logger;
use Psr\Log\LoggerInterface;
use Hermawan\DataTables\DataTable;
use CodeIgniter\I18n\Time;
use CodeIgniter\Validation\Validation;
class ChatController extends BaseController
{
@ -32,6 +33,8 @@ class ChatController extends BaseController
protected ClienteModel $clienteModel;
protected ChatUser $chatUserModel;
protected ChatNotification $chatNotificationModel;
protected Validation $validation;
protected array $viewData;
protected static $viewPath = 'themes/vuexy/form/mensajes/';
@ -52,6 +55,7 @@ class ChatController extends BaseController
$this->clienteModel = model(ClienteModel::class);
$this->chatUserModel = model(ChatUser::class);
$this->chatNotificationModel = model(ChatNotification::class);
$this->validation = service("validation");
}
public function index() {}
public function get_chat_departments()
@ -77,6 +81,7 @@ class ChatController extends BaseController
if ($chat) {
$data["messages"] = $this->chatMessageModel->get_chat_messages($chat->id);
$this->chatMessageModel->set_chat_department_messages_as_read($chat->id);
$this->chatModel->setAsViewedChatUserNotifications($chat->id, auth()->user()->id);
$data["count"] = count($data["messages"]);
}
$data["chat"] = $chat;
@ -94,6 +99,8 @@ class ChatController extends BaseController
if ($chat) {
$data["messages"] = $this->chatMessageModel->get_chat_messages($chat->id);
$this->chatMessageModel->set_chat_department_messages_as_read($chat->id);
$this->chatModel->setAsViewedChatUserNotifications($chat->id, auth()->user()->id);
$data["count"] = count($data["messages"]);
}
$data["chat"] = $chat;
@ -111,6 +118,7 @@ class ChatController extends BaseController
if ($chat) {
$data["messages"] = $this->chatMessageModel->get_chat_messages($chat->id);
$this->chatMessageModel->set_chat_department_messages_as_read($chat->id);
$this->chatModel->setAsViewedChatUserNotifications($chat->id, auth()->user()->id);
$data["count"] = count($data["messages"]);
}
$data["chat"] = $chat;
@ -207,19 +215,18 @@ class ChatController extends BaseController
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
$dataResponse = $this->chatMessageModel->find($chat_message_id);
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentPresupuestoUsers($data["chat_department_id"],$data["model_id"]);
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $data['client']]);
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',$data['client'])->where('presupuesto_id',$data['model_id'])->countAllResults();
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',auth()->user()->id)->countAllResults();
if($cliente_in_department_count == 0){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client'],'presupuesto_id' => $data['model_id']]);
}
if($auth_user_in_department_count){
$users_always_in_department = array_map(fn($q) => $q->id,$chatDepartmentUsers);
if(!in_array(auth()->user()->id,$users_always_in_department)){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => auth()->user()->id,'presupuesto_id' => $data['model_id']]);
if (auth()->user()->inGroup('admin')) {
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', $data['client'])->where('presupuesto_id', $data['model_id'])->countAllResults();
if ($cliente_in_department_count == 0) {
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => $data['client'], 'presupuesto_id' => $data['model_id']]);
}
}
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentPresupuestoUsers($data["chat_department_id"], $data["model_id"]);
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', auth()->user()->id)->countAllResults();
if ($auth_user_in_department_count) {
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => auth()->user()->id, 'presupuesto_id' => $data['model_id']]);
}
foreach ($chatDepartmentUsers as $user) {
if ($user->id != auth()->user()->id) {
@ -227,9 +234,7 @@ class ChatController extends BaseController
}
}
foreach ($chatExternalUsers as $user) {
if ($user->id != auth()->user()->id) {
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
return $this->response->setJSON($dataResponse);
}
@ -247,20 +252,17 @@ class ChatController extends BaseController
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
$dataResponse = $this->chatMessageModel->find($chat_message_id);
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentPedidoUsers($data["chat_department_id"],$data["model_id"]);
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $data['client']]);
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',$data['client'])->where('pedido_id',$data['model_id'])->countAllResults();
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',auth()->user()->id)->countAllResults();
if($cliente_in_department_count == 0){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client'],'pedido_id' => $data['model_id']]);
}
if($auth_user_in_department_count){
$users_always_in_department = array_map(fn($q) => $q->id,$chatDepartmentUsers);
if(!in_array(auth()->user()->id,$users_always_in_department)){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => auth()->user()->id,'pedido_id' => $data['model_id']]);
if (auth()->user()->inGroup('admin')) {
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', $data['client'])->where('pedido_id', $data['model_id'])->countAllResults();
if ($cliente_in_department_count == 0) {
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => $data['client'], 'pedido_id' => $data['model_id']]);
}
}
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentPedidoUsers($data["chat_department_id"], $data["model_id"]);
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', auth()->user()->id)->countAllResults();
if ($auth_user_in_department_count == 0) {
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => auth()->user()->id, 'pedido_id' => $data['model_id']]);
}
foreach ($chatDepartmentUsers as $user) {
if ($user->id != auth()->user()->id) {
@ -268,40 +270,34 @@ class ChatController extends BaseController
}
}
foreach ($chatExternalUsers as $user) {
if ($user->id != auth()->user()->id) {
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
return $this->response->setJSON($dataResponse);
}
public function store_chat_message_factura()
{
$data = $this->request->getPost();
$existChat = $this->chatModel->existChatFactura($data["chat_department_id"], $data["model_id"]);
$existChat = $this->chatModel->existChatPedido($data["chat_department_id"], $data["model_id"]);
if ($existChat == false) {
$chatId = $this->chatModel->createChatFactura($data["chat_department_id"], $data["model_id"]);
$chatId = $this->chatModel->createChatPedido($data["chat_department_id"], $data["model_id"]);
} else {
$chat = $this->chatModel->getChatFactura($data["chat_department_id"], $data["model_id"]);
$chat = $this->chatModel->getChatPedido($data["chat_department_id"], $data["model_id"]);
$chatId = $chat->id;
}
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
$dataResponse = $this->chatMessageModel->find($chat_message_id);
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentFacturaUsers($data["chat_department_id"],$data["model_id"]);
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $data['client']]);
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',$data['client'])->where('factura_id',$data['model_id'])->countAllResults();
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',auth()->user()->id)->countAllResults();
if($cliente_in_department_count == 0){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client'],'factura_id' => $data['model_id']]);
}
if($auth_user_in_department_count){
$users_always_in_department = array_map(fn($q) => $q->id,$chatDepartmentUsers);
if(!in_array(auth()->user()->id,$users_always_in_department)){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => auth()->user()->id,'factura_id' => $data['model_id']]);
if (auth()->user()->inGroup('admin')) {
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', $data['client'])->where('pedido_id', $data['model_id'])->countAllResults();
if ($cliente_in_department_count == 0) {
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => $data['client'], 'factura_id' => $data['model_id']]);
}
}
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentPedidoUsers($data["chat_department_id"], $data["model_id"]);
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', auth()->user()->id)->countAllResults();
if ($auth_user_in_department_count == 0) {
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => auth()->user()->id, 'pedido_id' => $data['model_id']]);
}
foreach ($chatDepartmentUsers as $user) {
if ($user->id != auth()->user()->id) {
@ -309,9 +305,7 @@ class ChatController extends BaseController
}
}
foreach ($chatExternalUsers as $user) {
if ($user->id != auth()->user()->id) {
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
return $this->response->setJSON($dataResponse);
}
@ -377,7 +371,7 @@ class ChatController extends BaseController
$cliente_id = auth()->user()->cliente_id;
$response = [];
if ($cliente_id) {
$data = $this->clienteModel->getClienteDataPresupuestoPedidoFactura($cliente_id);
// $data = $this->clienteModel->getClienteDataPresupuestoPedidoFactura($cliente_id);
$response["internals"] = $this->chatModel->getChatDepartmentNotifications();
$response["totalMessages"] = 0;
$mensajes_directos = $this->chatModel->getChatDirectMessageNotifications();
@ -389,10 +383,10 @@ class ChatController extends BaseController
// foreach ($response["chatPresupuestos"] as $key => $value) {
// $response["totalMessages"] += $value->unreadMessages;
// }
// foreach ($mensajes_directos as $value) {
// $response["internals"][] = $value;
// $response["totalMessages"] += $value->unreadMessages;
// }
foreach ($mensajes_directos as $value) {
$response["internals"][] = $value;
$response["totalMessages"] += $value->unreadMessages;
}
// $response["chatPedidos"] = $this->chatModel->getClienteChatPedidos($data["pedidos"]);
// foreach ($response["chatPedidos"] as $key => $value) {
// $response["totalMessages"] += $value->unreadMessages;
@ -420,23 +414,23 @@ class ChatController extends BaseController
return $this->response->setJSON($response);
}
public function get_chat_department_presupuesto_users(int $chat_department_id,int $presupuesto_id)
public function get_chat_department_presupuesto_users(int $chat_department_id, int $presupuesto_id)
{
$adminUsers = $this->chatDeparmentModel->getChatDepartmentUsers($chat_department_id);
$externalUsers = $this->chatDeparmentModel->getChatDeparmentPresupuestoUsers($chat_department_id,$presupuesto_id);
return $this->response->setJSON(['admin_users' => $adminUsers,'external_users' => $externalUsers]);
$externalUsers = $this->chatDeparmentModel->getChatDeparmentPresupuestoUsers($chat_department_id, $presupuesto_id);
return $this->response->setJSON(['admin_users' => $adminUsers, 'external_users' => $externalUsers]);
}
public function get_chat_department_pedido_users(int $chat_department_id,$pedido_id)
public function get_chat_department_pedido_users(int $chat_department_id, $pedido_id)
{
$adminUsers = $this->chatDeparmentModel->getChatDepartmentUsers($chat_department_id);
$externalUsers = $this->chatDeparmentModel->getChatDeparmentPedidoUsers($chat_department_id,$pedido_id);
return $this->response->setJSON(['admin_users' => $adminUsers,'external_users' => $externalUsers]);
$externalUsers = $this->chatDeparmentModel->getChatDeparmentPedidoUsers($chat_department_id, $pedido_id);
return $this->response->setJSON(['admin_users' => $adminUsers, 'external_users' => $externalUsers]);
}
public function get_chat_department_factura_users(int $chat_department_id,$factura_id)
public function get_chat_department_factura_users(int $chat_department_id, $factura_id)
{
$adminUsers = $this->chatDeparmentModel->getChatDepartmentUsers($chat_department_id);
$externalUsers = $this->chatDeparmentModel->getChatDeparmentFacturaUsers($chat_department_id,$factura_id);
return $this->response->setJSON(['admin_users' => $adminUsers,'external_users' => $externalUsers]);
$externalUsers = $this->chatDeparmentModel->getChatDeparmentFacturaUsers($chat_department_id, $factura_id);
return $this->response->setJSON(['admin_users' => $adminUsers, 'external_users' => $externalUsers]);
}
public function get_chat_users_internal()
{
@ -766,8 +760,18 @@ class ChatController extends BaseController
}
public function get_notifications_not_viewed_from_chat(int $chat_id)
{
$data = $this->chatModel->getUsersNotificationNotViewedFromChat($chat_id);
return $this->response->setJSON(["data" => $data, "chat_id" => $chat_id]);
$unviewedNotifications = $this->chatModel->getUsersNotificationNotViewedFromChat($chat_id);
$viewedNotifications = $this->chatModel->getUsersNotificationViewedFromChat($chat_id);
return $this->response->setJSON(
[
"data" => [
"unviewedNotifications" => $unviewedNotifications,
"viewedNotifications" => $viewedNotifications
],
"chat_id" => $chat_id
]
);
}
public function store_new_direct_message()
{
@ -878,46 +882,142 @@ class ChatController extends BaseController
}
public function delete_user_from_department($chat_department_id)
{
$data = $this->request->getPost();
$data = $this->request->getRawInput();
$user_id = auth()->user()->id;
$adminExist = $this->chatDeparmentUserModel->where('chat_department_id',$chat_department_id)
->where('user_id',$user_id)
->where('pedido_id',null)
->where('factura_id',null)
->where('presupuesto_id',null)->countAllResults();
if($adminExist)
{
return $this->response->setJSON(["message" => lang('Chat.exit_admin_chat_wrong'),"status" => false]);
$adminExist = $this->chatDeparmentUserModel->where('chat_department_id', $chat_department_id)
->where('user_id', $user_id)
->where('pedido_id', null)
->where('factura_id', null)
->where('presupuesto_id', null)->countAllResults();
if ($adminExist) {
return $this->response->setJSON(["message" => lang('Chat.exit_admin_chat_wrong'), "status" => false]);
}
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id',$chat_department_id)->where('user_id',$user_id)->where($data['model_fk'],$data['model_id_fk']);
if($chatDepartmentUserEntity->countAllResults() > 0)
{
$deleted = $this->chatDeparmentUserModel->where('chat_department_id',$chat_department_id)->where('user_id',$user_id)->delete();
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id', $chat_department_id)->where('user_id', $user_id)->where($data['model_fk'], $data['model_id_fk']);
if ($chatDepartmentUserEntity->countAllResults() > 0) {
$deleted = $this->chatDeparmentUserModel->where('chat_department_id', $chat_department_id)->where('user_id', $user_id)->delete(purge: true);
return $this->response->setJSON(["message" => lang('Chat.exit_chat_ok'), "status" => true]);
}else{
return $this->response->setJSON(["message" => lang('Chat.exit_chat_wrong'),"status" => false]);
} else {
return $this->response->setJSON(["message" => lang('Chat.exit_chat_wrong'), "status" => false]);
}
}
public function delete_user_admin_from_department($chat_department_id, $user_id)
{
$this->chatDeparmentUserModel->where('chat_department_id', $chat_department_id)->where('user_id', $user_id)->delete();
return $this->response->setJSON(["message" => lang('Chat.user_deleted_ok'), "status" => true]);
}
public function subscribe_to_chat_deparment()
{
$data = $this->request->getPost();
$user_id = auth()->user()->id;
$adminExist = $this->chatDeparmentUserModel->where('chat_department_id',$data['chat_department_id'])
->where('user_id',$user_id)
->where('pedido_id',null)
->where('factura_id',null)
->where('presupuesto_id',null)->countAllResults();
if($adminExist)
{
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_wrong'),"status" => false]);
$adminExist = $this->chatDeparmentUserModel->where('chat_department_id', $data['chat_department_id'])
->where('user_id', $user_id)
->where('pedido_id', null)
->where('factura_id', null)
->where('presupuesto_id', null)->countAllResults();
if ($adminExist) {
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_wrong'), "status" => false]);
}
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id',$data['chat_department_id'])->where('user_id',$user_id)->where($data['model_fk'],$data['model_id_fk']);
if($chatDepartmentUserEntity->countAllResults() > 0)
{
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_wrong'),"status" => false]);
}else{
$this->chatDeparmentUserModel->insert(["chat_department_id" => $data["chat_department_id"],"user_id" => $user_id,$data['model_fk'] => $data['model_id_fk']]);
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id', $data['chat_department_id'])->where('user_id', $user_id)->where($data['model_fk'], $data['model_id_fk']);
if ($chatDepartmentUserEntity->countAllResults() > 0) {
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_wrong'), "status" => false]);
} else {
$this->chatDeparmentUserModel->insert(["chat_department_id" => $data["chat_department_id"], "user_id" => $user_id, $data['model_fk'] => $data['model_id_fk']]);
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_ok'), "status" => true]);
}
}
public function subscribe_admin_to_department()
{
$data = $this->request->getPost();
if ($data['user_id']) {
$this->chatDeparmentUserModel
->insert(
[
"chat_department_id" => $data["chat_department_id"],
"user_id" => $data["user_id"],
]
);
return $this->response->setJSON(["message" => lang('Chat.subscribe_admin_chat_ok'), "status" => true]);
} else {
return $this->response->setStatusCode(422)->setJSON(["message" => lang('Chat.subscribe_admin_chat_wrong'), "status" => false]);
}
}
public function config_view()
{
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_configuration"), 'route' => 'javascript:void(0);', 'active' => false],
['title' => lang("App.menu_config_messages"), 'route' => route_to("configMessagesIndex"), 'active' => true]
];
return view('themes/vuexy/form/configuracion/messages/configView', $this->viewData);
}
public function chat_department_edit($chat_department_id)
{
$chatDepartment = $this->chatDeparmentModel->find($chat_department_id);
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_configuration"), 'route' => 'javascript:void(0);', 'active' => false],
['title' => lang("App.menu_config_messages"), 'route' => route_to("configMessagesIndex"), 'active' => false],
['title' => $chatDepartment->display, 'route' => route_to("chatDepartmentEditView", $chat_department_id), 'active' => true]
];
$this->viewData["chat_department"] = $chatDepartment;
return view('themes/vuexy/form/configuracion/messages/editChatDepartmentForm', $this->viewData);
}
public function chat_department_datatable()
{
$q = $this->chatDeparmentModel->datatableQuery();
return DataTable::of($q)
->add('action', fn($r) => $r->id)
->toJson(true);
}
public function chat_department_user_datatable(int $chat_department_id)
{
$q = $this->chatDeparmentUserModel->datatableQuery($chat_department_id);
$datatable = DataTable::of($q);
if (auth()->user()->inGroup('admin')) {
$datatable->add('action', fn($r) => $r->userId);
}
return $datatable->toJson(true);
}
public function select_users_not_in_chat_department(int $chat_department_id)
{
$paramQuery = $this->request->getGet("q");
$data = $this->chatDeparmentUserModel->querySelectUsersNotInDepartment($chat_department_id, $paramQuery);
return $this->response->setJSON($data);
}
public function store_chat_department()
{
$data = $this->request->getPost();
$validated = $this->validation->run($data, 'chat_department');
if ($validated) {
$dataValidated = $this->validation->getValidated();
$dataValidated['name'] = newUUID();
$this->chatDeparmentModel->insert($dataValidated);
return $this->response->setJSON(["message" => lang('App.global_alert_save_success'), "status" => true, "data" => $dataValidated]);
} else {
return $this->response->setStatusCode(422)->setJSON(["message" => lang('App.global_alert_save_success'), "status" => false, "errors" => $this->validation->getErrors()]);
}
return $this->response->setJSON(["message" => lang('App.global_alert_save_success'), "status" => true]);
}
public function update_chat_department(int $chat_department_id)
{
$data = $this->request->getPost();
$validated = $this->validation->run($data, 'chat_department');
if ($validated) {
$dataValidated = $this->validation->getValidated();
$this->chatDeparmentModel->update($chat_department_id, $dataValidated);
return $this->response->setJSON(["message" => lang('App.global_alert_save_success'), "status" => true, "data" => $dataValidated]);
} else {
return $this->response->setStatusCode(422)->setJSON(["message" => lang('App.global_alert_save_success'), "status" => false, "errors" => $this->validation->getErrors()]);
}
}
public function delete_chat_department($chat_department_id)
{
if (auth()->user()->inGroup('admin')) {
$this->chatDeparmentModel->delete($chat_department_id);
return $this->response->setJSON(["message" => lang('App.user_alert_delete'), "status" => true]);
} else {
return $this->response->setStatusCode(403)->setJSON(["message" => lang('App.user_alert_forbidden'), "status" => false]);
}
}
}

View File

@ -24,6 +24,14 @@ return [
"viewed" => "Viewed",
],
"datatable_departments" => [
"name" => "Name",
"description" => "Description",
],
"datatable_department_users" => [
"name" => "Name",
"user" => "User",
],
"new_message_ok" => "Message sent successfully",
"participants" => "Participants",
"choose_department" => "Choose a deparment",
@ -42,4 +50,12 @@ return [
"exit_chat_wrong" => "You can't exit the chat because you don't belong to it.",
"subscribe_chat_ok" => "You've subscribed to chat successfully. Now on you'll receive notifications.",
"subscribe_chat_wrong" => "You already belong to this chat.",
];
"message_configuration" => "Messages configuration",
"new_chat_department" => "New chat department",
"user_deleted_ok" => "User deleted succesfully",
"subscribe_admin_chat_ok" => "User added successfully",
"subscribe_admin_chat_wrong" => "You must select a user",
];

View File

@ -226,6 +226,8 @@ return [
"user_alert_add" => "¡Agregado exitosamente!",
"user_alert_edit" => "¡Editado con éxito!",
"user_alert_delete" => "¡Eliminado con éxito!",
"user_alert_forbidden" => "No tienes permiso para realizar esta acción",
// USER - form
"user_add_title" => "Nuevo Usuario",
@ -686,6 +688,7 @@ return [
"menu_configuration" => "Configuración",
"menu_variables" => "Variables sistema",
"menu_config_messages" => "Mensajería",
"menu_error_presupuesto" => "Errores presupuesto",
"menu_calendario" => "Calendario",
"menu_paises" => "Paises",

View File

@ -24,6 +24,14 @@ return [
"viewed" => "Leído",
],
"datatable_departments" => [
"name" => "Nombre",
"description" => "Descripción",
],
"datatable_department_users" => [
"name" => "Nombre",
"user" => "Usuario",
],
"new_message_ok" => "Mensaje enviado correctamente",
"participants" => "Participantes",
"choose_department" => "Elige un departamento",
@ -43,4 +51,14 @@ return [
"exit_admin_chat_wrong" => "Perteneces como personal a este chat y no puedes salirte. Contacta administrador para ello.",
"subscribe_chat_ok" => "Te has subscrito al chat correctamente. Ahora recibirás notificaciones cuando lleguen mensajes.",
"subscribe_chat_wrong" => "Ya perteneces a este chat.",
"message_configuration" => "Configuración mensajería",
"new_chat_department" => "Nuevo departamento",
"user_deleted_ok" => "Usuario eliminado con éxito",
"department_users" => "Usuarios departamento",
"subscribe_admin_chat_ok" => "Usuario añadido correctamente.",
"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 ...)",
"store_department" => "Crear departamento",
];

View File

@ -108,7 +108,7 @@ class ChatDeparmentModel extends Model
public function getChatDeparmentUserQuery(int $chat_deparment_id)
{
$query = $this->builder()
$query = $this
->select(
[
"users.*"
@ -123,20 +123,21 @@ class ChatDeparmentModel extends Model
"users",
"chat_department_users.user_id = users.id",
'left'
)->where("chat_departments.id", $chat_deparment_id)
->where("chat_department_users.deleted_at", null)
->where("users.deleted_at", null);
)
->where("chat_department_users.chat_department_id", $chat_deparment_id)
->where("chat_department_users.deleted_at",null)
->where("users.deleted_at",null);
return $query;
}
public function getChatDepartmentUsers(int $chat_deparment_id)
{
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
->where('chat_department_users.presupuesto_id', null)
->where('chat_department_users.pedido_id', null)
->where('chat_department_users.factura_id', null)
->get()->getResultObject();
return $result;
->where('chat_department_users.presupuesto_id',null)
->where('chat_department_users.pedido_id',null)
->where('chat_department_users.factura_id',null)
->get();
return $result->getResultObject() ?: [];
}
public function getChatDeparmentPresupuestoUsers(int $chat_deparment_id, int $presupuesto_id)
{
@ -163,7 +164,7 @@ class ChatDeparmentModel extends Model
{
return $this->find($chat_deparment_id)->display;
}
public function getChatDepartmentSelect(string $query = null)
public function getChatDepartmentSelect(?string $query)
{
$q = $this->builder()->select([
"id",
@ -176,4 +177,8 @@ class ChatDeparmentModel extends Model
}
return $q;
}
public function datatableQuery()
{
return $this->select(['id','display','description'])->where('deleted_at',null);
}
}

View File

@ -2,7 +2,7 @@
namespace App\Models\Chat;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Model;
class ChatDeparmentUserModel extends Model
@ -53,11 +53,55 @@ class ChatDeparmentUserModel extends Model
public function getChatDepartmentUser(int $user_id)
{
return $this->db->table($this->table." t1")
->select("chat_departments.*")
->join("chat_departments","t1.chat_department_id = chat_departments.id","left")
->where("t1.user_id",$user_id)
->where("t1.deleted_at",null)
->get()->getResultObject();
return $this->db->table($this->table . " t1")
->select("chat_departments.*")
->join("chat_departments", "t1.chat_department_id = chat_departments.id", "left")
->where("t1.user_id", $user_id)
->where("t1.deleted_at", null)
->get()->getResultObject();
}
public function datatableQuery(int $chat_department_id)
{
return $this->builder()->select(
[
'users.id as userId',
'CONCAT(users.first_name," ",users.last_name) as userFullName',
'users.username'
]
)
->join('users', 'users.id = chat_department_users.user_id', 'left')
->join('chat_departments', 'chat_departments.id = chat_department_users.chat_department_id', 'left')
->where('chat_departments.id', $chat_department_id)
->where('chat_department_users.pedido_id', null)
->where('chat_department_users.presupuesto_id', null)
->where('chat_department_users.factura_id', null)
->where('chat_department_users.deleted_at', null);
}
public function querySelectUsersNotInDepartment(int $chat_department_id, ?string $q): array
{
$query = $this->builder()->select([
'users.id as userId',
])
->join('users', 'users.id = chat_department_users.user_id', 'left')
->join('chat_departments', 'chat_departments.id = chat_department_users.chat_department_id', 'left')
->where('chat_departments.id', $chat_department_id)
->where('chat_department_users.deleted_at', null);
$usersInDepartment = array_map(fn($q) => $q->userId, $query->get()->getResultObject());
$userModel = model(UserModel::class);
$queryUser = $userModel->builder()->select([
'id',
'CONCAT(first_name," ",last_name) as name',
'username as description',
])
->where('cliente_id',null)
->where('deleted_at', null);
if ($usersInDepartment) {
$queryUser->whereNotIn("id", $usersInDepartment);
}
if ($q) {
$queryUser->like('CONCAT(first_name," ",last_name)', $q);
}
return $queryUser->get()->getResultArray();
}
}

View File

@ -329,18 +329,19 @@ class ChatModel extends Model
"chats.presupuesto_id as presupuestoId",
"chats.factura_id as facturaId",
"chats.title as chatDisplay",
"COUNT(chat_notifications.viewed) as unreadMessages"
])
->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);
->where("chats.chat_department_id is NOT NULL", NULL, FALSE)
->groupBy('chats.id');
$rows = $q->get()->getResultObject();
$auth_user = auth()->user();
$rows_new = [];
foreach ($rows as $row) {
$row->unreadMessages = 0;
if ($row->presupuestoId) {
$row->model = $presupuestoModel->find($row->presupuestoId);
if ($auth_user->cliente_id) {
@ -355,7 +356,6 @@ class ChatModel extends Model
$row->chatDisplay .= "[INTERNAL]";
}
$row->avatar = "PRE";
$row->unreadMessages = $this->countUnreadMessagePresupuesto($row->presupuestoId);
$rows_new[] = $row;
} elseif ($row->pedidoId) {
$row->model = $pedidoModel->find($row->pedidoId);
@ -365,7 +365,6 @@ class ChatModel extends Model
$row->chatDisplay .= "[INTERNAL]";
}
$row->avatar = "P";
$row->unreadMessages = $this->countUnreadMessagePedido($row->pedidoId);
$rows_new[] = $row;
} elseif ($row->facturaId) {
$row->model = $facturaModel->find($row->facturaId);
@ -375,7 +374,6 @@ class ChatModel extends Model
$row->chatDisplay .= "[INTERNAL]";
}
$row->title = $row->facturaId;
$row->unreadMessages = $this->countUnreadMessageFactura($row->facturaId);
$rows_new[] = $row;
}
}
@ -587,7 +585,7 @@ class ChatModel extends Model
}
return $data;
}
public function countUnreadMessagePresupuesto($presupuesto_id): int|string
public function countUnreadMessagePresupuesto(int $presupuesto_id,int $chat_department_id): int|string
{
return $this->builder()->select()
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
@ -595,6 +593,7 @@ class ChatModel extends Model
->where("chats.presupuesto_id", $presupuesto_id)
->where("chat_notifications.viewed", false)
->where("chat_notifications.user_id", auth()->user()->id)
->where('chats.chat_department_id',$chat_department_id)
->countAllResults();
}
public function countUnreadMessagePedido($pedido_id): int|string
@ -711,9 +710,7 @@ class ChatModel extends Model
[
"CONCAT(users.first_name,' ',users.last_name) as userFullName",
"users.username as userName",
"SUM(chat_notifications.viewed) as viewed_count",
"COUNT(chat_notifications.id) as notification_count"
"chat_notifications.viewed"
]
)
@ -722,6 +719,26 @@ class ChatModel extends Model
->join("users", "users.id = chat_notifications.user_id", 'left')
->where("chats.id", $chat_id)
->where("chat_notifications.deleted_at", null)
->where('chat_notifications.viewed',false)
->get()->getResultArray();
return $q;
}
public function getUsersNotificationViewedFromChat(int $chat_id): array
{
$q = $this->builder()->distinct()->select(
[
"CONCAT(users.first_name,' ',users.last_name) as userFullName",
"users.username as userName",
"chat_notifications.viewed"
]
)
->join("chat_messages", "chat_messages.chat_id = chats.id", 'left')
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", 'left')
->join("users", "users.id = chat_notifications.user_id", 'left')
->where("chats.id", $chat_id)
->where("chat_notifications.deleted_at", null)
->where('chat_notifications.viewed',true)
->get()->getResultArray();
return $q;
}
@ -903,16 +920,17 @@ class ChatModel extends Model
public function setAsViewedChatUserNotifications(int $chat_id, int $user_id)
{
$query = $this->builder()
->select("chat_messages.id")
->select("chat_notifications.id as notificationId")
->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',$user_id)
->where('chat_messages.chat_id', $chat_id)
->get()->getResultObject();
$chat_messages_ids = array_map(fn($q) => $q->id, $query);
$this->db->table("chat_notifications")
->where("user_id", $user_id)
->whereIn("chat_message_id", $chat_messages_ids)
->update(["viewed" => true]);
$chat_messages_ids = array_map(fn($q) => $q->notificationId, $query);
$chatNotificationModel = model(ChatNotification::class);
if($chat_messages_ids){
$chatNotificationModel->setNotificationsAsViewed($chat_messages_ids);
}
}
public function setAsViewedChatUserMessages(int $chat_id, int $user_id)
{
@ -924,16 +942,17 @@ class ChatModel extends Model
public function setAsUnviewedChatUserNotifications(int $chat_id, int $user_id)
{
$query = $this->builder()
->select("chat_messages.id")
->select("chat_notifications.id as notificationId")
->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',$user_id)
->where('chat_messages.chat_id', $chat_id)
->get()->getResultObject();
$chat_messages_ids = array_map(fn($q) => $q->id, $query);
$this->db->table("chat_notifications")
->where("user_id", $user_id)
->whereIn("chat_message_id", $chat_messages_ids)
->update(["viewed" => false]);
$chat_messages_ids = array_map(fn($q) => $q->notificationId, $query);
$chatNotificationModel = model(ChatNotification::class);
if($chat_messages_ids){
$chatNotificationModel->setNotificationsAsUnViewed($chat_messages_ids);
}
}
public function setAsUnviewedChatUserMessages(int $chat_id, int $user_id)

View File

@ -59,4 +59,12 @@ class ChatNotification extends Model
}
return $status;
}
public function setNotificationsAsViewed(array $notificationIds) : bool
{
return $this->update($notificationIds,["viewed" => 1]);
}
public function setNotificationsAsUnViewed(array $notificationIds) : bool
{
return $this->update($notificationIds,["viewed" => 0]);
}
}

View File

@ -26,11 +26,11 @@
</div>
<hr class="container-m-nx m-0" />
<div class="sidebar-body">
<div class="chat-contact-list-item-title">
<?php if (auth()->user()->inGroup('admin')): ?>
<div class="mb-0 px-4 pt-3 pb-2">
<select class="form-control chat-search-client"></select>
</div>
</div>
<?php endif; ?>
<div class="chat-contact-list-item-title">
<h5 class="text-primary mb-0 px-4 pt-3 pb-2">Departamentos</h5>
</div>
@ -68,18 +68,22 @@
</div>
<div class="d-flex align-items-center">
<div class="ml-2 px-2">
<button type="button" class="btn btn-danger btn-sm exit-chat">
<i class="ti ti-trash"></i>
<?= lang('Chat.exit_chat') ?>
</button>
</div>
<div class="ml-2 px-2">
<button type="button" class="btn btn-success btn-sm subscribe-chat">
<i class="ti ti-plus"></i>
<?= lang('Chat.subscribe_chat') ?>
</button>
</div>
<?php if (auth()->user()->inGroup('admin')): ?>
<div class="ml-2 px-2">
<button type="button" class="btn btn-danger btn-sm exit-chat">
<i class="ti ti-trash"></i>
<?= lang('Chat.exit_chat') ?>
</button>
</div>
<div class="ml-2 px-2">
<button type="button" class="btn btn-success btn-sm subscribe-chat">
<i class="ti ti-plus"></i>
<?= lang('Chat.subscribe_chat') ?>
</button>
</div>
<?php endif; ?>
<div class="dropdown d-flex align-self-center ml-2 px-2 d-none" id="chat-header-dropdown-users">
<button type="button" class="btn btn-primary btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
<i class="ti ti-users"></i>
@ -117,11 +121,19 @@
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
<div class="message-actions d-flex align-items-center">
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment" disabled>
<i class="ti ti-send me-md-1 me-0"></i>
<span class="align-middle d-md-inline-block">Enviar</span>
</button>
<?php if (auth()->user()->inGroup('admin')): ?>
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment" disabled>
<i class="ti ti-send me-md-1 me-0"></i>
<span class="align-middle d-md-inline-block">Enviar</span>
</button>
<?php else : ?>
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment-client">
<i class="ti ti-send me-md-1 me-0"></i>
<span class="align-middle d-md-inline-block">Enviar</span>
</button>
<?php endif; ?>
</div>
</div>

View File

@ -27,9 +27,11 @@
<hr class="container-m-nx m-0" />
<div class="sidebar-body">
<div class="chat-contact-list-item-title">
<div class="mb-0 px-4 pt-3 pb-2">
<select class="form-control chat-search-client"></select>
</div>
<?php if (auth()->user()->inGroup('admin')): ?>
<div class="mb-0 px-4 pt-3 pb-2">
<select class="form-control chat-search-client"></select>
</div>
<?php endif; ?>
</div>
<div class="chat-contact-list-item-title">
<h5 class="text-primary mb-0 px-4 pt-3 pb-2">Departamentos</h5>
@ -65,18 +67,21 @@
</div>
<div class="d-flex align-items-center">
<div class="ml-2 px-2">
<button type="button" class="btn btn-danger btn-sm exit-chat">
<i class="ti ti-trash"></i>
<?= lang('Chat.exit_chat') ?>
</button>
</div>
<div class="ml-2 px-2">
<button type="button" class="btn btn-success btn-sm subscribe-chat">
<i class="ti ti-plus"></i>
<?= lang('Chat.subscribe_chat') ?>
</button>
</div>
<?php if (auth()->user()->inGroup('admin')): ?>
<div class="ml-2 px-2">
<button type="button" class="btn btn-danger btn-sm exit-chat">
<i class="ti ti-trash"></i>
<?= lang('Chat.exit_chat') ?>
</button>
</div>
<div class="ml-2 px-2">
<button type="button" class="btn btn-success btn-sm subscribe-chat">
<i class="ti ti-plus"></i>
<?= lang('Chat.subscribe_chat') ?>
</button>
</div>
<?php endif; ?>
<div class="dropdown d-flex align-self-center ml-2 px-2 d-none" id="chat-header-dropdown-users">
<button type="button" class="btn btn-primary btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
<i class="ti ti-users"></i>
@ -113,12 +118,19 @@
<input class="form-control message-input border-0 me-3 shadow-none"
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
<div class="message-actions d-flex align-items-center">
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment" disabled>
<i class="ti ti-send me-md-1 me-0"></i>
<span class="align-middle d-md-inline-block">Enviar</span>
</button>
<?php if (auth()->user()->inGroup('admin')): ?>
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment" disabled>
<i class="ti ti-send me-md-1 me-0"></i>
<span class="align-middle d-md-inline-block">Enviar</span>
</button>
<?php else : ?>
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment-client">
<i class="ti ti-send me-md-1 me-0"></i>
<span class="align-middle d-md-inline-block">Enviar</span>
</button>
<?php endif; ?>
</div>
</div>
</div>

View File

@ -26,9 +26,11 @@
<hr class="container-m-nx m-0" />
<div class="sidebar-body">
<div class="chat-contact-list-item-title">
<div class="mb-0 px-4 pt-3 pb-2">
<select class="form-control chat-search-client"></select>
</div>
<?php if (auth()->user()->inGroup('admin')): ?>
<div class="mb-0 px-4 pt-3 pb-2">
<select class="form-control chat-search-client"></select>
</div>
<?php endif; ?>
</div>
<div class="chat-contact-list-item-title">
@ -67,18 +69,21 @@
</div>
<div class="d-flex align-items-center">
<div class="ml-2 px-2">
<button type="button" class="btn btn-danger btn-sm exit-chat">
<i class="ti ti-trash"></i>
<?= lang('Chat.exit_chat') ?>
</button>
</div>
<div class="ml-2 px-2">
<button type="button" class="btn btn-success btn-sm subscribe-chat">
<i class="ti ti-plus"></i>
<?= lang('Chat.subscribe_chat') ?>
</button>
</div>
<?php if (auth()->user()->inGroup('admin')): ?>
<div class="ml-2 px-2">
<button type="button" class="btn btn-danger btn-sm exit-chat">
<i class="ti ti-trash"></i>
<?= lang('Chat.exit_chat') ?>
</button>
</div>
<div class="ml-2 px-2">
<button type="button" class="btn btn-success btn-sm subscribe-chat">
<i class="ti ti-plus"></i>
<?= lang('Chat.subscribe_chat') ?>
</button>
</div>
<?php endif; ?>
<div class="dropdown d-flex align-self-center ml-2 px-2 d-none" id="chat-header-dropdown-users">
<button type="button" class="btn btn-primary btn-icon rounded-pill dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
<i class="ti ti-users"></i>
@ -112,12 +117,20 @@
<input class="form-control message-input border-0 me-3 shadow-none"
placeholder="<?= lang('Chat.write_message_placeholder') ?>" />
<div class="message-actions d-flex align-items-center">
<?php if (auth()->user()->inGroup('admin')): ?>
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment" disabled>
<i class="ti ti-send me-md-1 me-0"></i>
<span class="align-middle d-md-inline-block">Enviar</span>
</button>
<?php else : ?>
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment-client">
<i class="ti ti-send me-md-1 me-0"></i>
<span class="align-middle d-md-inline-block">Enviar</span>
</button>
<?php endif; ?>
<button type="button" class="btn btn-primary d-flex send-msg-btn" style="color:white"
id="send-msg-btn-deparment" disabled>
<i class="ti ti-send me-md-1 me-0"></i>
<span class="align-middle d-md-inline-block">Enviar</span>
</button>
</div>
</div>
</div>

View File

@ -0,0 +1,46 @@
<form id="<?=$id?>" data-id="<?= $entity->id ?>">
<div class="row">
<div class="col-md-12 mb-2">
<label for="chat-department-display"><?= lang('Chat.datatable_departments.name') ?></label>
<input type="text" name="display" id="chat-department-display" value="<?= $entity->display ?>" class="form-control" />
</div>
<div class="col-md-12 mb-2">
<label for="chat-department-description"><?= lang('Chat.datatable_departments.description') ?></label>
<textarea rows="5" cols="5" type="text" name="description" id="chat-department-description" class="form-control"><?= $entity->description ?></textarea>
</div>
<div class="col-md-12 mb-5">
<button type="button" class="btn btn-primary w-100" id="btn-chat-department-update"><i class="ti icon-base ti-refresh me-2"></i>
<?= lang("App.global_save") ?>
</button>
</div>
</div>
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<div class="accordion accordion-bordered" id="accordionChatDepartmentUser">
<div class="card accordion-item active">
<h2 class="accordion-header">
<button type="button" class="accordion-button" data-bs-toggle="collapse"
data-bs-target="#accordionChatDepartmentUserTip" aria-expanded="false"
aria-controls="accordionChatDepartmentUserTip">
<h4><?= lang("Chat.department_users") ?></h4>
</button>
</h2>
<div id="accordionChatDepartmentUserTip" class="accordion-collapse"
data-bs-parent="#accordionChatDepartment">
<div class="accordion-body">
<div class="col-md-12">
<div class="row">
<div class="col-md-10">
<select id="selectChatDepartmentUser" class="select2 form-select" data-allow-clear="true"></select>
<div id="floatingInputHelp" class="form-text"><?=lang('Chat.help_select_chat_department_user')?></div>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-primary w-100" id="add-user-admin-chat-department"><i class="ti icon-base ti-plus"></i></button>
</div>
</div>
<?= view("themes/vuexy/components/tables/chat_department_users_table", ["id" => "tableChatDepartmentUsers", "entity" => $entity]) ?>
</div>
</div>
</div>
</div>
</div>
</form>

View File

@ -0,0 +1,12 @@
<table id="<?= $id ?>" class="table table-striped table-hover" style="width: 100%;" data-id="<?= $entity->id ?>">
<thead>
<tr>
<th><?= lang('Chat.datatable_department_users.name') ?></th>
<th><?= lang('Chat.datatable_department_users.user') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>

View File

@ -0,0 +1,13 @@
<table id="<?= $id ?>" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th>#</th>
<th><?= lang('Chat.datatable_departments.name') ?></th>
<th><?= lang('Chat.datatable_departments.description') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>

View File

@ -0,0 +1,54 @@
<?= $this->include('themes/_commonPartialsBs/select2bs5') ?>
<?= $this->include('themes/_commonPartialsBs/datatables') ?>
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
<?= $this->extend('themes/vuexy/main/defaultlayout') ?>
<?= $this->section('content'); ?>
<!--Content Body-->
<div class="row">
<div class="col-md-12">
<div class="card card-info">
<div class="card-header">
<h3 class="card-title"><?= lang('Chat.message_configuration') ?></h3>
</div>
<!--//.card-header -->
<div class="card-body">
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<h4 class="card-title"><?= lang('Chat.store_department') ?></h4>
<div class="row d-flex align-item-center">
<div class="col-md-10 mb-2">
<label for="chat-department-display"><?= lang('Chat.datatable_departments.name') ?></label>
<input type="text" name="display" id="chat-department-display" class="form-control" placeholder="<?= lang('Chat.datatable_departments.name') ?>" />
</div>
<div class="col-md-2">
<label for="btn-add-new-chat-department">&nbsp;</label>
<button type="button" class="btn btn-primary btn-sm w-100" id="btn-add-new-chat-department">
<span class="icon-base ti ti-plus icon-xs me-1"></span>
</button>
</div>
</div>
<?= view("themes/vuexy/components/tables/chat_departments_table", ["id" => "tableChatDepartments"]) ?>
</div>
</div>
</div>
</div>
<?= $this->endSection() ?>
<?= $this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/formvalidation/dist/css/formValidation.min.css') ?>" />
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
<?= $this->endSection() ?>
<?= $this->section("additionalExternalJs") ?>
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/FormValidation.js") ?>"></script>
<script src="<?= site_url('themes/vuexy/vendor/libs/popper/popper.js') ?>"></script>
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
<script type="module" src="<?= site_url('assets/js/safekat/pages/configuracion/messages/configView.js') ?>"></script>
<?= $this->endSection() ?>

View File

@ -0,0 +1,38 @@
<?= $this->include('themes/_commonPartialsBs/select2bs5') ?>
<?= $this->include('themes/_commonPartialsBs/datatables') ?>
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
<?= $this->extend('themes/vuexy/main/defaultlayout') ?>
<?= $this->section('content'); ?>
<!--Content Body-->
<div class="row" id="chatDepartmentEditContainer">
<div class="col-md-12">
<div class="card card-info">
<div class="card-header">
<h3 class="card-title"><?= $chat_department->display ?></h3>
</div>
<!--//.card-header -->
<div class="card-body">
<?= view("themes/vuexy/components/forms/chat_department", ["id" => "chatDepartmentForm", "entity" => $chat_department]) ?>
</div>
</div>
</div>
<?= $this->endSection() ?>
<?= $this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/formvalidation/dist/css/formValidation.min.css') ?>" />
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
<?= $this->endSection() ?>
<?= $this->section("additionalExternalJs") ?>
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/FormValidation.js") ?>"></script>
<script src="<?= site_url('themes/vuexy/vendor/libs/popper/popper.js') ?>"></script>
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/Bootstrap5.min.js") ?>"></script>
<script src="<?= site_url("themes/vuexy/vendor/libs/formvalidation/dist/js/plugins/AutoFocus.min.js") ?>"></script>
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
<script type="module" src="<?= site_url('assets/js/safekat/pages/configuracion/messages/editChatDepartmentView.js') ?>"></script>
<?= $this->endSection() ?>

View File

@ -120,6 +120,13 @@ if (
</a>
</li>
<?php } ?>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?>
<li class="menu-item">
<a href="<?= route_to('configMessagesIndex') ?>" class="menu-link">
<?= lang("App.menu_config_messages") ?>
</a>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>