diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2019-02-26 18:11:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-26 18:11:24 +0100 |
commit | a3d936fbb7c8356a39308d836282b4ee6b2abdc1 (patch) | |
tree | ce0983e0c4d59d53d8f1a07d7fdd3b6b31356deb /core | |
parent | 0051bb7e4cd890793edac99d5b6475457c8580f3 (diff) | |
parent | 55f627d20b6eacb1773381ea4325d2159f9c3103 (diff) | |
download | nextcloud-server-a3d936fbb7c8356a39308d836282b4ee6b2abdc1.tar.gz nextcloud-server-a3d936fbb7c8356a39308d836282b4ee6b2abdc1.zip |
Merge pull request #14385 from nextcloud/feature/noid/add-event-to-allow-to-filter-results
Add an event to the Autocomplete Controller to allow to filter the re…
Diffstat (limited to 'core')
-rw-r--r-- | core/Controller/AutoCompleteController.php | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/core/Controller/AutoCompleteController.php b/core/Controller/AutoCompleteController.php index 3f3858ce1c8..80f5d3c8630 100644 --- a/core/Controller/AutoCompleteController.php +++ b/core/Controller/AutoCompleteController.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> * @@ -25,27 +26,33 @@ namespace OC\Core\Controller; use OCP\AppFramework\OCSController as Controller; use OCP\AppFramework\Http\DataResponse; +use OCP\Collaboration\AutoComplete\AutoCompleteEvent; use OCP\Collaboration\AutoComplete\IManager; use OCP\Collaboration\Collaborators\ISearch; use OCP\IRequest; use OCP\Share; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; class AutoCompleteController extends Controller { /** @var ISearch */ private $collaboratorSearch; /** @var IManager */ private $autoCompleteManager; + /** @var EventDispatcherInterface */ + private $dispatcher; public function __construct( - $appName, + string $appName, IRequest $request, ISearch $collaboratorSearch, - IManager $autoCompleteManager + IManager $autoCompleteManager, + EventDispatcherInterface $dispatcher ) { parent::__construct($appName, $request); $this->collaboratorSearch = $collaboratorSearch; $this->autoCompleteManager = $autoCompleteManager; + $this->dispatcher = $dispatcher; } /** @@ -59,10 +66,22 @@ class AutoCompleteController extends Controller { * @param int $limit * @return DataResponse */ - public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER], $limit = 10) { + public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER], $limit = 10): DataResponse { // if enumeration/user listings are disabled, we'll receive an empty // result from search() – thus nothing else to do here. - list($results,) = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); + [$results,] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); + + $event = new AutoCompleteEvent([ + 'search' => $search, + 'results' => $results, + 'itemType' => $itemType, + 'itemId' => $itemId, + 'sorter' => $sorter, + 'shareTypes' => $shareTypes, + 'limit' => $limit, + ]); + $this->dispatcher->dispatch(IManager::class . '::filterResults', $event); + $results = $event->getResults(); $exactMatches = $results['exact']; unset($results['exact']); @@ -83,7 +102,7 @@ class AutoCompleteController extends Controller { } - protected function prepareResultArray(array $results) { + protected function prepareResultArray(array $results): array { $output = []; foreach ($results as $type => $subResult) { foreach ($subResult as $result) { |