[+] скорректировал марштуры и добавил страницу пользаков

This commit is contained in:
rsgrinko committed 2023-07-24 23:28:51 +03:00
1 parent 236fd45afa
commit 6576be0c61
6 files changed
+68 -49

No files matched your search

+12 -31
View File
@@ -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]);
}
}
+1 -1
View File
@@ -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 [];
+11
View File
@@ -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));
}
}
+10 -14
View File
@@ -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');
+15
View File
@@ -0,0 +1,15 @@
{% extends 'layout.twig' %}
{% block title %}Профиль пользователя {{ userData.login }}{% endblock %}
{% block main %}
<h1>Профиль пользователя {{ userData.login }}</h1>
<p>
<span>ID: {{ userData.id }}</span><br>
<span>Логин: {{ userData.login }}</span><br>
<span>Имя: {{ userData.name }}</span><br>
<span>E-Mail: {{ userData.email }}</span><br>
<span>Был активен: {{ userData.last_active }}</span><br>
</p>
{% endblock %}
+19 -3
View File
@@ -5,9 +5,25 @@
{% block main %}
<h1>Список пользователей</h1>
<p>
<ul>{% for user in users %}
<li>{{ user.login }}</li>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Логин</th>
<th>Имя</th>
<th></th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ user.id }}</td>
<td>{{ user.login }}</td>
<td>{{ user.name }}</td>
<td><a href="/users/{{ user.id }}">Открыть профиль</a></td>
</tr>
{% endfor %}
</ul>
</tbody>
</table>
</p>
{% endblock %}