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 %} +
+ ID: {{ userData.id }}
+ Логин: {{ userData.login }}
+ Имя: {{ userData.name }}
+ E-Mail: {{ userData.email }}
+ Был активен: {{ userData.last_active }}
+
+
-
| ID | +Логин | +Имя | ++ |
|---|---|---|---|
| {{ user.id }} | +{{ user.login }} | +{{ user.name }} | +Открыть профиль | +