@@ -46,100 +46,100 @@ |
||
46 | 46 | */ |
47 | 47 | class SearchResultEntry implements JsonSerializable { |
48 | 48 | |
49 | - /** |
|
50 | - * @var string |
|
51 | - * @since 20.0.0 |
|
52 | - */ |
|
53 | - protected $thumbnailUrl; |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + * @since 20.0.0 |
|
52 | + */ |
|
53 | + protected $thumbnailUrl; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var string |
|
57 | - * @since 20.0.0 |
|
58 | - */ |
|
59 | - protected $title; |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + * @since 20.0.0 |
|
58 | + */ |
|
59 | + protected $title; |
|
60 | 60 | |
61 | - /** |
|
62 | - * @var string |
|
63 | - * @since 20.0.0 |
|
64 | - */ |
|
65 | - protected $subline; |
|
61 | + /** |
|
62 | + * @var string |
|
63 | + * @since 20.0.0 |
|
64 | + */ |
|
65 | + protected $subline; |
|
66 | 66 | |
67 | - /** |
|
68 | - * @var string |
|
69 | - * @since 20.0.0 |
|
70 | - */ |
|
71 | - protected $resourceUrl; |
|
67 | + /** |
|
68 | + * @var string |
|
69 | + * @since 20.0.0 |
|
70 | + */ |
|
71 | + protected $resourceUrl; |
|
72 | 72 | |
73 | - /** |
|
74 | - * @var string |
|
75 | - * @since 20.0.0 |
|
76 | - */ |
|
77 | - protected $icon; |
|
73 | + /** |
|
74 | + * @var string |
|
75 | + * @since 20.0.0 |
|
76 | + */ |
|
77 | + protected $icon; |
|
78 | 78 | |
79 | - /** |
|
80 | - * @var boolean |
|
81 | - * @since 20.0.0 |
|
82 | - */ |
|
83 | - protected $rounded; |
|
79 | + /** |
|
80 | + * @var boolean |
|
81 | + * @since 20.0.0 |
|
82 | + */ |
|
83 | + protected $rounded; |
|
84 | 84 | |
85 | - /** |
|
86 | - * @var string[] |
|
87 | - * @psalm-var array<string, string> |
|
88 | - * @since 20.0.0 |
|
89 | - */ |
|
90 | - protected $attributes = []; |
|
85 | + /** |
|
86 | + * @var string[] |
|
87 | + * @psalm-var array<string, string> |
|
88 | + * @since 20.0.0 |
|
89 | + */ |
|
90 | + protected $attributes = []; |
|
91 | 91 | |
92 | - /** |
|
93 | - * @param string $thumbnailUrl a relative or absolute URL to the thumbnail or icon of the entry |
|
94 | - * @param string $title a main title of the entry |
|
95 | - * @param string $subline the secondary line of the entry |
|
96 | - * @param string $resourceUrl the URL where the user can find the detail, like a deep link inside the app |
|
97 | - * @param string $icon the icon class or url to the icon |
|
98 | - * @param boolean $rounded is the thumbnail rounded |
|
99 | - * |
|
100 | - * @since 20.0.0 |
|
101 | - */ |
|
102 | - public function __construct(string $thumbnailUrl, |
|
103 | - string $title, |
|
104 | - string $subline, |
|
105 | - string $resourceUrl, |
|
106 | - string $icon = '', |
|
107 | - bool $rounded = false) { |
|
108 | - $this->thumbnailUrl = $thumbnailUrl; |
|
109 | - $this->title = $title; |
|
110 | - $this->subline = $subline; |
|
111 | - $this->resourceUrl = $resourceUrl; |
|
112 | - $this->icon = $icon; |
|
113 | - $this->rounded = $rounded; |
|
114 | - } |
|
92 | + /** |
|
93 | + * @param string $thumbnailUrl a relative or absolute URL to the thumbnail or icon of the entry |
|
94 | + * @param string $title a main title of the entry |
|
95 | + * @param string $subline the secondary line of the entry |
|
96 | + * @param string $resourceUrl the URL where the user can find the detail, like a deep link inside the app |
|
97 | + * @param string $icon the icon class or url to the icon |
|
98 | + * @param boolean $rounded is the thumbnail rounded |
|
99 | + * |
|
100 | + * @since 20.0.0 |
|
101 | + */ |
|
102 | + public function __construct(string $thumbnailUrl, |
|
103 | + string $title, |
|
104 | + string $subline, |
|
105 | + string $resourceUrl, |
|
106 | + string $icon = '', |
|
107 | + bool $rounded = false) { |
|
108 | + $this->thumbnailUrl = $thumbnailUrl; |
|
109 | + $this->title = $title; |
|
110 | + $this->subline = $subline; |
|
111 | + $this->resourceUrl = $resourceUrl; |
|
112 | + $this->icon = $icon; |
|
113 | + $this->rounded = $rounded; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Add optional attributes to the result entry, e.g. an ID or some other |
|
118 | - * context information that can be read by the client application |
|
119 | - * |
|
120 | - * @param string $key |
|
121 | - * @param string $value |
|
122 | - * |
|
123 | - * @since 20.0.0 |
|
124 | - */ |
|
125 | - public function addAttribute(string $key, string $value): void { |
|
126 | - $this->attributes[$key] = $value; |
|
127 | - } |
|
116 | + /** |
|
117 | + * Add optional attributes to the result entry, e.g. an ID or some other |
|
118 | + * context information that can be read by the client application |
|
119 | + * |
|
120 | + * @param string $key |
|
121 | + * @param string $value |
|
122 | + * |
|
123 | + * @since 20.0.0 |
|
124 | + */ |
|
125 | + public function addAttribute(string $key, string $value): void { |
|
126 | + $this->attributes[$key] = $value; |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @return array |
|
131 | - * |
|
132 | - * @since 20.0.0 |
|
133 | - */ |
|
134 | - public function jsonSerialize(): array { |
|
135 | - return [ |
|
136 | - 'thumbnailUrl' => $this->thumbnailUrl, |
|
137 | - 'title' => $this->title, |
|
138 | - 'subline' => $this->subline, |
|
139 | - 'resourceUrl' => $this->resourceUrl, |
|
140 | - 'icon' => $this->icon, |
|
141 | - 'rounded' => $this->rounded, |
|
142 | - 'attributes' => $this->attributes, |
|
143 | - ]; |
|
144 | - } |
|
129 | + /** |
|
130 | + * @return array |
|
131 | + * |
|
132 | + * @since 20.0.0 |
|
133 | + */ |
|
134 | + public function jsonSerialize(): array { |
|
135 | + return [ |
|
136 | + 'thumbnailUrl' => $this->thumbnailUrl, |
|
137 | + 'title' => $this->title, |
|
138 | + 'subline' => $this->subline, |
|
139 | + 'resourceUrl' => $this->resourceUrl, |
|
140 | + 'icon' => $this->icon, |
|
141 | + 'rounded' => $this->rounded, |
|
142 | + 'attributes' => $this->attributes, |
|
143 | + ]; |
|
144 | + } |
|
145 | 145 | } |
@@ -42,101 +42,101 @@ |
||
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 | - $searchResultEntry = 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 | - $searchResultEntry->addAttribute('fileId', (string)$result->id); |
|
121 | - $searchResultEntry->addAttribute('path', $result->path); |
|
122 | - return $searchResultEntry; |
|
123 | - }, $this->fileSearch->search($query->getTerm())) |
|
124 | - ); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Format subline for files |
|
129 | - * |
|
130 | - * @param FileResult $result |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - private function formatSubline($result): string { |
|
134 | - // Do not show the location if the file is in root |
|
135 | - if ($result->path === '/' . $result->name) { |
|
136 | - return ''; |
|
137 | - } |
|
138 | - |
|
139 | - $path = ltrim(dirname($result->path), '/'); |
|
140 | - return $this->l10n->t('in %s', [$path]); |
|
141 | - } |
|
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 | + $searchResultEntry = 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 | + $searchResultEntry->addAttribute('fileId', (string)$result->id); |
|
121 | + $searchResultEntry->addAttribute('path', $result->path); |
|
122 | + return $searchResultEntry; |
|
123 | + }, $this->fileSearch->search($query->getTerm())) |
|
124 | + ); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Format subline for files |
|
129 | + * |
|
130 | + * @param FileResult $result |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + private function formatSubline($result): string { |
|
134 | + // Do not show the location if the file is in root |
|
135 | + if ($result->path === '/' . $result->name) { |
|
136 | + return ''; |
|
137 | + } |
|
138 | + |
|
139 | + $path = ltrim(dirname($result->path), '/'); |
|
140 | + return $this->l10n->t('in %s', [$path]); |
|
141 | + } |
|
142 | 142 | } |
@@ -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]) |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $this->urlGenerator->getAbsoluteURL($result->link), |
118 | 118 | $result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type) |
119 | 119 | ); |
120 | - $searchResultEntry->addAttribute('fileId', (string)$result->id); |
|
120 | + $searchResultEntry->addAttribute('fileId', (string) $result->id); |
|
121 | 121 | $searchResultEntry->addAttribute('path', $result->path); |
122 | 122 | return $searchResultEntry; |
123 | 123 | }, $this->fileSearch->search($query->getTerm())) |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | private function formatSubline($result): string { |
134 | 134 | // Do not show the location if the file is in root |
135 | - if ($result->path === '/' . $result->name) { |
|
135 | + if ($result->path === '/'.$result->name) { |
|
136 | 136 | return ''; |
137 | 137 | } |
138 | 138 |