This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/src/Api/Jobs/ListCommentsJob.php

33 lines
847 B
PHP
Raw Normal View History

2014-05-02 09:50:13 +02:00
<?php
class ListCommentsJob extends AbstractPageJob
2014-05-02 09:50:13 +02:00
{
public function execute()
{
$pageSize = $this->getPageSize();
$page = $this->getArgument(JobArgs::ARG_PAGE_NUMBER);
$query = 'comment_min:1 order:comment_date,desc';
2014-05-02 09:50:13 +02:00
$posts = PostSearchService::getEntities($query, $pageSize, $page);
$postCount = PostSearchService::getEntityCount($query);
2014-05-02 13:49:31 +02:00
2014-05-02 09:50:13 +02:00
PostModel::preloadTags($posts);
PostModel::preloadComments($posts);
$comments = [];
foreach ($posts as $post)
$comments = array_merge($comments, $post->getComments());
CommentModel::preloadCommenters($comments);
return $this->getPager($posts, $postCount, $page, $pageSize);
}
public function getDefaultPageSize()
{
return intval(getConfig()->comments->commentsPerPage);
2014-05-02 09:50:13 +02:00
}
public function requiresPrivilege()
{
2014-05-04 16:27:15 +02:00
return new Privilege(Privilege::ListComments);
2014-05-02 09:50:13 +02:00
}
}