@@ -41,114 +41,114 @@ |
||
| 41 | 41 | |
| 42 | 42 | class UnifiedSearchController extends OCSController { |
| 43 | 43 | |
| 44 | - /** @var SearchComposer */ |
|
| 45 | - private $composer; |
|
| 46 | - |
|
| 47 | - /** @var IUserSession */ |
|
| 48 | - private $userSession; |
|
| 49 | - |
|
| 50 | - /** @var IRouter */ |
|
| 51 | - private $router; |
|
| 52 | - |
|
| 53 | - public function __construct(IRequest $request, |
|
| 54 | - IUserSession $userSession, |
|
| 55 | - SearchComposer $composer, |
|
| 56 | - IRouter $router) { |
|
| 57 | - parent::__construct('core', $request); |
|
| 58 | - |
|
| 59 | - $this->composer = $composer; |
|
| 60 | - $this->userSession = $userSession; |
|
| 61 | - $this->router = $router; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @NoAdminRequired |
|
| 66 | - * @NoCSRFRequired |
|
| 67 | - * |
|
| 68 | - * @param string $from the url the user is currently at |
|
| 69 | - * |
|
| 70 | - * @return DataResponse |
|
| 71 | - */ |
|
| 72 | - public function getProviders(string $from = ''): DataResponse { |
|
| 73 | - [$route, $parameters] = $this->getRouteInformation($from); |
|
| 74 | - |
|
| 75 | - $result = $this->composer->getProviders($route, $parameters); |
|
| 76 | - $response = new DataResponse($result); |
|
| 77 | - $response->setETag(md5(json_encode($result))); |
|
| 78 | - return $response; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @NoAdminRequired |
|
| 83 | - * @NoCSRFRequired |
|
| 84 | - * |
|
| 85 | - * @param string $providerId |
|
| 86 | - * @param string $term |
|
| 87 | - * @param int|null $sortOrder |
|
| 88 | - * @param int|null $limit |
|
| 89 | - * @param int|string|null $cursor |
|
| 90 | - * @param string $from |
|
| 91 | - * |
|
| 92 | - * @return DataResponse |
|
| 93 | - */ |
|
| 94 | - public function search(string $providerId, |
|
| 95 | - string $term = '', |
|
| 96 | - ?int $sortOrder = null, |
|
| 97 | - ?int $limit = null, |
|
| 98 | - $cursor = null, |
|
| 99 | - string $from = ''): DataResponse { |
|
| 100 | - if (empty(trim($term))) { |
|
| 101 | - return new DataResponse(null, Http::STATUS_BAD_REQUEST); |
|
| 102 | - } |
|
| 103 | - [$route, $routeParameters] = $this->getRouteInformation($from); |
|
| 104 | - |
|
| 105 | - return new DataResponse( |
|
| 106 | - $this->composer->search( |
|
| 107 | - $this->userSession->getUser(), |
|
| 108 | - $providerId, |
|
| 109 | - new SearchQuery( |
|
| 110 | - $term, |
|
| 111 | - $sortOrder ?? ISearchQuery::SORT_DATE_DESC, |
|
| 112 | - $limit ?? SearchQuery::LIMIT_DEFAULT, |
|
| 113 | - $cursor, |
|
| 114 | - $route, |
|
| 115 | - $routeParameters |
|
| 116 | - ) |
|
| 117 | - ) |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - protected function getRouteInformation(string $url): array { |
|
| 122 | - $routeStr = ''; |
|
| 123 | - $parameters = []; |
|
| 124 | - |
|
| 125 | - if ($url !== '') { |
|
| 126 | - $urlParts = parse_url($url); |
|
| 127 | - |
|
| 128 | - try { |
|
| 129 | - $parameters = $this->router->findMatchingRoute($urlParts['path']); |
|
| 130 | - |
|
| 131 | - // contacts.PageController.index => contacts.Page.index |
|
| 132 | - $route = $parameters['caller']; |
|
| 133 | - if (substr($route[1], -10) === 'Controller') { |
|
| 134 | - $route[1] = substr($route[1], 0, -10); |
|
| 135 | - } |
|
| 136 | - $routeStr = implode('.', $route); |
|
| 137 | - |
|
| 138 | - // cleanup |
|
| 139 | - unset($parameters['_route'], $parameters['action'], $parameters['caller']); |
|
| 140 | - } catch (ResourceNotFoundException $exception) { |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - if (isset($urlParts['query'])) { |
|
| 144 | - parse_str($urlParts['query'], $queryParameters); |
|
| 145 | - $parameters = array_merge($parameters, $queryParameters); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return [ |
|
| 150 | - $routeStr, |
|
| 151 | - $parameters, |
|
| 152 | - ]; |
|
| 153 | - } |
|
| 44 | + /** @var SearchComposer */ |
|
| 45 | + private $composer; |
|
| 46 | + |
|
| 47 | + /** @var IUserSession */ |
|
| 48 | + private $userSession; |
|
| 49 | + |
|
| 50 | + /** @var IRouter */ |
|
| 51 | + private $router; |
|
| 52 | + |
|
| 53 | + public function __construct(IRequest $request, |
|
| 54 | + IUserSession $userSession, |
|
| 55 | + SearchComposer $composer, |
|
| 56 | + IRouter $router) { |
|
| 57 | + parent::__construct('core', $request); |
|
| 58 | + |
|
| 59 | + $this->composer = $composer; |
|
| 60 | + $this->userSession = $userSession; |
|
| 61 | + $this->router = $router; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @NoAdminRequired |
|
| 66 | + * @NoCSRFRequired |
|
| 67 | + * |
|
| 68 | + * @param string $from the url the user is currently at |
|
| 69 | + * |
|
| 70 | + * @return DataResponse |
|
| 71 | + */ |
|
| 72 | + public function getProviders(string $from = ''): DataResponse { |
|
| 73 | + [$route, $parameters] = $this->getRouteInformation($from); |
|
| 74 | + |
|
| 75 | + $result = $this->composer->getProviders($route, $parameters); |
|
| 76 | + $response = new DataResponse($result); |
|
| 77 | + $response->setETag(md5(json_encode($result))); |
|
| 78 | + return $response; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @NoAdminRequired |
|
| 83 | + * @NoCSRFRequired |
|
| 84 | + * |
|
| 85 | + * @param string $providerId |
|
| 86 | + * @param string $term |
|
| 87 | + * @param int|null $sortOrder |
|
| 88 | + * @param int|null $limit |
|
| 89 | + * @param int|string|null $cursor |
|
| 90 | + * @param string $from |
|
| 91 | + * |
|
| 92 | + * @return DataResponse |
|
| 93 | + */ |
|
| 94 | + public function search(string $providerId, |
|
| 95 | + string $term = '', |
|
| 96 | + ?int $sortOrder = null, |
|
| 97 | + ?int $limit = null, |
|
| 98 | + $cursor = null, |
|
| 99 | + string $from = ''): DataResponse { |
|
| 100 | + if (empty(trim($term))) { |
|
| 101 | + return new DataResponse(null, Http::STATUS_BAD_REQUEST); |
|
| 102 | + } |
|
| 103 | + [$route, $routeParameters] = $this->getRouteInformation($from); |
|
| 104 | + |
|
| 105 | + return new DataResponse( |
|
| 106 | + $this->composer->search( |
|
| 107 | + $this->userSession->getUser(), |
|
| 108 | + $providerId, |
|
| 109 | + new SearchQuery( |
|
| 110 | + $term, |
|
| 111 | + $sortOrder ?? ISearchQuery::SORT_DATE_DESC, |
|
| 112 | + $limit ?? SearchQuery::LIMIT_DEFAULT, |
|
| 113 | + $cursor, |
|
| 114 | + $route, |
|
| 115 | + $routeParameters |
|
| 116 | + ) |
|
| 117 | + ) |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + protected function getRouteInformation(string $url): array { |
|
| 122 | + $routeStr = ''; |
|
| 123 | + $parameters = []; |
|
| 124 | + |
|
| 125 | + if ($url !== '') { |
|
| 126 | + $urlParts = parse_url($url); |
|
| 127 | + |
|
| 128 | + try { |
|
| 129 | + $parameters = $this->router->findMatchingRoute($urlParts['path']); |
|
| 130 | + |
|
| 131 | + // contacts.PageController.index => contacts.Page.index |
|
| 132 | + $route = $parameters['caller']; |
|
| 133 | + if (substr($route[1], -10) === 'Controller') { |
|
| 134 | + $route[1] = substr($route[1], 0, -10); |
|
| 135 | + } |
|
| 136 | + $routeStr = implode('.', $route); |
|
| 137 | + |
|
| 138 | + // cleanup |
|
| 139 | + unset($parameters['_route'], $parameters['action'], $parameters['caller']); |
|
| 140 | + } catch (ResourceNotFoundException $exception) { |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + if (isset($urlParts['query'])) { |
|
| 144 | + parse_str($urlParts['query'], $queryParameters); |
|
| 145 | + $parameters = array_merge($parameters, $queryParameters); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return [ |
|
| 150 | + $routeStr, |
|
| 151 | + $parameters, |
|
| 152 | + ]; |
|
| 153 | + } |
|
| 154 | 154 | } |
@@ -41,78 +41,78 @@ |
||
| 41 | 41 | |
| 42 | 42 | class CommentsSearchProvider implements IProvider { |
| 43 | 43 | |
| 44 | - /** @var IUserManager */ |
|
| 45 | - private $userManager; |
|
| 44 | + /** @var IUserManager */ |
|
| 45 | + private $userManager; |
|
| 46 | 46 | |
| 47 | - /** @var IL10N */ |
|
| 48 | - private $l10n; |
|
| 47 | + /** @var IL10N */ |
|
| 48 | + private $l10n; |
|
| 49 | 49 | |
| 50 | - /** @var IURLGenerator */ |
|
| 51 | - private $urlGenerator; |
|
| 50 | + /** @var IURLGenerator */ |
|
| 51 | + private $urlGenerator; |
|
| 52 | 52 | |
| 53 | - /** @var LegacyProvider */ |
|
| 54 | - private $legacyProvider; |
|
| 53 | + /** @var LegacyProvider */ |
|
| 54 | + private $legacyProvider; |
|
| 55 | 55 | |
| 56 | - public function __construct(IUserManager $userManager, |
|
| 57 | - IL10N $l10n, |
|
| 58 | - IURLGenerator $urlGenerator, |
|
| 59 | - LegacyProvider $legacyProvider) { |
|
| 60 | - $this->userManager = $userManager; |
|
| 61 | - $this->l10n = $l10n; |
|
| 62 | - $this->urlGenerator = $urlGenerator; |
|
| 63 | - $this->legacyProvider = $legacyProvider; |
|
| 64 | - } |
|
| 56 | + public function __construct(IUserManager $userManager, |
|
| 57 | + IL10N $l10n, |
|
| 58 | + IURLGenerator $urlGenerator, |
|
| 59 | + LegacyProvider $legacyProvider) { |
|
| 60 | + $this->userManager = $userManager; |
|
| 61 | + $this->l10n = $l10n; |
|
| 62 | + $this->urlGenerator = $urlGenerator; |
|
| 63 | + $this->legacyProvider = $legacyProvider; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @inheritDoc |
|
| 68 | - */ |
|
| 69 | - public function getId(): string { |
|
| 70 | - return 'comments'; |
|
| 71 | - } |
|
| 66 | + /** |
|
| 67 | + * @inheritDoc |
|
| 68 | + */ |
|
| 69 | + public function getId(): string { |
|
| 70 | + return 'comments'; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @inheritDoc |
|
| 75 | - */ |
|
| 76 | - public function getName(): string { |
|
| 77 | - return $this->l10n->t('Comments'); |
|
| 78 | - } |
|
| 73 | + /** |
|
| 74 | + * @inheritDoc |
|
| 75 | + */ |
|
| 76 | + public function getName(): string { |
|
| 77 | + return $this->l10n->t('Comments'); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @inheritDoc |
|
| 82 | - */ |
|
| 83 | - public function getOrder(string $route, array $routeParameters): int { |
|
| 84 | - if ($route === 'files.View.index') { |
|
| 85 | - // Files first |
|
| 86 | - return 0; |
|
| 87 | - } |
|
| 88 | - return 10; |
|
| 89 | - } |
|
| 80 | + /** |
|
| 81 | + * @inheritDoc |
|
| 82 | + */ |
|
| 83 | + public function getOrder(string $route, array $routeParameters): int { |
|
| 84 | + if ($route === 'files.View.index') { |
|
| 85 | + // Files first |
|
| 86 | + return 0; |
|
| 87 | + } |
|
| 88 | + return 10; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @inheritDoc |
|
| 93 | - */ |
|
| 94 | - public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
| 95 | - return SearchResult::complete( |
|
| 96 | - $this->l10n->t('Comments'), |
|
| 97 | - array_map(function (Result $result) { |
|
| 98 | - $path = $result->path; |
|
| 99 | - $pathInfo = pathinfo($path); |
|
| 100 | - $isUser = $this->userManager->userExists($result->authorId); |
|
| 101 | - $avatarUrl = $isUser |
|
| 102 | - ? $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42]) |
|
| 103 | - : $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]); |
|
| 104 | - return new SearchResultEntry( |
|
| 105 | - $avatarUrl, |
|
| 106 | - $result->name, |
|
| 107 | - $path, |
|
| 108 | - $this->urlGenerator->linkToRouteAbsolute('files.view.index',[ |
|
| 109 | - 'dir' => $pathInfo['dirname'], |
|
| 110 | - 'scrollto' => $pathInfo['basename'], |
|
| 111 | - ]), |
|
| 112 | - '', |
|
| 113 | - true |
|
| 114 | - ); |
|
| 115 | - }, $this->legacyProvider->search($query->getTerm())) |
|
| 116 | - ); |
|
| 117 | - } |
|
| 91 | + /** |
|
| 92 | + * @inheritDoc |
|
| 93 | + */ |
|
| 94 | + public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
| 95 | + return SearchResult::complete( |
|
| 96 | + $this->l10n->t('Comments'), |
|
| 97 | + array_map(function (Result $result) { |
|
| 98 | + $path = $result->path; |
|
| 99 | + $pathInfo = pathinfo($path); |
|
| 100 | + $isUser = $this->userManager->userExists($result->authorId); |
|
| 101 | + $avatarUrl = $isUser |
|
| 102 | + ? $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42]) |
|
| 103 | + : $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]); |
|
| 104 | + return new SearchResultEntry( |
|
| 105 | + $avatarUrl, |
|
| 106 | + $result->name, |
|
| 107 | + $path, |
|
| 108 | + $this->urlGenerator->linkToRouteAbsolute('files.view.index',[ |
|
| 109 | + 'dir' => $pathInfo['dirname'], |
|
| 110 | + 'scrollto' => $pathInfo['basename'], |
|
| 111 | + ]), |
|
| 112 | + '', |
|
| 113 | + true |
|
| 114 | + ); |
|
| 115 | + }, $this->legacyProvider->search($query->getTerm())) |
|
| 116 | + ); |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | public function search(IUser $user, ISearchQuery $query): SearchResult { |
| 95 | 95 | return SearchResult::complete( |
| 96 | 96 | $this->l10n->t('Comments'), |
| 97 | - array_map(function (Result $result) { |
|
| 97 | + array_map(function(Result $result) { |
|
| 98 | 98 | $path = $result->path; |
| 99 | 99 | $pathInfo = pathinfo($path); |
| 100 | 100 | $isUser = $this->userManager->userExists($result->authorId); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | $avatarUrl, |
| 106 | 106 | $result->name, |
| 107 | 107 | $path, |
| 108 | - $this->urlGenerator->linkToRouteAbsolute('files.view.index',[ |
|
| 108 | + $this->urlGenerator->linkToRouteAbsolute('files.view.index', [ |
|
| 109 | 109 | 'dir' => $pathInfo['dirname'], |
| 110 | 110 | 'scrollto' => $pathInfo['basename'], |
| 111 | 111 | ]), |
@@ -42,98 +42,98 @@ |
||
| 42 | 42 | |
| 43 | 43 | class FilesSearchProvider implements IProvider { |
| 44 | 44 | |
| 45 | - /** @var File */ |
|
| 46 | - private $fileSearch; |
|
| 47 | - |
|
| 48 | - /** @var IL10N */ |
|
| 49 | - private $l10n; |
|
| 50 | - |
|
| 51 | - /** @var IURLGenerator */ |
|
| 52 | - private $urlGenerator; |
|
| 53 | - |
|
| 54 | - /** @var IMimeTypeDetector */ |
|
| 55 | - private $mimeTypeDetector; |
|
| 56 | - |
|
| 57 | - /** @var IRootFolder */ |
|
| 58 | - private $rootFolder; |
|
| 59 | - |
|
| 60 | - public function __construct(File $fileSearch, |
|
| 61 | - IL10N $l10n, |
|
| 62 | - IURLGenerator $urlGenerator, |
|
| 63 | - IMimeTypeDetector $mimeTypeDetector, |
|
| 64 | - IRootFolder $rootFolder) { |
|
| 65 | - $this->l10n = $l10n; |
|
| 66 | - $this->fileSearch = $fileSearch; |
|
| 67 | - $this->urlGenerator = $urlGenerator; |
|
| 68 | - $this->mimeTypeDetector = $mimeTypeDetector; |
|
| 69 | - $this->rootFolder = $rootFolder; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @inheritDoc |
|
| 74 | - */ |
|
| 75 | - public function getId(): string { |
|
| 76 | - return 'files'; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @inheritDoc |
|
| 81 | - */ |
|
| 82 | - public function getName(): string { |
|
| 83 | - return $this->l10n->t('Files'); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @inheritDoc |
|
| 88 | - */ |
|
| 89 | - public function getOrder(string $route, array $routeParameters): int { |
|
| 90 | - if ($route === 'files.View.index') { |
|
| 91 | - // Before comments |
|
| 92 | - return -5; |
|
| 93 | - } |
|
| 94 | - return 5; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @inheritDoc |
|
| 99 | - */ |
|
| 100 | - public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
| 101 | - |
|
| 102 | - // Make sure we setup the users filesystem |
|
| 103 | - $this->rootFolder->getUserFolder($user->getUID()); |
|
| 104 | - |
|
| 105 | - return SearchResult::complete( |
|
| 106 | - $this->l10n->t('Files'), |
|
| 107 | - array_map(function (FileResult $result) { |
|
| 108 | - // Generate thumbnail url |
|
| 109 | - $thumbnailUrl = $result->has_preview |
|
| 110 | - ? $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]) |
|
| 111 | - : ''; |
|
| 112 | - |
|
| 113 | - return new SearchResultEntry( |
|
| 114 | - $thumbnailUrl, |
|
| 115 | - $result->name, |
|
| 116 | - $this->formatSubline($result), |
|
| 117 | - $this->urlGenerator->getAbsoluteURL($result->link), |
|
| 118 | - $result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type) |
|
| 119 | - ); |
|
| 120 | - }, $this->fileSearch->search($query->getTerm())) |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Format subline for files |
|
| 126 | - * |
|
| 127 | - * @param FileResult $result |
|
| 128 | - * @return string |
|
| 129 | - */ |
|
| 130 | - private function formatSubline($result): string { |
|
| 131 | - // Do not show the location if the file is in root |
|
| 132 | - if ($result->path === '/' . $result->name) { |
|
| 133 | - return ''; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $path = ltrim(dirname($result->path), '/'); |
|
| 137 | - return $this->l10n->t('in %s', [$path]); |
|
| 138 | - } |
|
| 45 | + /** @var File */ |
|
| 46 | + private $fileSearch; |
|
| 47 | + |
|
| 48 | + /** @var IL10N */ |
|
| 49 | + private $l10n; |
|
| 50 | + |
|
| 51 | + /** @var IURLGenerator */ |
|
| 52 | + private $urlGenerator; |
|
| 53 | + |
|
| 54 | + /** @var IMimeTypeDetector */ |
|
| 55 | + private $mimeTypeDetector; |
|
| 56 | + |
|
| 57 | + /** @var IRootFolder */ |
|
| 58 | + private $rootFolder; |
|
| 59 | + |
|
| 60 | + public function __construct(File $fileSearch, |
|
| 61 | + IL10N $l10n, |
|
| 62 | + IURLGenerator $urlGenerator, |
|
| 63 | + IMimeTypeDetector $mimeTypeDetector, |
|
| 64 | + IRootFolder $rootFolder) { |
|
| 65 | + $this->l10n = $l10n; |
|
| 66 | + $this->fileSearch = $fileSearch; |
|
| 67 | + $this->urlGenerator = $urlGenerator; |
|
| 68 | + $this->mimeTypeDetector = $mimeTypeDetector; |
|
| 69 | + $this->rootFolder = $rootFolder; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @inheritDoc |
|
| 74 | + */ |
|
| 75 | + public function getId(): string { |
|
| 76 | + return 'files'; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @inheritDoc |
|
| 81 | + */ |
|
| 82 | + public function getName(): string { |
|
| 83 | + return $this->l10n->t('Files'); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @inheritDoc |
|
| 88 | + */ |
|
| 89 | + public function getOrder(string $route, array $routeParameters): int { |
|
| 90 | + if ($route === 'files.View.index') { |
|
| 91 | + // Before comments |
|
| 92 | + return -5; |
|
| 93 | + } |
|
| 94 | + return 5; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @inheritDoc |
|
| 99 | + */ |
|
| 100 | + public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
| 101 | + |
|
| 102 | + // Make sure we setup the users filesystem |
|
| 103 | + $this->rootFolder->getUserFolder($user->getUID()); |
|
| 104 | + |
|
| 105 | + return SearchResult::complete( |
|
| 106 | + $this->l10n->t('Files'), |
|
| 107 | + array_map(function (FileResult $result) { |
|
| 108 | + // Generate thumbnail url |
|
| 109 | + $thumbnailUrl = $result->has_preview |
|
| 110 | + ? $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]) |
|
| 111 | + : ''; |
|
| 112 | + |
|
| 113 | + return new SearchResultEntry( |
|
| 114 | + $thumbnailUrl, |
|
| 115 | + $result->name, |
|
| 116 | + $this->formatSubline($result), |
|
| 117 | + $this->urlGenerator->getAbsoluteURL($result->link), |
|
| 118 | + $result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type) |
|
| 119 | + ); |
|
| 120 | + }, $this->fileSearch->search($query->getTerm())) |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Format subline for files |
|
| 126 | + * |
|
| 127 | + * @param FileResult $result |
|
| 128 | + * @return string |
|
| 129 | + */ |
|
| 130 | + private function formatSubline($result): string { |
|
| 131 | + // Do not show the location if the file is in root |
|
| 132 | + if ($result->path === '/' . $result->name) { |
|
| 133 | + return ''; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $path = ltrim(dirname($result->path), '/'); |
|
| 137 | + return $this->l10n->t('in %s', [$path]); |
|
| 138 | + } |
|
| 139 | 139 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | return SearchResult::complete( |
| 106 | 106 | $this->l10n->t('Files'), |
| 107 | - array_map(function (FileResult $result) { |
|
| 107 | + array_map(function(FileResult $result) { |
|
| 108 | 108 | // Generate thumbnail url |
| 109 | 109 | $thumbnailUrl = $result->has_preview |
| 110 | 110 | ? $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]) |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | private function formatSubline($result): string { |
| 131 | 131 | // Do not show the location if the file is in root |
| 132 | - if ($result->path === '/' . $result->name) { |
|
| 132 | + if ($result->path === '/'.$result->name) { |
|
| 133 | 133 | return ''; |
| 134 | 134 | } |
| 135 | 135 | |