Files
szurubooru/src/Api/Jobs/CommentJobs/ListCommentsJob.php
Marcin Kurczewski e59b7e8b7b Refactored privilege system a bit
- Jobs specify main privilege and sub privileges separately
  Rationale: increase maintenance, restrict what can be done runtime
- Renamed ChangeUser* to EditUser* (consistency with EditPost*)
- Simplified enum names and configuration reading
- IJob interface members must be explicitly implemented
  Rationale: reduce chances of forgetting something, or typos in
  inherited method names
- Invalid privileges names in configuration yield exceptions
2014-05-18 21:59:56 +02:00

61 lines
1.2 KiB
PHP

<?php
class ListCommentsJob extends AbstractJob implements IPagedJob
{
protected $pager;
public function __construct()
{
$this->pager = new JobPager($this);
$this->pager->setPageSize(Core::getConfig()->comments->commentsPerPage);
}
public function getPager()
{
return $this->pager;
}
public function execute()
{
$pageSize = $this->pager->getPageSize();
$page = $this->pager->getPageNumber();
$query = 'comment_min:1 order:comment_date,desc';
$posts = PostSearchService::getEntities($query, $pageSize, $page);
$postCount = PostSearchService::getEntityCount($query);
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);
}
public function getRequiredArguments()
{
return $this->pager->getRequiredArguments();
}
public function getRequiredMainPrivilege()
{
return Privilege::ListComments;
}
public function getRequiredSubPrivileges()
{
return null;
}
public function isAuthenticationRequired()
{
return false;
}
public function isConfirmedEmailRequired()
{
return false;
}
}