[*] поправил стиль диалогоа
This commit is contained in:
1 parent
0048e9f9d7
commit
e8be354a1f
8 files changed
+196
-427
No files matched your search
@@ -96,7 +96,7 @@
|
||||
public static function dialogs()
|
||||
{
|
||||
global $USER;
|
||||
self::render('dialogs.twig', ['dialogs' => $USER->getDialogs()]);
|
||||
self::render('dialogs.twig', ['dialogs' => User::isAuthorized() ? $USER->getDialogs() : []]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +108,23 @@
|
||||
public static function dialog(int $id)
|
||||
{
|
||||
global $USER;
|
||||
self::render('dialog.twig', ['messages' => $USER->getMessages($id, true), 'userId' => $USER->getId()]);
|
||||
self::render(
|
||||
'dialog.twig',
|
||||
[
|
||||
'dialog_id' => $id,
|
||||
'messages' => $USER->getMessages($id, true),
|
||||
'userId' => $USER->getId(),
|
||||
'companionId' => $USER->getDialogObject()->getDialogCompanionId($id),
|
||||
'companionName' => (new User($USER->getDialogObject()->getDialogCompanionId($id)))->getName(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public static function sendMessage(int $userId)
|
||||
{
|
||||
global $USER;
|
||||
$USER->getDialogObject()->sendMessage($userId, $_REQUEST['message']);
|
||||
header('Location: /dialog/' . (int)$_REQUEST['dialogId']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -78,10 +78,37 @@
|
||||
return $dialogs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получения ID собеседника диалога
|
||||
*
|
||||
* @param int $dialogId Идентификатор диалога
|
||||
*
|
||||
* @return int|null Идентификатор собеседника
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function getDialogCompanionId(int $dialogId): ?int
|
||||
{
|
||||
/** @var $DB DB Объект базы данных */
|
||||
$DB = DB::getInstance();
|
||||
$dialog = $DB->query('SELECT * FROM ' . self::TABLE_DIALOGS . ' WHERE `id`="' . $dialogId . '"');
|
||||
if (empty($dialog)) {
|
||||
return null;
|
||||
}
|
||||
$dialog = array_shift($dialog);
|
||||
if ((int)$dialog['send'] === $this->user->getId()) {
|
||||
return (int)$dialog['receive'];
|
||||
} elseif ((int)$dialog['receive'] === $this->user->getId()) {
|
||||
return (int)$dialog['send'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение сообщений диалога
|
||||
*
|
||||
* @param int $dialogId
|
||||
* @param int $dialogId Идентификатор диаолога
|
||||
* @param bool $markDialogViewed Пометить диалог прочитанным
|
||||
*
|
||||
* @return array
|
||||
* @throws CoreException
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
} else {
|
||||
$result = (DB::getInstance())->getItem(self::TABLE, ['id' => $this->id]);
|
||||
$result = array_merge($result, ['roles' => $this->getRolesObject()->getRoles()]);
|
||||
$result['nameForDisplay'] = '[' . $result['id'] . '] (' . $result['login'] . ') ' . $result['name'];
|
||||
|
||||
// В случае запроса безопасных данных убираем лишнее
|
||||
if ($onlySecureData) {
|
||||
@@ -901,8 +902,8 @@
|
||||
{
|
||||
$dialogs = $this->getDialogObject()->getDialogs();
|
||||
foreach ($dialogs as $key => $dialog) {
|
||||
$dialogs[$key]['send_user_data'] = (new self((int)$dialog['send']))->getAllUserData(true);
|
||||
$dialogs[$key]['receive_user_data'] = (new self((int)$dialog['receive']))->getAllUserData(true);
|
||||
$dialogs[$key]['companionId'] = $this->getDialogObject()->getDialogCompanionId((int)$dialog['id']);
|
||||
$dialogs[$key]['companionData'] = (new self((int)$dialogs[$key]['companionId']))->getAllUserData(true);
|
||||
}
|
||||
|
||||
return $dialogs;
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
Router::route('/dialogs', '\Core\App::dialogs');
|
||||
Router::route('/dialog/(\d+)', '\Core\App::dialog');
|
||||
|
||||
Router::route('/users/(\d+)/sendMessage', '\Core\App::sendMessage');
|
||||
|
||||
Router::route('/404', function () {
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
echo '404 - Page Not Found';
|
||||
|
||||
Reference in new issue
Block a user