[*] скорректировал работу диалогов

[+] добавил jquery в публичную часть
This commit is contained in:
rsgrinko committed 2023-08-08 23:55:27 +03:00
1 parent 94f387b072
commit 27ba47465f
10 files changed
+108 -12

No files matched your search

+14
View File
@@ -78,6 +78,20 @@
require_once $_SERVER['DOCUMENT_ROOT'] . '/config.local.php';
}
function dd($data): void
{
echo '<pre>';
print_r($data);
echo '</pre>';
}
function ddd($data): void
{
echo '<pre>';
print_r($data);
echo '</pre>';
die();
}
/**
* Реализация механизма автозагрузки классов
+11 -2
View File
@@ -24,7 +24,7 @@
use Core\Helpers\Pagination;
use Core\Helpers\Registry;
use Core\Helpers\SystemFunctions;
use Core\Models\{Posts, User};
use Core\Models\{File, Posts, User};
class App
{
@@ -57,6 +57,7 @@
'isAdmin' => User::isAuthorized() && $USER->isAdmin(),
'userData' => User::isAuthorized() ? $USER->getAllUserData(true) : [],
'currentYear' => date('Y'),
'newMessages' => User::isAuthorized() ? $USER->getDialogObject()->getUnviewedMessagesCount() : 0,
];
}
@@ -121,7 +122,15 @@
{
/** @var User $USER */
global $USER;
$USER->getDialogObject()->sendMessage($userId, $_REQUEST['message']);
if (empty($_FILES['file']['tmp_name'])) {
$USER->getDialogObject()->sendMessage($userId, $_REQUEST['message']);
} else {
$fileObject = new File();
$fileObject->saveFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], true);
$USER->getDialogObject()->sendFile($userId, $fileObject->getId(), in_array($_FILES['file']['type'], ['image/jpeg', 'image/png', 'image/gif', 'image/webp'], true));
}
header('Location: /dialog/' . (int)$_REQUEST['dialogId']);
}
+19 -5
View File
@@ -137,7 +137,7 @@
{
/** @var $DB DB Объект базы данных */
$DB = DB::getInstance();
$messages = $DB->query('SELECT * FROM ' . self::TABLE_MESSAGES . ' WHERE `dialog_id`="' . $dialogId . '"');
$messages = $DB->query('SELECT * FROM ' . self::TABLE_MESSAGES . ' WHERE `dialog_id`="' . $dialogId . '" ORDER BY id ASC');
if ($markDialogViewed) {
$this->markDialogViewed($dialogId);
}
@@ -173,12 +173,14 @@
/**
* Отправка файлов
*
* @param int $fileId
*
* @param int $to
* @param int $fileId
* @param bool $sendAsImage
*
* @return bool
* @throws CoreException
*/
public function sendFile(int $to, int $fileId): bool
public function sendFile(int $to, int $fileId, bool $sendAsImage = false): bool
{
if (!User::isUserExistsByParams(['id' => $to])) {
throw new CoreException('Пользователь с идентификатором ' . $to . ' отсутствует в базе', CoreException::ERROR_USER_NOT_FOUND);
@@ -192,7 +194,7 @@
$DB->update(self::TABLE_DIALOGS, ['id' => $dialogId], ['viewed'=> CODE_VALUE_N, 'send' => $this->user->getId(), 'receive' => $to]);
}
$result = $DB->addItem(self::TABLE_MESSAGES, ['dialog_id' => $dialogId, 'type' => self::MESSAGE_TYPE_FILE, 'user_from' => $this->user->getId(), 'user_to' => $to, 'text' => $fileId]);
$result = $DB->addItem(self::TABLE_MESSAGES, ['dialog_id' => $dialogId, 'type' => $sendAsImage ? self::MESSAGE_TYPE_IMAGE : self::MESSAGE_TYPE_FILE, 'user_from' => $this->user->getId(), 'user_to' => $to, 'text' => $fileId]);
return (int)$result > 0;
}
@@ -210,5 +212,17 @@
return $DB->getCountItems(self::TABLE_MESSAGES, ['dialog_id' => $dialogId, 'viewed' => CODE_VALUE_N, 'user_to' => $this->user->getId()]);
}
/**
* Получение количества непрочитанных сообщений
*
* @return int Количество
*/
public function getUnviewedMessagesCount(): int
{
/** @var $DB DB Объект базы данных */
$DB = DB::getInstance();
return $DB->getCountItems(self::TABLE_MESSAGES, ['viewed' => CODE_VALUE_N, 'user_to' => $this->user->getId()]);
}
}