@@ -30,70 +30,70 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class AutoCompleteEvent extends GenericEvent { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param array $arguments |
|
| 35 | - * @since 16.0.0 |
|
| 36 | - */ |
|
| 37 | - public function __construct(array $arguments) { |
|
| 38 | - parent::__construct(null, $arguments); |
|
| 39 | - } |
|
| 33 | + /** |
|
| 34 | + * @param array $arguments |
|
| 35 | + * @since 16.0.0 |
|
| 36 | + */ |
|
| 37 | + public function __construct(array $arguments) { |
|
| 38 | + parent::__construct(null, $arguments); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @since 16.0.0 |
|
| 43 | - */ |
|
| 44 | - public function getResults(): array { |
|
| 45 | - return $this->getArgument('results'); |
|
| 46 | - } |
|
| 41 | + /** |
|
| 42 | + * @since 16.0.0 |
|
| 43 | + */ |
|
| 44 | + public function getResults(): array { |
|
| 45 | + return $this->getArgument('results'); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param array $results |
|
| 50 | - * @since 16.0.0 |
|
| 51 | - */ |
|
| 52 | - public function setResults(array $results): void { |
|
| 53 | - $this->setArgument('results', $results); |
|
| 54 | - } |
|
| 48 | + /** |
|
| 49 | + * @param array $results |
|
| 50 | + * @since 16.0.0 |
|
| 51 | + */ |
|
| 52 | + public function setResults(array $results): void { |
|
| 53 | + $this->setArgument('results', $results); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @since 16.0.0 |
|
| 58 | - */ |
|
| 59 | - public function getSearchTerm(): string { |
|
| 60 | - return $this->getArgument('search'); |
|
| 61 | - } |
|
| 56 | + /** |
|
| 57 | + * @since 16.0.0 |
|
| 58 | + */ |
|
| 59 | + public function getSearchTerm(): string { |
|
| 60 | + return $this->getArgument('search'); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @return int[] |
|
| 65 | - * @since 16.0.0 |
|
| 66 | - */ |
|
| 67 | - public function getShareTypes(): array { |
|
| 68 | - return $this->getArgument('shareTypes'); |
|
| 69 | - } |
|
| 63 | + /** |
|
| 64 | + * @return int[] |
|
| 65 | + * @since 16.0.0 |
|
| 66 | + */ |
|
| 67 | + public function getShareTypes(): array { |
|
| 68 | + return $this->getArgument('shareTypes'); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @since 16.0.0 |
|
| 73 | - */ |
|
| 74 | - public function getItemType(): string { |
|
| 75 | - return $this->getArgument('itemType'); |
|
| 76 | - } |
|
| 71 | + /** |
|
| 72 | + * @since 16.0.0 |
|
| 73 | + */ |
|
| 74 | + public function getItemType(): string { |
|
| 75 | + return $this->getArgument('itemType'); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @since 16.0.0 |
|
| 80 | - */ |
|
| 81 | - public function getItemId(): string { |
|
| 82 | - return $this->getArgument('itemId'); |
|
| 83 | - } |
|
| 78 | + /** |
|
| 79 | + * @since 16.0.0 |
|
| 80 | + */ |
|
| 81 | + public function getItemId(): string { |
|
| 82 | + return $this->getArgument('itemId'); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @since 16.0.0 |
|
| 87 | - */ |
|
| 88 | - public function getSorter(): string { |
|
| 89 | - return $this->getArgument('sorter'); |
|
| 90 | - } |
|
| 85 | + /** |
|
| 86 | + * @since 16.0.0 |
|
| 87 | + */ |
|
| 88 | + public function getSorter(): string { |
|
| 89 | + return $this->getArgument('sorter'); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @since 16.0.0 |
|
| 94 | - */ |
|
| 95 | - public function getLimit(): int { |
|
| 96 | - return $this->getArgument('limit'); |
|
| 97 | - } |
|
| 92 | + /** |
|
| 93 | + * @since 16.0.0 |
|
| 94 | + */ |
|
| 95 | + public function getLimit(): int { |
|
| 96 | + return $this->getArgument('limit'); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | } |
@@ -34,85 +34,85 @@ |
||
| 34 | 34 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 35 | 35 | |
| 36 | 36 | class AutoCompleteController extends Controller { |
| 37 | - /** @var ISearch */ |
|
| 38 | - private $collaboratorSearch; |
|
| 39 | - /** @var IManager */ |
|
| 40 | - private $autoCompleteManager; |
|
| 41 | - /** @var EventDispatcherInterface */ |
|
| 42 | - private $dispatcher; |
|
| 37 | + /** @var ISearch */ |
|
| 38 | + private $collaboratorSearch; |
|
| 39 | + /** @var IManager */ |
|
| 40 | + private $autoCompleteManager; |
|
| 41 | + /** @var EventDispatcherInterface */ |
|
| 42 | + private $dispatcher; |
|
| 43 | 43 | |
| 44 | - public function __construct( |
|
| 45 | - string $appName, |
|
| 46 | - IRequest $request, |
|
| 47 | - ISearch $collaboratorSearch, |
|
| 48 | - IManager $autoCompleteManager, |
|
| 49 | - EventDispatcherInterface $dispatcher |
|
| 50 | - ) { |
|
| 51 | - parent::__construct($appName, $request); |
|
| 44 | + public function __construct( |
|
| 45 | + string $appName, |
|
| 46 | + IRequest $request, |
|
| 47 | + ISearch $collaboratorSearch, |
|
| 48 | + IManager $autoCompleteManager, |
|
| 49 | + EventDispatcherInterface $dispatcher |
|
| 50 | + ) { |
|
| 51 | + parent::__construct($appName, $request); |
|
| 52 | 52 | |
| 53 | - $this->collaboratorSearch = $collaboratorSearch; |
|
| 54 | - $this->autoCompleteManager = $autoCompleteManager; |
|
| 55 | - $this->dispatcher = $dispatcher; |
|
| 56 | - } |
|
| 53 | + $this->collaboratorSearch = $collaboratorSearch; |
|
| 54 | + $this->autoCompleteManager = $autoCompleteManager; |
|
| 55 | + $this->dispatcher = $dispatcher; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @NoAdminRequired |
|
| 60 | - * |
|
| 61 | - * @param string $search |
|
| 62 | - * @param string $itemType |
|
| 63 | - * @param string $itemId |
|
| 64 | - * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" |
|
| 65 | - * @param array $shareTypes |
|
| 66 | - * @param int $limit |
|
| 67 | - * @return DataResponse |
|
| 68 | - */ |
|
| 69 | - public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER], $limit = 10): DataResponse { |
|
| 70 | - // if enumeration/user listings are disabled, we'll receive an empty |
|
| 71 | - // result from search() – thus nothing else to do here. |
|
| 72 | - [$results,] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
| 58 | + /** |
|
| 59 | + * @NoAdminRequired |
|
| 60 | + * |
|
| 61 | + * @param string $search |
|
| 62 | + * @param string $itemType |
|
| 63 | + * @param string $itemId |
|
| 64 | + * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" |
|
| 65 | + * @param array $shareTypes |
|
| 66 | + * @param int $limit |
|
| 67 | + * @return DataResponse |
|
| 68 | + */ |
|
| 69 | + public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER], $limit = 10): DataResponse { |
|
| 70 | + // if enumeration/user listings are disabled, we'll receive an empty |
|
| 71 | + // result from search() – thus nothing else to do here. |
|
| 72 | + [$results,] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
| 73 | 73 | |
| 74 | - $event = new AutoCompleteEvent([ |
|
| 75 | - 'search' => $search, |
|
| 76 | - 'results' => $results, |
|
| 77 | - 'itemType' => $itemType, |
|
| 78 | - 'itemId' => $itemId, |
|
| 79 | - 'sorter' => $sorter, |
|
| 80 | - 'shareTypes' => $shareTypes, |
|
| 81 | - 'limit' => $limit, |
|
| 82 | - ]); |
|
| 83 | - $this->dispatcher->dispatch(IManager::class . '::filterResults', $event); |
|
| 84 | - $results = $event->getResults(); |
|
| 74 | + $event = new AutoCompleteEvent([ |
|
| 75 | + 'search' => $search, |
|
| 76 | + 'results' => $results, |
|
| 77 | + 'itemType' => $itemType, |
|
| 78 | + 'itemId' => $itemId, |
|
| 79 | + 'sorter' => $sorter, |
|
| 80 | + 'shareTypes' => $shareTypes, |
|
| 81 | + 'limit' => $limit, |
|
| 82 | + ]); |
|
| 83 | + $this->dispatcher->dispatch(IManager::class . '::filterResults', $event); |
|
| 84 | + $results = $event->getResults(); |
|
| 85 | 85 | |
| 86 | - $exactMatches = $results['exact']; |
|
| 87 | - unset($results['exact']); |
|
| 88 | - $results = array_merge_recursive($exactMatches, $results); |
|
| 86 | + $exactMatches = $results['exact']; |
|
| 87 | + unset($results['exact']); |
|
| 88 | + $results = array_merge_recursive($exactMatches, $results); |
|
| 89 | 89 | |
| 90 | - if($sorter !== null) { |
|
| 91 | - $sorters = array_reverse(explode('|', $sorter)); |
|
| 92 | - $this->autoCompleteManager->runSorters($sorters, $results, [ |
|
| 93 | - 'itemType' => $itemType, |
|
| 94 | - 'itemId' => $itemId, |
|
| 95 | - ]); |
|
| 96 | - } |
|
| 90 | + if($sorter !== null) { |
|
| 91 | + $sorters = array_reverse(explode('|', $sorter)); |
|
| 92 | + $this->autoCompleteManager->runSorters($sorters, $results, [ |
|
| 93 | + 'itemType' => $itemType, |
|
| 94 | + 'itemId' => $itemId, |
|
| 95 | + ]); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - // transform to expected format |
|
| 99 | - $results = $this->prepareResultArray($results); |
|
| 98 | + // transform to expected format |
|
| 99 | + $results = $this->prepareResultArray($results); |
|
| 100 | 100 | |
| 101 | - return new DataResponse($results); |
|
| 102 | - } |
|
| 101 | + return new DataResponse($results); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | - protected function prepareResultArray(array $results): array { |
|
| 106 | - $output = []; |
|
| 107 | - foreach ($results as $type => $subResult) { |
|
| 108 | - foreach ($subResult as $result) { |
|
| 109 | - $output[] = [ |
|
| 110 | - 'id' => $result['value']['shareWith'], |
|
| 111 | - 'label' => $result['label'], |
|
| 112 | - 'source' => $type, |
|
| 113 | - ]; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - return $output; |
|
| 117 | - } |
|
| 105 | + protected function prepareResultArray(array $results): array { |
|
| 106 | + $output = []; |
|
| 107 | + foreach ($results as $type => $subResult) { |
|
| 108 | + foreach ($subResult as $result) { |
|
| 109 | + $output[] = [ |
|
| 110 | + 'id' => $result['value']['shareWith'], |
|
| 111 | + 'label' => $result['label'], |
|
| 112 | + 'source' => $type, |
|
| 113 | + ]; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + return $output; |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER], $limit = 10): DataResponse { |
| 70 | 70 | // if enumeration/user listings are disabled, we'll receive an empty |
| 71 | 71 | // result from search() – thus nothing else to do here. |
| 72 | - [$results,] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
| 72 | + [$results, ] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
| 73 | 73 | |
| 74 | 74 | $event = new AutoCompleteEvent([ |
| 75 | 75 | 'search' => $search, |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | 'shareTypes' => $shareTypes, |
| 81 | 81 | 'limit' => $limit, |
| 82 | 82 | ]); |
| 83 | - $this->dispatcher->dispatch(IManager::class . '::filterResults', $event); |
|
| 83 | + $this->dispatcher->dispatch(IManager::class.'::filterResults', $event); |
|
| 84 | 84 | $results = $event->getResults(); |
| 85 | 85 | |
| 86 | 86 | $exactMatches = $results['exact']; |
| 87 | 87 | unset($results['exact']); |
| 88 | 88 | $results = array_merge_recursive($exactMatches, $results); |
| 89 | 89 | |
| 90 | - if($sorter !== null) { |
|
| 90 | + if ($sorter !== null) { |
|
| 91 | 91 | $sorters = array_reverse(explode('|', $sorter)); |
| 92 | 92 | $this->autoCompleteManager->runSorters($sorters, $results, [ |
| 93 | 93 | 'itemType' => $itemType, |