mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
messages view
This commit is contained in:
@ -11,10 +11,13 @@ use App\Models\ChatNotification;
|
||||
use App\Models\ChatUser;
|
||||
use App\Models\Clientes\ClienteModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use App\Services\MessageService;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\Log\Logger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Hermawan\DataTables\DataTable;
|
||||
use CodeIgniter\I18n\Time;
|
||||
|
||||
class ChatController extends BaseController
|
||||
{
|
||||
@ -27,7 +30,7 @@ class ChatController extends BaseController
|
||||
protected ChatUser $chatUserModel;
|
||||
protected ChatNotification $chatNotificationModel;
|
||||
|
||||
|
||||
protected static $viewPath = 'themes/vuexy/form/mensajes/';
|
||||
|
||||
|
||||
public function initController(
|
||||
@ -108,6 +111,16 @@ class ChatController extends BaseController
|
||||
$data["chat"] = $chat;
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_chat_direct_view($chat_id){
|
||||
$chat = $this->chatModel->find($chat_id);
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("Chat.chat"), 'route' => route_to("mensajeriaView"), 'active' => false],
|
||||
['title' => $chat->title, 'route' => 'javascript:void(0);', 'active' => true]
|
||||
];
|
||||
$this->viewData["chatId"] = $chat_id;
|
||||
|
||||
return view(static::$viewPath . 'messageChat', $this->viewData);
|
||||
}
|
||||
public function get_chat(int $chat_id)
|
||||
{
|
||||
|
||||
@ -428,5 +441,75 @@ class ChatController extends BaseController
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
|
||||
public function datatable_messages()
|
||||
{
|
||||
$query = $this->chatModel->getQueryDatatable();
|
||||
$auth_user_id = auth()->user()->id;
|
||||
return DataTable::of($query)
|
||||
->edit('created_at',fn($q) => Time::createFromFormat('Y-m-d H:i:s',$q->created_at)->format("d/m/Y H:i"))
|
||||
->edit('updated_at',fn($q) => Time::createFromFormat('Y-m-d H:i:s',$q->updated_at)->format("d/m/Y H:i"))
|
||||
->add("creator", fn($q) => $this->chatModel->getChatFirstUser($q->id)->userFullName)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id,$auth_user_id))
|
||||
->add("action", fn($q) => $q->id)
|
||||
->toJson(true);
|
||||
}
|
||||
public function store_new_direct_message()
|
||||
{
|
||||
$bodyData = $this->request->getPost();
|
||||
$rules = [
|
||||
"title" => "required|string",
|
||||
"message" => "required|string",
|
||||
"users" => "required",
|
||||
|
||||
];
|
||||
if(!$this->validate($rules)){
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
'message' => lang('App.global_alert_save_error'),
|
||||
'status' => 'error',
|
||||
'errors' => $this->validator->getErrors(),
|
||||
]);
|
||||
}
|
||||
$this->chatModel->createNewDirectChat(...$bodyData);
|
||||
return $this->response->setJSON(["message" => lang("Chat.new_message_ok"),"status" => true]);
|
||||
|
||||
}
|
||||
public function get_chat_direct($chat_id){
|
||||
$chatData = $this->chatModel->getChatDirect($chat_id);
|
||||
return $this->response->setJSON($chatData);
|
||||
}
|
||||
public function get_chat_direct_select_users($chat_id){
|
||||
$chat_users_id = $this->chatUserModel->getChatUserArrayId($chat_id);
|
||||
|
||||
$query = $this->userModel->builder()->select(
|
||||
[
|
||||
"id",
|
||||
"CONCAT(first_name,' ',last_name,'(',username,')') as name"
|
||||
]
|
||||
)->where("cliente_id", null)
|
||||
->where("deleted_at", null)
|
||||
->whereNotIn("id",$chat_users_id);
|
||||
if ($this->request->getGet("q")) {
|
||||
$query->groupStart()
|
||||
->orLike("users.username", $this->request->getGet("q"))
|
||||
->orLike("CONCAT(first_name,' ',last_name)", $this->request->getGet("q"))
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
return $this->response->setJSON($query->get()->getResultObject());
|
||||
}
|
||||
public function store_chat_direct_users($chat_id){
|
||||
$bodyData = $this->request->getPost();
|
||||
$chat_users = array_map(fn($q) => ["chat_id" => $chat_id,"user_id" => $q],$bodyData["users"]);
|
||||
$this->chatUserModel->insertBatch($chat_users);
|
||||
return $this->response->setJSON(["message" => "ok","status" => true]);
|
||||
}
|
||||
public function store_chat_direct_message(int $chat_id){
|
||||
$bodyData = $this->request->getPost();
|
||||
$bodyData["sender_id"] = auth()->user()->id;
|
||||
$chat_message_id = $this->chatMessageModel->insert($bodyData);
|
||||
$message = $this->chatMessageModel->get_chat_message($chat_message_id);
|
||||
return $this->response->setJSON($message);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user