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/CommentJobs/ListCommentsJob.php

46 lines
1 KiB
PHP
Raw Normal View History

2014-05-02 09:50:13 +02:00
<?php
class ListCommentsJob extends AbstractJob implements IPagedJob
2014-05-02 09:50:13 +02:00
{
protected $pager;
public function __construct()
{
$this->pager = new JobPager($this);
$this->pager->setPageSize(getConfig()->comments->commentsPerPage);
}
public function getPager()
{
return $this->pager;
}
2014-05-02 09:50:13 +02:00
public function execute()
{
$pageSize = $this->pager->getPageSize();
$page = $this->pager->getPageNumber();
$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->pager->serialize($posts, $postCount);
2014-05-02 09:50:13 +02:00
}
public function getRequiredArguments()
2014-05-12 10:31:34 +02:00
{
return $this->pager->getRequiredArguments();
2014-05-12 10:31:34 +02:00
}
public function getRequiredPrivileges()
2014-05-02 09:50:13 +02:00
{
2014-05-04 16:27:15 +02:00
return new Privilege(Privilege::ListComments);
2014-05-02 09:50:13 +02:00
}
}