Добавлен класс Posts

This commit is contained in:
rsgrinko committed 2022-08-04 23:32:16 +03:00
1 parent d52dd3d0c4
commit 59d398b6ef
104 files changed
+17020 -49

No files matched your search

+33 -12
View File
@@ -21,28 +21,49 @@
namespace Core;
use Core\Models\Posts;
class App
{
public static function index()
{
global $twig, $USER;
$navbarItems = [
['name' => 'Главная', 'url' => '/', 'active' => true],
['name' => 'Админка', 'url' => '/admin', 'active' => false],
['name' => 'Командная PHP строка', 'url' => '/phpcmd.php', 'active' => false],
['name' => 'Тест', 'url' => '/test', 'active' => false],
];
$userData = $USER ? $USER->getAllUserData() : '';
$userRoles = $USER ? $USER->getRolesObject()->getFullRoles() : '';
echo $twig->render(
'index.twig',
[
'navbarItems' => $navbarItems,
'name' => $USER ? $USER->getName() : '',
'emailConfirmed' => $USER ? $USER->isEmailConfirmed() : false,
'user' => $USER,
'userData' => $userData,
'userRoles' => $userRoles
'sections' => (new Posts())->getMainSections(),
'user' => $USER ? $USER->getAllUserData() : null,
]
);
}
public static function sections()
{
global $twig, $USER;
$userData = $USER ? $USER->getAllUserData() : '';
$userRoles = $USER ? $USER->getRolesObject()->getFullRoles() : '';
echo $twig->render(
'sections.twig',
[
'sections' => (new Posts())->getMainSections(),
'user' => $USER ? $USER->getAllUserData() : null,
]
);
}
public static function section($sectionId)
{
global $twig, $USER;
$userData = $USER ? $USER->getAllUserData() : '';
$userRoles = $USER ? $USER->getRolesObject()->getFullRoles() : '';
echo $twig->render(
'section.twig',
[
'sections' => (new Posts())->getMainSections(),
'user' => $USER ? $USER->getAllUserData() : null,
'sectionId' => $sectionId,
]
);
}
+10 -1
View File
@@ -117,11 +117,20 @@
$sql = 'SELECT count(*) as count FROM ' . self::TABLE;
if (!empty($this->sectionId)) {
$sql .= ' WHERE section_id="' . $this->sectionId . '"';
$sql .= ' WHERE section_id = "' . $this->sectionId . '"';
}
$res = $DB->query($sql);
return $res ? (int)$res[0]['count'] : 0;
}
public function getMainSections(): array
{
/** @var $DB DB */
$DB = DB::getInstance();
$res = $DB->query('SELECT id, name, description, image_id FROM ' . self::TABLE_SECTIONS .' WHERE parrent_id = 0');
return $res ?: [];
}
}
+3
View File
@@ -29,6 +29,9 @@
echo '404 - Page Not Found';
});
Router::route('/sections', '\Core\App::sections');
Router::route('/section/(\d+)', '\Core\App::section');
Router::route('blog/(\w+)/(\d+)', function ($category, $id) {
echo $category . ':' . $id;
});