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/Jobs/ListPostsJob.php
Marcin Kurczewski f383a5ed21 Moved JobArgs to Jobs
Reason: trying to make unique string for every possible argument in
global fashion is difficult. For example it would make sense for
EditPostRelationsJob to accept argument named "post-ids", but it
wouldn't make much sense for AddPostJob to accept "post-ids" since it
doesn't tell much. Thus, common arguments are going to be defined in
top-level AbstractJob for ease of control, while more job-specific
arguments are going to be specified in respective job implementations.
2014-05-03 19:25:59 +02:00

41 lines
876 B
PHP

<?php
class ListPostsJob extends AbstractJob
{
public function execute()
{
$page = $this->getArgument(self::PAGE_NUMBER);
$query = $this->getArgument(self::QUERY);
$page = max(1, intval($page));
$postsPerPage = intval(getConfig()->browsing->postsPerPage);
$posts = PostSearchService::getEntities($query, $postsPerPage, $page);
$postCount = PostSearchService::getEntityCount($query);
$pageCount = ceil($postCount / $postsPerPage);
$page = min($pageCount, $page);
PostModel::preloadTags($posts);
$ret = new StdClass;
$ret->posts = $posts;
$ret->postCount = $postCount;
$ret->page = $page;
$ret->pageCount = $pageCount;
return $ret;
}
public function requiresPrivilege()
{
return Privilege::ListPosts;
}
public function requiresAuthentication()
{
return false;
}
public function requiresConfirmedEmail()
{
return false;
}
}