diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php index 6fce8e3c..aeac8357 100644 --- a/src/Controllers/CommentController.php +++ b/src/Controllers/CommentController.php @@ -1,33 +1,21 @@ 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); - PostModel::preloadComments($posts); - $comments = []; - foreach ($posts as $post) - $comments = array_merge($comments, $post->getComments()); - CommentModel::preloadCommenters($comments); + $ret = Api::run( + new ListCommentsJob(), + [ + JobArgs::PAGE_NUMBER => $page, + ]); $context = getContext(); - $context->postGroups = true; - $context->transport->posts = $posts; + $context->transport->posts = $ret->posts; $context->transport->paginator = new StdClass; - $context->transport->paginator->page = $page; - $context->transport->paginator->pageCount = $pageCount; - $context->transport->paginator->entityCount = $postCount; - $context->transport->paginator->entities = $posts; - $context->transport->paginator->params = func_get_args(); + $context->transport->paginator->page = $ret->page; + $context->transport->paginator->pageCount = $ret->pageCount; + $context->transport->paginator->entityCount = $ret->postCount; + $context->transport->paginator->entities = $ret->posts; } public function previewAction() diff --git a/src/Jobs/Abstraction/JobArgs.php b/src/Jobs/Abstraction/JobArgs.php index 677f11c1..0c33f3b6 100644 --- a/src/Jobs/Abstraction/JobArgs.php +++ b/src/Jobs/Abstraction/JobArgs.php @@ -4,4 +4,5 @@ class JobArgs const COMMENT_ID = 'comment-id'; const POST_ID = 'post-id'; const TEXT = 'text'; + const PAGE_NUMBER = 'page-number'; } diff --git a/src/Jobs/ListCommentsJob.php b/src/Jobs/ListCommentsJob.php new file mode 100644 index 00000000..4a2e69d8 --- /dev/null +++ b/src/Jobs/ListCommentsJob.php @@ -0,0 +1,44 @@ +getArgument(JobArgs::PAGE_NUMBER); + + $page = max(1, intval($page)); + $commentsPerPage = intval(getConfig()->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); + PostModel::preloadComments($posts); + $comments = []; + foreach ($posts as $post) + $comments = array_merge($comments, $post->getComments()); + CommentModel::preloadCommenters($comments); + + $ret = new StdClass; + $ret->posts = $posts; + $ret->postCount = $postCount; + $ret->page = $page; + $ret->pageCount = $pageCount; + return $ret; + } + + public function requiresPrivilege() + { + return Privilege::ListComments; + } + + public function requiresAuthentication() + { + return false; + } + + public function requiresConfirmedEmail() + { + return false; + } +}