aboutsummaryrefslogtreecommitdiffstats
path: root/admin/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'admin/index.php')
-rw-r--r--admin/index.php109
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;