From 6576be0c61aec5a66cd6721d44161e44d51f363a Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Mon, 24 Jul 2023 23:28:51 +0300 Subject: [PATCH] =?UTF-8?q?[+]=20=D1=81=D0=BA=D0=BE=D1=80=D1=80=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=80=D1=88=D1=82=D1=83=D1=80=D1=8B=20=D0=B8=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=86=D1=83=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=B0=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Core/App.class.php | 43 ++++++++------------------- core/lib/Core/Models/Dialog.class.php | 2 +- core/lib/Core/Models/Router.class.php | 11 +++++++ core/routes.php | 24 +++++++-------- templates/userProfile.twig | 15 ++++++++++ templates/users.twig | 22 ++++++++++++-- 6 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 templates/userProfile.twig diff --git a/core/lib/Core/App.class.php b/core/lib/Core/App.class.php index b5032d2..61516a1 100644 --- a/core/lib/Core/App.class.php +++ b/core/lib/Core/App.class.php @@ -32,6 +32,7 @@ * Получение параметров для шаблона в целом * * @return array + * @throws CoreException */ private static function getLayoutParams(): array { @@ -60,9 +61,10 @@ * Отдача на рендер * * @param string $template Шаблон - * @param array $params Параметры + * @param array $params Параметры * * @return void + * @throws CoreException */ private static function render(string $template, array $params = []): void { @@ -71,23 +73,11 @@ echo $twig->render($template, $params); } - /** - * Отрисовка главной страницы - * - * @return void - * @throws CoreException - */ public static function index() { self::render('index.twig'); } - /** - * Информация о сборке - * я - * @return void - * @throws CoreException - */ public static function info() { $buildInfo = [ @@ -101,24 +91,12 @@ self::render('info.twig', ['data' => $buildInfo]); } - /** - * Отрисовка диалогов - * - * @return void - * @throws CoreException - */ public static function dialogs() { global $USER; self::render('dialogs.twig', ['dialogs' => User::isAuthorized() ? $USER->getDialogs() : []]); } - /** - * Отрисовка диалога - * - * @return void - * @throws CoreException - */ public static function dialog(int $id) { global $USER; @@ -153,13 +131,10 @@ self::render('users.twig', ['users' => $arUsers]); } - /** - *Тестовая - * - * @return void - */ - public static function test() + + public static function test($a = null, $b = null, $c = null, $d = null) { + print_r([$a, $b, $c, $d]); self::render('test.twig'); } @@ -187,4 +162,10 @@ { self::render('login.twig', ['failed' => true]); } + + public static function userProfile(int $id) + { + $userData = (new User($id))->getAllUserData(true); + self::render('userProfile.twig', ['userData' => $userData]); + } } \ No newline at end of file diff --git a/core/lib/Core/Models/Dialog.class.php b/core/lib/Core/Models/Dialog.class.php index f68ed98..e600a37 100644 --- a/core/lib/Core/Models/Dialog.class.php +++ b/core/lib/Core/Models/Dialog.class.php @@ -70,7 +70,7 @@ /** @var $DB DB Объект базы данных */ $DB = DB::getInstance(); $dialogs = $DB->query( - 'SELECT * FROM ' . self::TABLE_DIALOGS . ' WHERE `send`="' . $this->user->getId() . '" OR `receive`="' . $this->user->getId() . '"' + 'SELECT * FROM ' . self::TABLE_DIALOGS . ' WHERE `send`="' . $this->user->getId() . '" OR `receive`="' . $this->user->getId() . '" ORDER BY `date_updated` DESC' ); if (empty($dialogs)) { return []; diff --git a/core/lib/Core/Models/Router.class.php b/core/lib/Core/Models/Router.class.php index 54d517d..795758e 100644 --- a/core/lib/Core/Models/Router.class.php +++ b/core/lib/Core/Models/Router.class.php @@ -36,6 +36,11 @@ */ private static array $routes = []; + /** + * @var array $paginationRoutes Маршруты, использующие пагинацию + */ + private static array $paginationRoutes = []; + /** * Метод вывода 404 ошибки */ @@ -76,6 +81,12 @@ { array_shift($params); Registry::set('currentPage', $callback); + // Проверка на пагинацию + /*if (preg_match('/\/page\/(\d+)$/', $params[1], $paginationParams)) { + Registry::set('usePagination', true); + Registry::set('page', $paginationParams[1]); + }*/ + return call_user_func_array($callback, array_values($params)); } } diff --git a/core/routes.php b/core/routes.php index 830bf74..6a71e15 100644 --- a/core/routes.php +++ b/core/routes.php @@ -22,8 +22,12 @@ use Core\Models\Router; + Router::route('/404', function () { + header('HTTP/1.0 404 Not Found'); + echo '404 - Page Not Found'; + }); + Router::route('/', '\Core\App::index'); - Router::route('/test', '\Core\App::test', true); Router::route('/info', '\Core\App::info'); Router::route('/login', '\Core\App::login'); @@ -31,29 +35,21 @@ Router::route('/login/failed', '\Core\App::loginFailed'); Router::route('/logout', '\Core\App::logout'); - Router::route('/dialogs', '\Core\App::dialogs'); Router::route('/dialog/(\d+)', '\Core\App::dialog'); Router::route('/users', '\Core\App::users'); + Router::route('/users/(\d+)', '\Core\App::userProfile'); Router::route('/users/(\d+)/sendMessage', '\Core\App::sendMessage'); - Router::route('/404', function () { - header('HTTP/1.0 404 Not Found'); - echo '404 - Page Not Found'; - }); + Router::route('/test', '\Core\App::test', true); + Router::route('/test/(\d+)', '\Core\App::test'); + Router::route('/test/(\d+)/page/(\d+)', '\Core\App::test'); + /** Тестовые маршруты */ Router::route('/sections', '\Core\App::sections'); Router::route('/section/(\d+)', '\Core\App::section'); Router::route('blog/(\w+)/(\d+)', function ($category, $id) { echo $category . ':' . $id; }); - - - - // Router::route('/test/(\d+)', '\Core\App::test'); - - - - diff --git a/templates/userProfile.twig b/templates/userProfile.twig new file mode 100644 index 0000000..b0348ed --- /dev/null +++ b/templates/userProfile.twig @@ -0,0 +1,15 @@ +{% extends 'layout.twig' %} + +{% block title %}Профиль пользователя {{ userData.login }}{% endblock %} + +{% block main %} +

Профиль пользователя {{ userData.login }}

+

+ ID: {{ userData.id }}
+ Логин: {{ userData.login }}
+ Имя: {{ userData.name }}
+ E-Mail: {{ userData.email }}
+ Был активен: {{ userData.last_active }}
+ +

+{% endblock %} \ No newline at end of file diff --git a/templates/users.twig b/templates/users.twig index d83ab07..5e673e7 100644 --- a/templates/users.twig +++ b/templates/users.twig @@ -5,9 +5,25 @@ {% block main %}

Список пользователей

-