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.
41 lines
876 B
PHP
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;
|
|
}
|
|
}
|