@@ -60,284 +60,284 @@ |
||
60 | 60 | * @package OCA\Files\Controller |
61 | 61 | */ |
62 | 62 | class ApiController extends Controller { |
63 | - /** @var TagService */ |
|
64 | - private $tagService; |
|
65 | - /** @var IManager * */ |
|
66 | - private $shareManager; |
|
67 | - /** @var IPreview */ |
|
68 | - private $previewManager; |
|
69 | - /** IUserSession */ |
|
70 | - private $userSession; |
|
71 | - /** IConfig */ |
|
72 | - private $config; |
|
73 | - /** @var Folder */ |
|
74 | - private $userFolder; |
|
63 | + /** @var TagService */ |
|
64 | + private $tagService; |
|
65 | + /** @var IManager * */ |
|
66 | + private $shareManager; |
|
67 | + /** @var IPreview */ |
|
68 | + private $previewManager; |
|
69 | + /** IUserSession */ |
|
70 | + private $userSession; |
|
71 | + /** IConfig */ |
|
72 | + private $config; |
|
73 | + /** @var Folder */ |
|
74 | + private $userFolder; |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param string $appName |
|
78 | - * @param IRequest $request |
|
79 | - * @param IUserSession $userSession |
|
80 | - * @param TagService $tagService |
|
81 | - * @param IPreview $previewManager |
|
82 | - * @param IManager $shareManager |
|
83 | - * @param IConfig $config |
|
84 | - * @param Folder $userFolder |
|
85 | - */ |
|
86 | - public function __construct($appName, |
|
87 | - IRequest $request, |
|
88 | - IUserSession $userSession, |
|
89 | - TagService $tagService, |
|
90 | - IPreview $previewManager, |
|
91 | - IManager $shareManager, |
|
92 | - IConfig $config, |
|
93 | - Folder $userFolder) { |
|
94 | - parent::__construct($appName, $request); |
|
95 | - $this->userSession = $userSession; |
|
96 | - $this->tagService = $tagService; |
|
97 | - $this->previewManager = $previewManager; |
|
98 | - $this->shareManager = $shareManager; |
|
99 | - $this->config = $config; |
|
100 | - $this->userFolder = $userFolder; |
|
101 | - } |
|
76 | + /** |
|
77 | + * @param string $appName |
|
78 | + * @param IRequest $request |
|
79 | + * @param IUserSession $userSession |
|
80 | + * @param TagService $tagService |
|
81 | + * @param IPreview $previewManager |
|
82 | + * @param IManager $shareManager |
|
83 | + * @param IConfig $config |
|
84 | + * @param Folder $userFolder |
|
85 | + */ |
|
86 | + public function __construct($appName, |
|
87 | + IRequest $request, |
|
88 | + IUserSession $userSession, |
|
89 | + TagService $tagService, |
|
90 | + IPreview $previewManager, |
|
91 | + IManager $shareManager, |
|
92 | + IConfig $config, |
|
93 | + Folder $userFolder) { |
|
94 | + parent::__construct($appName, $request); |
|
95 | + $this->userSession = $userSession; |
|
96 | + $this->tagService = $tagService; |
|
97 | + $this->previewManager = $previewManager; |
|
98 | + $this->shareManager = $shareManager; |
|
99 | + $this->config = $config; |
|
100 | + $this->userFolder = $userFolder; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Gets a thumbnail of the specified file |
|
105 | - * |
|
106 | - * @since API version 1.0 |
|
107 | - * |
|
108 | - * @NoAdminRequired |
|
109 | - * @NoCSRFRequired |
|
110 | - * @StrictCookieRequired |
|
111 | - * |
|
112 | - * @param int $x |
|
113 | - * @param int $y |
|
114 | - * @param string $file URL-encoded filename |
|
115 | - * @return DataResponse|FileDisplayResponse |
|
116 | - */ |
|
117 | - public function getThumbnail($x, $y, $file) { |
|
118 | - if ($x < 1 || $y < 1) { |
|
119 | - return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
120 | - } |
|
103 | + /** |
|
104 | + * Gets a thumbnail of the specified file |
|
105 | + * |
|
106 | + * @since API version 1.0 |
|
107 | + * |
|
108 | + * @NoAdminRequired |
|
109 | + * @NoCSRFRequired |
|
110 | + * @StrictCookieRequired |
|
111 | + * |
|
112 | + * @param int $x |
|
113 | + * @param int $y |
|
114 | + * @param string $file URL-encoded filename |
|
115 | + * @return DataResponse|FileDisplayResponse |
|
116 | + */ |
|
117 | + public function getThumbnail($x, $y, $file) { |
|
118 | + if ($x < 1 || $y < 1) { |
|
119 | + return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
120 | + } |
|
121 | 121 | |
122 | - try { |
|
123 | - $file = $this->userFolder->get($file); |
|
124 | - if ($file instanceof Folder) { |
|
125 | - throw new NotFoundException(); |
|
126 | - } |
|
122 | + try { |
|
123 | + $file = $this->userFolder->get($file); |
|
124 | + if ($file instanceof Folder) { |
|
125 | + throw new NotFoundException(); |
|
126 | + } |
|
127 | 127 | |
128 | - /** @var File $file */ |
|
129 | - $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
128 | + /** @var File $file */ |
|
129 | + $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
130 | 130 | |
131 | - return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
132 | - } catch (NotFoundException $e) { |
|
133 | - return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
134 | - } catch (\Exception $e) { |
|
135 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
136 | - } |
|
137 | - } |
|
131 | + return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
132 | + } catch (NotFoundException $e) { |
|
133 | + return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
134 | + } catch (\Exception $e) { |
|
135 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
136 | + } |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Updates the info of the specified file path |
|
141 | - * The passed tags are absolute, which means they will |
|
142 | - * replace the actual tag selection. |
|
143 | - * |
|
144 | - * @NoAdminRequired |
|
145 | - * |
|
146 | - * @param string $path path |
|
147 | - * @param array|string $tags array of tags |
|
148 | - * @return DataResponse |
|
149 | - */ |
|
150 | - public function updateFileTags($path, $tags = null) { |
|
151 | - $result = []; |
|
152 | - // if tags specified or empty array, update tags |
|
153 | - if (!is_null($tags)) { |
|
154 | - try { |
|
155 | - $this->tagService->updateFileTags($path, $tags); |
|
156 | - } catch (\OCP\Files\NotFoundException $e) { |
|
157 | - return new DataResponse([ |
|
158 | - 'message' => $e->getMessage() |
|
159 | - ], Http::STATUS_NOT_FOUND); |
|
160 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
161 | - return new DataResponse([ |
|
162 | - 'message' => $e->getMessage() |
|
163 | - ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
164 | - } catch (\Exception $e) { |
|
165 | - return new DataResponse([ |
|
166 | - 'message' => $e->getMessage() |
|
167 | - ], Http::STATUS_NOT_FOUND); |
|
168 | - } |
|
169 | - $result['tags'] = $tags; |
|
170 | - } |
|
171 | - return new DataResponse($result); |
|
172 | - } |
|
139 | + /** |
|
140 | + * Updates the info of the specified file path |
|
141 | + * The passed tags are absolute, which means they will |
|
142 | + * replace the actual tag selection. |
|
143 | + * |
|
144 | + * @NoAdminRequired |
|
145 | + * |
|
146 | + * @param string $path path |
|
147 | + * @param array|string $tags array of tags |
|
148 | + * @return DataResponse |
|
149 | + */ |
|
150 | + public function updateFileTags($path, $tags = null) { |
|
151 | + $result = []; |
|
152 | + // if tags specified or empty array, update tags |
|
153 | + if (!is_null($tags)) { |
|
154 | + try { |
|
155 | + $this->tagService->updateFileTags($path, $tags); |
|
156 | + } catch (\OCP\Files\NotFoundException $e) { |
|
157 | + return new DataResponse([ |
|
158 | + 'message' => $e->getMessage() |
|
159 | + ], Http::STATUS_NOT_FOUND); |
|
160 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
161 | + return new DataResponse([ |
|
162 | + 'message' => $e->getMessage() |
|
163 | + ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
164 | + } catch (\Exception $e) { |
|
165 | + return new DataResponse([ |
|
166 | + 'message' => $e->getMessage() |
|
167 | + ], Http::STATUS_NOT_FOUND); |
|
168 | + } |
|
169 | + $result['tags'] = $tags; |
|
170 | + } |
|
171 | + return new DataResponse($result); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * @param \OCP\Files\Node[] $nodes |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - private function formatNodes(array $nodes) { |
|
179 | - return array_values(array_map(function (Node $node) { |
|
180 | - /** @var \OC\Files\Node\Node $shareTypes */ |
|
181 | - $shareTypes = $this->getShareTypes($node); |
|
182 | - $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
|
183 | - $parts = explode('/', dirname($node->getPath()), 4); |
|
184 | - if (isset($parts[3])) { |
|
185 | - $file['path'] = '/' . $parts[3]; |
|
186 | - } else { |
|
187 | - $file['path'] = '/'; |
|
188 | - } |
|
189 | - if (!empty($shareTypes)) { |
|
190 | - $file['shareTypes'] = $shareTypes; |
|
191 | - } |
|
192 | - return $file; |
|
193 | - }, $nodes)); |
|
194 | - } |
|
174 | + /** |
|
175 | + * @param \OCP\Files\Node[] $nodes |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + private function formatNodes(array $nodes) { |
|
179 | + return array_values(array_map(function (Node $node) { |
|
180 | + /** @var \OC\Files\Node\Node $shareTypes */ |
|
181 | + $shareTypes = $this->getShareTypes($node); |
|
182 | + $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
|
183 | + $parts = explode('/', dirname($node->getPath()), 4); |
|
184 | + if (isset($parts[3])) { |
|
185 | + $file['path'] = '/' . $parts[3]; |
|
186 | + } else { |
|
187 | + $file['path'] = '/'; |
|
188 | + } |
|
189 | + if (!empty($shareTypes)) { |
|
190 | + $file['shareTypes'] = $shareTypes; |
|
191 | + } |
|
192 | + return $file; |
|
193 | + }, $nodes)); |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Returns a list of recently modifed files. |
|
198 | - * |
|
199 | - * @NoAdminRequired |
|
200 | - * |
|
201 | - * @return DataResponse |
|
202 | - */ |
|
203 | - public function getRecentFiles() { |
|
204 | - $nodes = $this->userFolder->getRecent(100); |
|
205 | - $files = $this->formatNodes($nodes); |
|
206 | - return new DataResponse(['files' => $files]); |
|
207 | - } |
|
196 | + /** |
|
197 | + * Returns a list of recently modifed files. |
|
198 | + * |
|
199 | + * @NoAdminRequired |
|
200 | + * |
|
201 | + * @return DataResponse |
|
202 | + */ |
|
203 | + public function getRecentFiles() { |
|
204 | + $nodes = $this->userFolder->getRecent(100); |
|
205 | + $files = $this->formatNodes($nodes); |
|
206 | + return new DataResponse(['files' => $files]); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Return a list of share types for outgoing shares |
|
211 | - * |
|
212 | - * @param Node $node file node |
|
213 | - * |
|
214 | - * @return int[] array of share types |
|
215 | - */ |
|
216 | - private function getShareTypes(Node $node) { |
|
217 | - $userId = $this->userSession->getUser()->getUID(); |
|
218 | - $shareTypes = []; |
|
219 | - $requestedShareTypes = [ |
|
220 | - IShare::TYPE_USER, |
|
221 | - IShare::TYPE_GROUP, |
|
222 | - IShare::TYPE_LINK, |
|
223 | - IShare::TYPE_REMOTE, |
|
224 | - IShare::TYPE_EMAIL, |
|
225 | - IShare::TYPE_ROOM |
|
226 | - ]; |
|
227 | - foreach ($requestedShareTypes as $requestedShareType) { |
|
228 | - // one of each type is enough to find out about the types |
|
229 | - $shares = $this->shareManager->getSharesBy( |
|
230 | - $userId, |
|
231 | - $requestedShareType, |
|
232 | - $node, |
|
233 | - false, |
|
234 | - 1 |
|
235 | - ); |
|
236 | - if (!empty($shares)) { |
|
237 | - $shareTypes[] = $requestedShareType; |
|
238 | - } |
|
239 | - } |
|
240 | - return $shareTypes; |
|
241 | - } |
|
209 | + /** |
|
210 | + * Return a list of share types for outgoing shares |
|
211 | + * |
|
212 | + * @param Node $node file node |
|
213 | + * |
|
214 | + * @return int[] array of share types |
|
215 | + */ |
|
216 | + private function getShareTypes(Node $node) { |
|
217 | + $userId = $this->userSession->getUser()->getUID(); |
|
218 | + $shareTypes = []; |
|
219 | + $requestedShareTypes = [ |
|
220 | + IShare::TYPE_USER, |
|
221 | + IShare::TYPE_GROUP, |
|
222 | + IShare::TYPE_LINK, |
|
223 | + IShare::TYPE_REMOTE, |
|
224 | + IShare::TYPE_EMAIL, |
|
225 | + IShare::TYPE_ROOM |
|
226 | + ]; |
|
227 | + foreach ($requestedShareTypes as $requestedShareType) { |
|
228 | + // one of each type is enough to find out about the types |
|
229 | + $shares = $this->shareManager->getSharesBy( |
|
230 | + $userId, |
|
231 | + $requestedShareType, |
|
232 | + $node, |
|
233 | + false, |
|
234 | + 1 |
|
235 | + ); |
|
236 | + if (!empty($shares)) { |
|
237 | + $shareTypes[] = $requestedShareType; |
|
238 | + } |
|
239 | + } |
|
240 | + return $shareTypes; |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Change the default sort mode |
|
245 | - * |
|
246 | - * @NoAdminRequired |
|
247 | - * |
|
248 | - * @param string $mode |
|
249 | - * @param string $direction |
|
250 | - * @return Response |
|
251 | - * @throws \OCP\PreConditionNotMetException |
|
252 | - */ |
|
253 | - public function updateFileSorting($mode, $direction) { |
|
254 | - $allowedMode = ['name', 'size', 'mtime']; |
|
255 | - $allowedDirection = ['asc', 'desc']; |
|
256 | - if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { |
|
257 | - $response = new Response(); |
|
258 | - $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); |
|
259 | - return $response; |
|
260 | - } |
|
261 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode); |
|
262 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction); |
|
263 | - return new Response(); |
|
264 | - } |
|
243 | + /** |
|
244 | + * Change the default sort mode |
|
245 | + * |
|
246 | + * @NoAdminRequired |
|
247 | + * |
|
248 | + * @param string $mode |
|
249 | + * @param string $direction |
|
250 | + * @return Response |
|
251 | + * @throws \OCP\PreConditionNotMetException |
|
252 | + */ |
|
253 | + public function updateFileSorting($mode, $direction) { |
|
254 | + $allowedMode = ['name', 'size', 'mtime']; |
|
255 | + $allowedDirection = ['asc', 'desc']; |
|
256 | + if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { |
|
257 | + $response = new Response(); |
|
258 | + $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); |
|
259 | + return $response; |
|
260 | + } |
|
261 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode); |
|
262 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction); |
|
263 | + return new Response(); |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Toggle default for showing/hiding hidden files |
|
268 | - * |
|
269 | - * @NoAdminRequired |
|
270 | - * |
|
271 | - * @param bool $show |
|
272 | - * @return Response |
|
273 | - * @throws \OCP\PreConditionNotMetException |
|
274 | - */ |
|
275 | - public function showHiddenFiles($show) { |
|
276 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show); |
|
277 | - return new Response(); |
|
278 | - } |
|
266 | + /** |
|
267 | + * Toggle default for showing/hiding hidden files |
|
268 | + * |
|
269 | + * @NoAdminRequired |
|
270 | + * |
|
271 | + * @param bool $show |
|
272 | + * @return Response |
|
273 | + * @throws \OCP\PreConditionNotMetException |
|
274 | + */ |
|
275 | + public function showHiddenFiles($show) { |
|
276 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show); |
|
277 | + return new Response(); |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * Toggle default for files grid view |
|
282 | - * |
|
283 | - * @NoAdminRequired |
|
284 | - * |
|
285 | - * @param bool $show |
|
286 | - * @return Response |
|
287 | - * @throws \OCP\PreConditionNotMetException |
|
288 | - */ |
|
289 | - public function showGridView($show) { |
|
290 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show); |
|
291 | - return new Response(); |
|
292 | - } |
|
280 | + /** |
|
281 | + * Toggle default for files grid view |
|
282 | + * |
|
283 | + * @NoAdminRequired |
|
284 | + * |
|
285 | + * @param bool $show |
|
286 | + * @return Response |
|
287 | + * @throws \OCP\PreConditionNotMetException |
|
288 | + */ |
|
289 | + public function showGridView($show) { |
|
290 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show); |
|
291 | + return new Response(); |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * Get default settings for the grid view |
|
296 | - * |
|
297 | - * @NoAdminRequired |
|
298 | - */ |
|
299 | - public function getGridView() { |
|
300 | - $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1'; |
|
301 | - return new JSONResponse(['gridview' => $status]); |
|
302 | - } |
|
294 | + /** |
|
295 | + * Get default settings for the grid view |
|
296 | + * |
|
297 | + * @NoAdminRequired |
|
298 | + */ |
|
299 | + public function getGridView() { |
|
300 | + $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1'; |
|
301 | + return new JSONResponse(['gridview' => $status]); |
|
302 | + } |
|
303 | 303 | |
304 | - /** |
|
305 | - * Toggle default for showing/hiding xxx folder |
|
306 | - * |
|
307 | - * @NoAdminRequired |
|
308 | - * |
|
309 | - * @param int $show |
|
310 | - * @param string $key the key of the folder |
|
311 | - * |
|
312 | - * @return Response |
|
313 | - * @throws \OCP\PreConditionNotMetException |
|
314 | - */ |
|
315 | - public function toggleShowFolder(int $show, string $key) { |
|
316 | - // ensure the edited key exists |
|
317 | - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
318 | - foreach ($navItems as $item) { |
|
319 | - // check if data is valid |
|
320 | - if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) { |
|
321 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show); |
|
322 | - return new Response(); |
|
323 | - } |
|
324 | - } |
|
325 | - $response = new Response(); |
|
326 | - $response->setStatus(Http::STATUS_FORBIDDEN); |
|
327 | - return $response; |
|
328 | - } |
|
304 | + /** |
|
305 | + * Toggle default for showing/hiding xxx folder |
|
306 | + * |
|
307 | + * @NoAdminRequired |
|
308 | + * |
|
309 | + * @param int $show |
|
310 | + * @param string $key the key of the folder |
|
311 | + * |
|
312 | + * @return Response |
|
313 | + * @throws \OCP\PreConditionNotMetException |
|
314 | + */ |
|
315 | + public function toggleShowFolder(int $show, string $key) { |
|
316 | + // ensure the edited key exists |
|
317 | + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
318 | + foreach ($navItems as $item) { |
|
319 | + // check if data is valid |
|
320 | + if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) { |
|
321 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show); |
|
322 | + return new Response(); |
|
323 | + } |
|
324 | + } |
|
325 | + $response = new Response(); |
|
326 | + $response->setStatus(Http::STATUS_FORBIDDEN); |
|
327 | + return $response; |
|
328 | + } |
|
329 | 329 | |
330 | - /** |
|
331 | - * Get sorting-order for custom sorting |
|
332 | - * |
|
333 | - * @NoAdminRequired |
|
334 | - * |
|
335 | - * @param string |
|
336 | - * @return string |
|
337 | - * @throws \OCP\Files\NotFoundException |
|
338 | - */ |
|
339 | - public function getNodeType($folderpath) { |
|
340 | - $node = $this->userFolder->get($folderpath); |
|
341 | - return $node->getType(); |
|
342 | - } |
|
330 | + /** |
|
331 | + * Get sorting-order for custom sorting |
|
332 | + * |
|
333 | + * @NoAdminRequired |
|
334 | + * |
|
335 | + * @param string |
|
336 | + * @return string |
|
337 | + * @throws \OCP\Files\NotFoundException |
|
338 | + */ |
|
339 | + public function getNodeType($folderpath) { |
|
340 | + $node = $this->userFolder->get($folderpath); |
|
341 | + return $node->getType(); |
|
342 | + } |
|
343 | 343 | } |
@@ -40,85 +40,85 @@ |
||
40 | 40 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
41 | 41 | |
42 | 42 | class AutoCompleteController extends Controller { |
43 | - /** @var ISearch */ |
|
44 | - private $collaboratorSearch; |
|
45 | - /** @var IManager */ |
|
46 | - private $autoCompleteManager; |
|
47 | - /** @var EventDispatcherInterface */ |
|
48 | - private $dispatcher; |
|
43 | + /** @var ISearch */ |
|
44 | + private $collaboratorSearch; |
|
45 | + /** @var IManager */ |
|
46 | + private $autoCompleteManager; |
|
47 | + /** @var EventDispatcherInterface */ |
|
48 | + private $dispatcher; |
|
49 | 49 | |
50 | - public function __construct( |
|
51 | - string $appName, |
|
52 | - IRequest $request, |
|
53 | - ISearch $collaboratorSearch, |
|
54 | - IManager $autoCompleteManager, |
|
55 | - EventDispatcherInterface $dispatcher |
|
56 | - ) { |
|
57 | - parent::__construct($appName, $request); |
|
50 | + public function __construct( |
|
51 | + string $appName, |
|
52 | + IRequest $request, |
|
53 | + ISearch $collaboratorSearch, |
|
54 | + IManager $autoCompleteManager, |
|
55 | + EventDispatcherInterface $dispatcher |
|
56 | + ) { |
|
57 | + parent::__construct($appName, $request); |
|
58 | 58 | |
59 | - $this->collaboratorSearch = $collaboratorSearch; |
|
60 | - $this->autoCompleteManager = $autoCompleteManager; |
|
61 | - $this->dispatcher = $dispatcher; |
|
62 | - } |
|
59 | + $this->collaboratorSearch = $collaboratorSearch; |
|
60 | + $this->autoCompleteManager = $autoCompleteManager; |
|
61 | + $this->dispatcher = $dispatcher; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @NoAdminRequired |
|
66 | - * |
|
67 | - * @param string $search |
|
68 | - * @param string $itemType |
|
69 | - * @param string $itemId |
|
70 | - * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" |
|
71 | - * @param array $shareTypes |
|
72 | - * @param int $limit |
|
73 | - * @return DataResponse |
|
74 | - */ |
|
75 | - public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [IShare::TYPE_USER], $limit = 10): DataResponse { |
|
76 | - // if enumeration/user listings are disabled, we'll receive an empty |
|
77 | - // result from search() – thus nothing else to do here. |
|
78 | - [$results,] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
64 | + /** |
|
65 | + * @NoAdminRequired |
|
66 | + * |
|
67 | + * @param string $search |
|
68 | + * @param string $itemType |
|
69 | + * @param string $itemId |
|
70 | + * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" |
|
71 | + * @param array $shareTypes |
|
72 | + * @param int $limit |
|
73 | + * @return DataResponse |
|
74 | + */ |
|
75 | + public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [IShare::TYPE_USER], $limit = 10): DataResponse { |
|
76 | + // if enumeration/user listings are disabled, we'll receive an empty |
|
77 | + // result from search() – thus nothing else to do here. |
|
78 | + [$results,] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
79 | 79 | |
80 | - $event = new AutoCompleteEvent([ |
|
81 | - 'search' => $search, |
|
82 | - 'results' => $results, |
|
83 | - 'itemType' => $itemType, |
|
84 | - 'itemId' => $itemId, |
|
85 | - 'sorter' => $sorter, |
|
86 | - 'shareTypes' => $shareTypes, |
|
87 | - 'limit' => $limit, |
|
88 | - ]); |
|
89 | - $this->dispatcher->dispatch(IManager::class . '::filterResults', $event); |
|
90 | - $results = $event->getResults(); |
|
80 | + $event = new AutoCompleteEvent([ |
|
81 | + 'search' => $search, |
|
82 | + 'results' => $results, |
|
83 | + 'itemType' => $itemType, |
|
84 | + 'itemId' => $itemId, |
|
85 | + 'sorter' => $sorter, |
|
86 | + 'shareTypes' => $shareTypes, |
|
87 | + 'limit' => $limit, |
|
88 | + ]); |
|
89 | + $this->dispatcher->dispatch(IManager::class . '::filterResults', $event); |
|
90 | + $results = $event->getResults(); |
|
91 | 91 | |
92 | - $exactMatches = $results['exact']; |
|
93 | - unset($results['exact']); |
|
94 | - $results = array_merge_recursive($exactMatches, $results); |
|
92 | + $exactMatches = $results['exact']; |
|
93 | + unset($results['exact']); |
|
94 | + $results = array_merge_recursive($exactMatches, $results); |
|
95 | 95 | |
96 | - if ($sorter !== null) { |
|
97 | - $sorters = array_reverse(explode('|', $sorter)); |
|
98 | - $this->autoCompleteManager->runSorters($sorters, $results, [ |
|
99 | - 'itemType' => $itemType, |
|
100 | - 'itemId' => $itemId, |
|
101 | - ]); |
|
102 | - } |
|
96 | + if ($sorter !== null) { |
|
97 | + $sorters = array_reverse(explode('|', $sorter)); |
|
98 | + $this->autoCompleteManager->runSorters($sorters, $results, [ |
|
99 | + 'itemType' => $itemType, |
|
100 | + 'itemId' => $itemId, |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | |
104 | - // transform to expected format |
|
105 | - $results = $this->prepareResultArray($results); |
|
104 | + // transform to expected format |
|
105 | + $results = $this->prepareResultArray($results); |
|
106 | 106 | |
107 | - return new DataResponse($results); |
|
108 | - } |
|
107 | + return new DataResponse($results); |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - protected function prepareResultArray(array $results): array { |
|
112 | - $output = []; |
|
113 | - foreach ($results as $type => $subResult) { |
|
114 | - foreach ($subResult as $result) { |
|
115 | - $output[] = [ |
|
116 | - 'id' => (string) $result['value']['shareWith'], |
|
117 | - 'label' => $result['label'], |
|
118 | - 'source' => $type, |
|
119 | - ]; |
|
120 | - } |
|
121 | - } |
|
122 | - return $output; |
|
123 | - } |
|
111 | + protected function prepareResultArray(array $results): array { |
|
112 | + $output = []; |
|
113 | + foreach ($results as $type => $subResult) { |
|
114 | + foreach ($subResult as $result) { |
|
115 | + $output[] = [ |
|
116 | + 'id' => (string) $result['value']['shareWith'], |
|
117 | + 'label' => $result['label'], |
|
118 | + 'source' => $type, |
|
119 | + ]; |
|
120 | + } |
|
121 | + } |
|
122 | + return $output; |
|
123 | + } |
|
124 | 124 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [IShare::TYPE_USER], $limit = 10): DataResponse { |
76 | 76 | // if enumeration/user listings are disabled, we'll receive an empty |
77 | 77 | // result from search() – thus nothing else to do here. |
78 | - [$results,] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
78 | + [$results, ] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
79 | 79 | |
80 | 80 | $event = new AutoCompleteEvent([ |
81 | 81 | 'search' => $search, |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | 'shareTypes' => $shareTypes, |
87 | 87 | 'limit' => $limit, |
88 | 88 | ]); |
89 | - $this->dispatcher->dispatch(IManager::class . '::filterResults', $event); |
|
89 | + $this->dispatcher->dispatch(IManager::class.'::filterResults', $event); |
|
90 | 90 | $results = $event->getResults(); |
91 | 91 | |
92 | 92 | $exactMatches = $results['exact']; |