diff options
author | Thomas Lange <code@nerdmind.de> | 2021-06-17 22:00:39 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2021-06-17 22:00:39 +0200 |
commit | 5555624546ea48d6327700f32b80848e0662dc90 (patch) | |
tree | 47d61fb756a6cb008aaf33586d292fcfe43da2a1 /admin/index.php | |
parent | 91d8a28c664afa5378735bcd0efe068dd74d589f (diff) | |
parent | 0a2614cb69fc732c2115ef2f0c356f39f602d311 (diff) | |
download | blog-5555624546ea48d6327700f32b80848e0662dc90.tar.gz blog-5555624546ea48d6327700f32b80848e0662dc90.tar.xz blog-5555624546ea48d6327700f32b80848e0662dc90.zip |
Merge branch 'master' into 'optimization'optimization
Diffstat (limited to 'admin/index.php')
-rw-r--r-- | admin/index.php | 109 |
1 files changed, 44 insertions, 65 deletions
diff --git a/admin/index.php b/admin/index.php index 1f8d9f6..788cee4 100644 --- a/admin/index.php +++ b/admin/index.php @@ -11,82 +11,61 @@ define('AUTHENTICATION', TRUE); require '../core/application.php'; #=============================================================================== -# TRY: PDOException +# Fetch last items and item count #=============================================================================== -try { - $execute = 'SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1'; +$execute = 'SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1'; +$LastPageStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE)); +$LastPostStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE)); +$LastUserStatement = $Database->query(sprintf($execute, User\Attribute::TABLE)); - $LastPageStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE)); - $LastPostStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE)); - $LastUserStatement = $Database->query(sprintf($execute, User\Attribute::TABLE)); +$execute = 'SELECT COUNT(*) FROM %s'; +$PageCountStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE)); +$PostCountStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE)); +$UserCountStatement = $Database->query(sprintf($execute, User\Attribute::TABLE)); - $execute = 'SELECT COUNT(*) FROM %s'; +try { + $LastPage = Page\Factory::build($LastPageStatement->fetchColumn()); + $LastPageUser = User\Factory::build($LastPage->attr('user')); - $PageCountStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE)); - $PostCountStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE)); - $UserCountStatement = $Database->query(sprintf($execute, User\Attribute::TABLE)); + $PageItemTemplate = generatePageItemTemplate($LastPage, $LastPageUser); } -#=============================================================================== -# CATCH: PDOException -#=============================================================================== -catch(PDOException $Exception) { - exit($Exception->getMessage()); -} +catch(Page\Exception $Exception){} +catch(User\Exception $Exception){} -#=============================================================================== -# TRY: Template\Exception -#=============================================================================== try { - try { - $LastPage = Page\Factory::build($LastPageStatement->fetchColumn()); - $LastPageUser = User\Factory::build($LastPage->attr('user')); - - $PageItemTemplate = generatePageItemTemplate($LastPage, $LastPageUser); - } - - catch(Page\Exception $Exception){} - catch(User\Exception $Exception){} + $LastPost = Post\Factory::build($LastPostStatement->fetchColumn()); + $LastPostUser = User\Factory::build($LastPost->attr('user')); - try { - $LastPost = Post\Factory::build($LastPostStatement->fetchColumn()); - $LastPostUser = User\Factory::build($LastPost->attr('user')); - - $PostItemTemplate = generatePostItemTemplate($LastPost, $LastPostUser); - } - - catch(Post\Exception $Exception){} - catch(User\Exception $Exception){} - - try { - $LastUser = User\Factory::build($LastUserStatement->fetchColumn()); - $UserItemTemplate = generateUserItemTemplate($LastUser); - } catch(User\Exception $Exception){} - - $HomeTemplate = Template\Factory::build('home'); - $HomeTemplate->set('LAST', [ - 'PAGE' => $PageItemTemplate ?? FALSE, - 'POST' => $PostItemTemplate ?? FALSE, - 'USER' => $UserItemTemplate ?? FALSE, - - ]); + $PostItemTemplate = generatePostItemTemplate($LastPost, $LastPostUser); +} - $HomeTemplate->set('COUNT', [ - 'PAGE' => $PageCountStatement->fetchColumn(), - 'POST' => $PostCountStatement->fetchColumn(), - 'USER' => $UserCountStatement->fetchColumn(), - ]); +catch(Post\Exception $Exception){} +catch(User\Exception $Exception){} - $MainTemplate = Template\Factory::build('main'); - $MainTemplate->set('NAME', 'Dashboard'); - $MainTemplate->set('HTML', $HomeTemplate); - echo $MainTemplate; -} +try { + $LastUser = User\Factory::build($LastUserStatement->fetchColumn()); + $UserItemTemplate = generateUserItemTemplate($LastUser); +} catch(User\Exception $Exception){} #=============================================================================== -# CATCH: Template\Exception +# Build document #=============================================================================== -catch(Template\Exception $Exception) { - Application::exit($Exception->getMessage()); -} -?>
\ No newline at end of file +$HomeTemplate = Template\Factory::build('home'); +$HomeTemplate->set('LAST', [ + 'PAGE' => $PageItemTemplate ?? FALSE, + 'POST' => $PostItemTemplate ?? FALSE, + 'USER' => $UserItemTemplate ?? FALSE, + +]); + +$HomeTemplate->set('COUNT', [ + 'PAGE' => $PageCountStatement->fetchColumn(), + 'POST' => $PostCountStatement->fetchColumn(), + 'USER' => $UserCountStatement->fetchColumn(), +]); + +$MainTemplate = Template\Factory::build('main'); +$MainTemplate->set('NAME', 'Dashboard'); +$MainTemplate->set('HTML', $HomeTemplate); +echo $MainTemplate; |