2018-04-18 12:29:49 +03:00
|
|
|
<?php
|
2020-06-22 13:19:34 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-04-18 12:29:49 +03:00
|
|
|
/**
|
2020-06-22 13:19:34 +03:00
|
|
|
* @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
|
2018-04-18 12:29:49 +03:00
|
|
|
*
|
2020-06-22 13:19:34 +03:00
|
|
|
* @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-03 21:57:53 +03:00
|
|
|
*
|
2018-04-18 12:29:49 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2020-06-22 13:19:34 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-04-18 12:29:49 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Comments\Search;
|
|
|
|
|
2020-06-22 13:19:34 +03:00
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\IURLGenerator;
|
2018-04-18 12:29:49 +03:00
|
|
|
use OCP\IUser;
|
2020-06-22 13:19:34 +03:00
|
|
|
use OCP\Search\IProvider;
|
|
|
|
use OCP\Search\ISearchQuery;
|
|
|
|
use OCP\Search\SearchResult;
|
|
|
|
use function array_map;
|
|
|
|
use function pathinfo;
|
2018-04-18 12:29:49 +03:00
|
|
|
|
2020-06-22 13:19:34 +03:00
|
|
|
class Provider implements IProvider {
|
2018-04-18 12:29:49 +03:00
|
|
|
|
2020-06-22 13:19:34 +03:00
|
|
|
/** @var IL10N */
|
|
|
|
private $l10n;
|
2018-04-23 15:58:43 +03:00
|
|
|
|
2020-06-22 13:19:34 +03:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
2018-04-23 15:58:43 +03:00
|
|
|
|
2020-06-22 13:19:34 +03:00
|
|
|
/** @var LegacyProvider */
|
|
|
|
private $legacyProvider;
|
2018-04-23 15:58:43 +03:00
|
|
|
|
2020-06-22 13:19:34 +03:00
|
|
|
public function __construct(IL10N $l10n,
|
|
|
|
IURLGenerator $urlGenerator,
|
|
|
|
LegacyProvider $legacyProvider) {
|
|
|
|
$this->l10n = $l10n;
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
|
|
|
$this->legacyProvider = $legacyProvider;
|
2018-04-18 12:29:49 +03:00
|
|
|
}
|
|
|
|
|
2020-06-22 13:19:34 +03:00
|
|
|
public function getId(): string {
|
|
|
|
return 'comments';
|
|
|
|
}
|
2018-04-18 12:29:49 +03:00
|
|
|
|
2020-06-22 13:19:34 +03:00
|
|
|
public function search(IUser $user, ISearchQuery $query): SearchResult {
|
|
|
|
return SearchResult::complete(
|
|
|
|
$this->l10n->t('Comments'),
|
|
|
|
array_map(function (Result $result) {
|
|
|
|
$path = $result->path;
|
|
|
|
$pathInfo = pathinfo($path);
|
|
|
|
return new CommentsSearchResultEntry(
|
|
|
|
$this->urlGenerator->linkToRoute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]),
|
|
|
|
$result->name,
|
|
|
|
$path,
|
|
|
|
$this->urlGenerator->linkToRoute(
|
|
|
|
'files.view.index',
|
|
|
|
[
|
|
|
|
'dir' => $pathInfo['dirname'],
|
|
|
|
'scrollto' => $pathInfo['basename'],
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}, $this->legacyProvider->search($query->getTerm()))
|
|
|
|
);
|
2018-04-18 12:29:49 +03:00
|
|
|
}
|
|
|
|
}
|