diff --git a/data/config.ini b/data/config.ini index 2adcee5e..9fe2e4f6 100644 --- a/data/config.ini +++ b/data/config.ini @@ -44,7 +44,8 @@ maxRelatedPosts=50 [comments] minLength = 5 maxLength = 2000 -commentsPerPage = 20 +commentsPerPage = 10 +maxCommentsInList = 5 [registration] staffActivation = 0 diff --git a/public_html/media/css/comment-list.css b/public_html/media/css/comment-list.css index 9eaee645..c68e20fd 100644 --- a/public_html/media/css/comment-list.css +++ b/public_html/media/css/comment-list.css @@ -26,3 +26,8 @@ .small-screen .comment-group .comments { margin-left: 0; } + +.hellip { + margin-bottom: 2em; + display: inline-block; +} diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php index 0aa54af1..e4607141 100644 --- a/src/Controllers/CommentController.php +++ b/src/Controllers/CommentController.php @@ -8,27 +8,29 @@ class CommentController */ public function listAction($page) { - $page = intval($page); - $commentsPerPage = intval($this->config->comments->commentsPerPage); PrivilegesHelper::confirmWithException(Privilege::ListComments); - $page = max(1, $page); - $comments = CommentSearchService::getEntities(null, $commentsPerPage, $page); - $commentCount = CommentSearchService::getEntityCount(null); - $pageCount = ceil($commentCount / $commentsPerPage); - CommentModel::preloadCommenters($comments); - CommentModel::preloadPosts($comments); - $posts = array_map(function($comment) { return $comment->getPost(); }, $comments); + $page = max(1, intval($page)); + $commentsPerPage = intval($this->config->comments->commentsPerPage); + $searchQuery = 'comment_min:1 order:comment_date,desc'; + + $posts = PostSearchService::getEntities($searchQuery, $commentsPerPage, $page); + $postCount = PostSearchService::getEntityCount($searchQuery); + $pageCount = ceil($postCount / $commentsPerPage); PostModel::preloadTags($posts); + $comments = []; + foreach ($posts as $post) + $comments = array_merge($comments, $post->getComments()); + CommentModel::preloadCommenters($comments); $this->context->postGroups = true; + $this->context->transport->posts = $posts; $this->context->transport->paginator = new StdClass; $this->context->transport->paginator->page = $page; $this->context->transport->paginator->pageCount = $pageCount; - $this->context->transport->paginator->entityCount = $commentCount; - $this->context->transport->paginator->entities = $comments; + $this->context->transport->paginator->entityCount = $postCount; + $this->context->transport->paginator->entities = $posts; $this->context->transport->paginator->params = func_get_args(); - $this->context->transport->comments = $comments; } diff --git a/src/Models/SearchParsers/PostSearchParser.php b/src/Models/SearchParsers/PostSearchParser.php index 45ad7f85..83c3d8bb 100644 --- a/src/Models/SearchParsers/PostSearchParser.php +++ b/src/Models/SearchParsers/PostSearchParser.php @@ -225,6 +225,9 @@ class PostSearchParser extends AbstractSearchParser elseif (in_array($orderByString, ['tag', 'tags', 'tagcount', 'tag_count'])) $orderColumn = 'tag_count'; + elseif (in_array($orderByString, ['commentdate', 'comment_date'])) + $orderColumn = 'comment_date'; + elseif ($orderByString == 'random') { //seeding works like this: if you visit anything diff --git a/src/Upgrades/mysql/Upgrade12.sql b/src/Upgrades/mysql/Upgrade12.sql new file mode 100644 index 00000000..da5e4a5a --- /dev/null +++ b/src/Upgrades/mysql/Upgrade12.sql @@ -0,0 +1,13 @@ +ALTER TABLE post ADD COLUMN comment_date INTEGER DEFAULT NULL; + +CREATE TRIGGER comment_update_date AFTER UPDATE ON comment FOR EACH ROW +BEGIN + UPDATE post SET comment_date = (SELECT MAX(comment_date) FROM comment WHERE comment.post_id = post.id); +END; + +CREATE TRIGGER comment_insert_date AFTER INSERT ON comment FOR EACH ROW +BEGIN + UPDATE post SET comment_date = (SELECT MAX(comment_date) FROM comment WHERE comment.post_id = post.id); +END; + +UPDATE comment SET id = id; diff --git a/src/Upgrades/sqlite/Upgrade12.sql b/src/Upgrades/sqlite/Upgrade12.sql new file mode 100644 index 00000000..da5e4a5a --- /dev/null +++ b/src/Upgrades/sqlite/Upgrade12.sql @@ -0,0 +1,13 @@ +ALTER TABLE post ADD COLUMN comment_date INTEGER DEFAULT NULL; + +CREATE TRIGGER comment_update_date AFTER UPDATE ON comment FOR EACH ROW +BEGIN + UPDATE post SET comment_date = (SELECT MAX(comment_date) FROM comment WHERE comment.post_id = post.id); +END; + +CREATE TRIGGER comment_insert_date AFTER INSERT ON comment FOR EACH ROW +BEGIN + UPDATE post SET comment_date = (SELECT MAX(comment_date) FROM comment WHERE comment.post_id = post.id); +END; + +UPDATE comment SET id = id; diff --git a/src/Views/comment-list.phtml b/src/Views/comment-list.phtml index 5fc005ff..91caa144 100644 --- a/src/Views/comment-list.phtml +++ b/src/Views/comment-list.phtml @@ -2,7 +2,7 @@ LayoutHelper::setSubTitle('comments'); ?> -context->transport->comments)): ?> +context->transport->posts)): ?>
No comments to show.