Moved tag listing to API
This commit is contained in:
parent
259eabfaaa
commit
97c17c68a0
6 changed files with 68 additions and 43 deletions
|
@ -116,18 +116,18 @@ $commentValidation =
|
|||
\Chibi\Router::register(['CommentController', 'editView'], 'GET', '/comment/{id}/edit', $commentValidation);
|
||||
\Chibi\Router::register(['CommentController', 'editAction'], 'POST', '/comment/{id}/edit', $commentValidation);
|
||||
|
||||
foreach (['GET', 'POST'] as $method)
|
||||
{
|
||||
$tagValidation =
|
||||
[
|
||||
'page' => '\d*',
|
||||
'filter' => '[^\/]+',
|
||||
];
|
||||
|
||||
\Chibi\Router::register(['TagController', 'listAction'], $method, '/tags', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'listAction'], $method, '/tags/{filter}', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'listAction'], $method, '/tags/{page}', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'listAction'], $method, '/tags/{filter}/{page}', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'listView'], 'GET', '/tags', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'listView'], 'GET', '/tags/{page}', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'listView'], 'GET', '/tags/{filter}/{page}', $tagValidation);
|
||||
|
||||
foreach (['GET', 'POST'] as $method)
|
||||
{
|
||||
\Chibi\Router::register(['TagController', 'autoCompleteAction'], $method, '/tags-autocomplete', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'relatedAction'], $method, '/tags-related', $tagValidation);
|
||||
\Chibi\Router::register(['TagController', 'mergeAction'], $method, '/tags-merge', $tagValidation);
|
||||
|
|
39
src/Api/Jobs/ListTagsJob.php
Normal file
39
src/Api/Jobs/ListTagsJob.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
class ListTagsJob extends AbstractJob
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
$page = $this->getArgument(self::PAGE_NUMBER);
|
||||
$query = $this->getArgument(self::QUERY);
|
||||
|
||||
$page = max(1, intval($page));
|
||||
$tagsPerPage = intval(getConfig()->browsing->tagsPerPage);
|
||||
|
||||
$tags = TagSearchService::getEntitiesRows($query, $tagsPerPage, $page);
|
||||
$tagCount = TagSearchService::getEntityCount($query);
|
||||
$pageCount = ceil($tagCount / $tagsPerPage);
|
||||
$page = min($pageCount, $page);
|
||||
|
||||
$ret = new StdClass;
|
||||
$ret->tags = $tags;
|
||||
$ret->tagCount = $tagCount;
|
||||
$ret->page = $page;
|
||||
$ret->pageCount = $pageCount;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function requiresPrivilege()
|
||||
{
|
||||
return Privilege::ListTags;
|
||||
}
|
||||
|
||||
public function requiresAuthentication()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function requiresConfirmedEmail()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,39 +1,25 @@
|
|||
<?php
|
||||
class TagController
|
||||
{
|
||||
public function listAction($filter = null, $page = 1)
|
||||
public function listView($filter = 'order:alpha,asc', $page = 1)
|
||||
{
|
||||
$ret = Api::run(
|
||||
new ListTagsJob(),
|
||||
[
|
||||
ListTagsJob::PAGE_NUMBER => $page,
|
||||
ListTagsJob::QUERY => $filter,
|
||||
]);
|
||||
|
||||
$context = getContext();
|
||||
$context->viewName = 'tag-list-wrapper';
|
||||
Access::assert(Privilege::ListTags);
|
||||
|
||||
$suppliedFilter = $filter ?: 'order:alpha,asc';
|
||||
$page = max(1, intval($page));
|
||||
$tagsPerPage = intval(getConfig()->browsing->tagsPerPage);
|
||||
|
||||
$tags = TagSearchService::getEntitiesRows($suppliedFilter, $tagsPerPage, $page);
|
||||
$tagCount = TagSearchService::getEntityCount($suppliedFilter);
|
||||
$pageCount = ceil($tagCount / $tagsPerPage);
|
||||
$page = min($pageCount, $page);
|
||||
|
||||
$context->filter = $suppliedFilter;
|
||||
$context->transport->tags = $tags;
|
||||
|
||||
if ($context->json)
|
||||
{
|
||||
$context->transport->tags = array_values(array_map(function($tag) {
|
||||
return ['name' => $tag['name'], 'count' => $tag['post_count']];
|
||||
}, $context->transport->tags));
|
||||
}
|
||||
else
|
||||
{
|
||||
$context->highestUsage = TagSearchService::getMostUsedTag()['post_count'];
|
||||
$context->filter = $filter;
|
||||
$context->transport->tags = $ret->tags;
|
||||
$context->transport->paginator = new StdClass;
|
||||
$context->transport->paginator->page = $page;
|
||||
$context->transport->paginator->pageCount = $pageCount;
|
||||
$context->transport->paginator->entityCount = $tagCount;
|
||||
$context->transport->paginator->entities = $tags;
|
||||
}
|
||||
$context->transport->paginator->page = $ret->page;
|
||||
$context->transport->paginator->pageCount = $ret->pageCount;
|
||||
$context->transport->paginator->entityCount = $ret->tagCount;
|
||||
$context->transport->paginator->entities = $ret->tags;
|
||||
}
|
||||
|
||||
public function autoCompleteAction()
|
||||
|
|
|
@ -3,7 +3,7 @@ Assets::setSubTitle('tags');
|
|||
Assets::addStylesheet('tag-list.css');
|
||||
|
||||
$tabs = [];
|
||||
if (Access::check(Privilege::ListTags)) $tabs['list'] = ['List', 'listAction'];
|
||||
if (Access::check(Privilege::ListTags)) $tabs['list'] = ['List', 'listView'];
|
||||
if (Access::check(Privilege::RenameTags)) $tabs['rename'] = ['Rename', 'renameAction'];
|
||||
if (Access::check(Privilege::MergeTags)) $tabs['merge'] = ['Merge', 'mergeAction'];
|
||||
if (Access::check(Privilege::MassTag)) $tabs['mass-tag-redirect'] = ['Mass tag', 'massTagRedirectAction'];
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<?php else: ?>
|
||||
<li>
|
||||
<?php endif ?>
|
||||
<a href="<?= \Chibi\Router::linkTo(['TagController', 'listAction'], ['filter' => $key]) ?>"><?= $text ?></a>
|
||||
<a href="<?= \Chibi\Router::linkTo(['TagController', 'listView'], ['filter' => $key]) ?>"><?= $text ?></a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
{
|
||||
$registerNavItem(
|
||||
'Tags',
|
||||
\Chibi\Router::linkTo(['TagController', 'listAction']),
|
||||
\Chibi\Router::linkTo(['TagController', 'listView']),
|
||||
$activeController == 'tag');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue