@@ -32,73 +32,73 @@ |
||
32 | 32 | use OCP\Share; |
33 | 33 | |
34 | 34 | class AutoCompleteController extends Controller { |
35 | - /** @var ISearch */ |
|
36 | - private $collaboratorSearch; |
|
37 | - /** @var IManager */ |
|
38 | - private $autoCompleteManager; |
|
39 | - /** @var IConfig */ |
|
40 | - private $config; |
|
35 | + /** @var ISearch */ |
|
36 | + private $collaboratorSearch; |
|
37 | + /** @var IManager */ |
|
38 | + private $autoCompleteManager; |
|
39 | + /** @var IConfig */ |
|
40 | + private $config; |
|
41 | 41 | |
42 | - public function __construct( |
|
43 | - $appName, |
|
44 | - IRequest $request, |
|
45 | - ISearch $collaboratorSearch, |
|
46 | - IManager $autoCompleteManager, |
|
47 | - IConfig $config |
|
48 | - ) { |
|
49 | - parent::__construct($appName, $request); |
|
42 | + public function __construct( |
|
43 | + $appName, |
|
44 | + IRequest $request, |
|
45 | + ISearch $collaboratorSearch, |
|
46 | + IManager $autoCompleteManager, |
|
47 | + IConfig $config |
|
48 | + ) { |
|
49 | + parent::__construct($appName, $request); |
|
50 | 50 | |
51 | - $this->collaboratorSearch = $collaboratorSearch; |
|
52 | - $this->autoCompleteManager = $autoCompleteManager; |
|
53 | - $this->config = $config; |
|
54 | - } |
|
51 | + $this->collaboratorSearch = $collaboratorSearch; |
|
52 | + $this->autoCompleteManager = $autoCompleteManager; |
|
53 | + $this->config = $config; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @NoAdminRequired |
|
58 | - * |
|
59 | - * @param string $search |
|
60 | - * @param string $itemType |
|
61 | - * @param string $itemId |
|
62 | - * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" |
|
63 | - * @param array $shareTypes |
|
64 | - * @param int $limit |
|
65 | - * @return DataResponse |
|
66 | - */ |
|
67 | - public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER], $limit = 10) { |
|
68 | - // if enumeration/user listings are disabled, we'll receive an empty |
|
69 | - // result from search() – thus nothing else to do here. |
|
70 | - list($results,) = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
56 | + /** |
|
57 | + * @NoAdminRequired |
|
58 | + * |
|
59 | + * @param string $search |
|
60 | + * @param string $itemType |
|
61 | + * @param string $itemId |
|
62 | + * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" |
|
63 | + * @param array $shareTypes |
|
64 | + * @param int $limit |
|
65 | + * @return DataResponse |
|
66 | + */ |
|
67 | + public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER], $limit = 10) { |
|
68 | + // if enumeration/user listings are disabled, we'll receive an empty |
|
69 | + // result from search() – thus nothing else to do here. |
|
70 | + list($results,) = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
71 | 71 | |
72 | - $exactMatches = $results['exact']; |
|
73 | - unset($results['exact']); |
|
74 | - $results = array_merge_recursive($exactMatches, $results); |
|
72 | + $exactMatches = $results['exact']; |
|
73 | + unset($results['exact']); |
|
74 | + $results = array_merge_recursive($exactMatches, $results); |
|
75 | 75 | |
76 | - if($sorter !== null) { |
|
77 | - $sorters = array_reverse(explode('|', $sorter)); |
|
78 | - $this->autoCompleteManager->runSorters($sorters, $results, [ |
|
79 | - 'itemType' => $itemType, |
|
80 | - 'itemId' => $itemId, |
|
81 | - ]); |
|
82 | - } |
|
76 | + if($sorter !== null) { |
|
77 | + $sorters = array_reverse(explode('|', $sorter)); |
|
78 | + $this->autoCompleteManager->runSorters($sorters, $results, [ |
|
79 | + 'itemType' => $itemType, |
|
80 | + 'itemId' => $itemId, |
|
81 | + ]); |
|
82 | + } |
|
83 | 83 | |
84 | - // transform to expected format |
|
85 | - $results = $this->prepareResultArray($results); |
|
84 | + // transform to expected format |
|
85 | + $results = $this->prepareResultArray($results); |
|
86 | 86 | |
87 | - return new DataResponse($results); |
|
88 | - } |
|
87 | + return new DataResponse($results); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | - protected function prepareResultArray(array $results) { |
|
92 | - $output = []; |
|
93 | - foreach ($results as $type => $subResult) { |
|
94 | - foreach ($subResult as $result) { |
|
95 | - $output[] = [ |
|
96 | - 'id' => $result['value']['shareWith'], |
|
97 | - 'label' => $result['label'], |
|
98 | - 'source' => $type, |
|
99 | - ]; |
|
100 | - } |
|
101 | - } |
|
102 | - return $output; |
|
103 | - } |
|
91 | + protected function prepareResultArray(array $results) { |
|
92 | + $output = []; |
|
93 | + foreach ($results as $type => $subResult) { |
|
94 | + foreach ($subResult as $result) { |
|
95 | + $output[] = [ |
|
96 | + 'id' => $result['value']['shareWith'], |
|
97 | + 'label' => $result['label'], |
|
98 | + 'source' => $type, |
|
99 | + ]; |
|
100 | + } |
|
101 | + } |
|
102 | + return $output; |
|
103 | + } |
|
104 | 104 | } |