исправление и симпатизация метода вывода таблицы из массива

This commit is contained in:
rsgrinko committed 2022-04-26 23:36:59 +03:00
1 parent e6ca126f07
commit 0cb150b0e4
2 files changed
+23 -18

No files matched your search

@@ -332,19 +332,23 @@
*/
public static function arrayToTable($var, string $title = ''): ?string
{
$tableStyle = 'border: 1px solid #7b9ea3;border-collapse: collapse;';
$tdBoldStyle = 'padding: 10px;border: 1px solid #7b9ea3;background: powderblue;font-weight: bold; text-align: center;';
$tdStyle = 'padding: 10px;border: 1px solid #7b9ea3;';
$thStyle = 'background: #b0e0e6;font-size: 1.3em;padding: 10px;';
if (is_array($var)) {
$table = '<table>';
$table = '<table style="' . $tableStyle . '">';
if ($title) {
$table .= '<tr><th colspan="20">' . $title . '</th></tr>';
$table .= '<tr><th colspan="20" style="' . $thStyle . '">' . $title . '</th></tr>';
}
foreach ($var as $k => $v) {
$table .= '<tr>';
$table .= '<td><b>' . htmlspecialchars($k) . '</b></td>';
$table .= '<td>';
$table .= '<td style="' . $tdBoldStyle . '">' . htmlspecialchars($k) . '</td>';
$table .= '<td style="' . $tdStyle . '">';
if (is_array($v)) {
$table .= self::arrayToTable($v);
} else {
$table .= htmlspecialchars($v);
$table .= '<pre>' . htmlspecialchars($v) . '</pre>';
}
$table .= '</td>';
$table .= '</tr>';
+14 -13
View File
@@ -2,42 +2,43 @@
use Core\CoreException;
use Core\ExternalServices\Telegram;
use Core\Models\User;
use Core\Models\{User, DB};
use Core\Helpers\{SystemFunctions, Cache, Log, Mail, Zip};
require_once $_SERVER['DOCUMENT_ROOT'] . '/core/bootstrap.php';
Log::logToFile('Скрипт начал свою работу', 'test.log');
echo '<a href="/admin/">{{ADMIN_PANEL_LINK_NAME}}</a> | <a href="/?clear_cache=Y">{{CLEAR_CACHE_LINK_NAME}}</a> | <a href="/">{{REFRESH_PAGE_LINK_NAME}}</a> <br>';
Telegram::init('5232660453:AAGfMWu6EcRfBGSSURJsEEvGPmAqhCyzYHU', './');
//$userId = User::registration('test', '12345', 'support@it-stories.ru', 'user', 'Тестировщик', 'http://samag.ru/uploads/5222447.png');
/*if (isset($_REQUEST['log']) && $_REQUEST['log'] === CODE_VALUE_Y) {
Log::logToFile('Тестовое сообщение в лог', 'test.log', $_REQUEST);
}*/
/*$user = new User($userId);*/
$userId = User::getCurrentUserId();
Log::logToFile('Проверка пользователя на авторизованность', 'test.log', ['userId' => $userId]);
try {
$user = new User($userId);
User::authorize((int)$userId);
echo 'Current user id: ' . $userId . '<br>';
} catch (CoreException $e) {
Log::logToFile('CoreException: ' . $e->getMessage(), 'test.log', $_REQUEST);
echo $e->showTrace();
}
echo '<br><br>';
if (User::isAuthorized()) {
Log::logToFile('Пользователь авторизован, выводим данные о нем', 'test.log', $user->getAllUserData());
echo SystemFunctions::arrayToTable($user->getAllUserData(), 'Информация о пользователе');
}
echo SystemFunctions::arrayToTable(Cache::getCacheInfo(), 'Информация о кэше');
$arPosts = (DB::getInstance())->query('select * from d_posts where post_type="post" and post_status="publish" order by id desc limit 10');
$arResult = [];
foreach($arPosts as $post) {
$arResult[] = [
'title' => $post['post_title'],
'postname' => $post['post_name'],
'date' => $post['post_date'],
'userId' => $post['post_author'],
'userName' => (new User((int)$post['post_author']))->getName()
Log::logToFile('Скрипт завершил свою работу', 'test.log');
];
}
echo SystemFunctions::arrayToTable($arResult, 'Статьи');