aboutsummaryrefslogtreecommitdiffstats
path: root/core/include/post/list.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/include/post/list.php')
-rw-r--r--core/include/post/list.php35
1 files changed, 20 insertions, 15 deletions
diff --git a/core/include/post/list.php b/core/include/post/list.php
index 84de108..4599883 100644
--- a/core/include/post/list.php
+++ b/core/include/post/list.php
@@ -2,16 +2,21 @@
#===============================================================================
# Get instances
#===============================================================================
-$Database = Application::getDatabase();
$Language = Application::getLanguage();
#===============================================================================
+# Get repositories
+#===============================================================================
+$PostRepository = Application::getRepository('Post');
+$UserRepository = Application::getRepository('User');
+
+#===============================================================================
# Pagination
#===============================================================================
$site_size = Application::get('POST.LIST_SIZE');
$site_sort = Application::get('POST.LIST_SORT');
-$count = $Database->query(sprintf('SELECT COUNT(id) FROM %s', Post\Attribute::TABLE))->fetchColumn();
+$count = $PostRepository->getCount();
$lastSite = ceil($count / $site_size);
$currentSite = HTTP::GET('site') ?? 1;
@@ -24,23 +29,23 @@ if($currentSite < 1 OR ($currentSite > $lastSite AND $lastSite > 0)) {
#===============================================================================
# Single redirect
#===============================================================================
-if(Application::get('POST.SINGLE_REDIRECT') === TRUE AND $count === '1') {
- $Statement = $Database->query(sprintf('SELECT id FROM %s LIMIT 1', Post\Attribute::TABLE));
- $Post = Post\Factory::build($Statement->fetchColumn());
+if(Application::get('POST.SINGLE_REDIRECT') === TRUE AND $count === 1) {
+ $Post = $PostRepository->getLast();
HTTP::redirect(Application::getEntityURL($Post));
}
-$execSQL = "SELECT id FROM %s ORDER BY {$site_sort} LIMIT ".(($currentSite-1) * $site_size).", {$site_size}";
-$postIDs = $Database->query(sprintf($execSQL, Post\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN);
+#===============================================================================
+# Get paginated post list
+#===============================================================================
+$posts = $PostRepository->getPaginated(
+ $site_sort,
+ $site_size,
+ ($currentSite-1) * $site_size
+);
-foreach($postIDs as $postID) {
- try {
- $Post = Post\Factory::build($postID);
- $User = User\Factory::build($Post->get('user'));
- $templates[] = generatePostItemTemplate($Post, $User);
- }
- catch(Post\Exception $Exception){}
- catch(User\Exception $Exception){}
+foreach($posts as $Post) {
+ $User = $UserRepository->find($Post->get('user'));
+ $templates[] = generatePostItemTemplate($Post, $User);
}
#===============================================================================