From 26323f996b220a52b55643602030e19d37a9cc5e Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 4 May 2014 09:20:13 +0200 Subject: [PATCH] Moved tag autocompleting to API --- public_html/dispatch.php | 2 +- src/Controllers/TagController.php | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/public_html/dispatch.php b/public_html/dispatch.php index 0b7710b3..175a08e4 100644 --- a/public_html/dispatch.php +++ b/public_html/dispatch.php @@ -125,10 +125,10 @@ $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); +\Chibi\Router::register(['TagController', 'autoCompleteView'], 'GET', '/tags-autocomplete', $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); \Chibi\Router::register(['TagController', 'renameAction'], $method, '/tags-rename', $tagValidation); diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index c0b28a33..bc612c98 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -18,16 +18,19 @@ class TagController $context->transport->paginator = $ret; } - public function autoCompleteAction() + public function autoCompleteView() { + $filter = InputHelper::get('search'); + $filter .= ' order:popularity,desc'; + + $ret = Api::run( + (new ListTagsJob)->setPageSize(15), + [ + ListTagsJob::QUERY => $filter, + ListTagsJob::PAGE_NUMBER => 1, + ]); + $context = getContext(); - Access::assert(Privilege::ListTags); - - $suppliedSearch = InputHelper::get('search'); - - $filter = $suppliedSearch . ' order:popularity,desc'; - $tags = TagSearchService::getEntitiesRows($filter, 15, 1); - $context->transport->tags = array_values(array_map( function($tag) @@ -36,7 +39,7 @@ class TagController 'name' => $tag['name'], 'count' => $tag['post_count'] ]; - }, $tags)); + }, $ret->entities)); } public function relatedAction()