60 lines
1.2 KiB
PHP
60 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace OCA\Radio\Search;
|
||
|
|
||
|
use OCA\Radio\AppInfo\Application;
|
||
|
use OCP\IUser;
|
||
|
use OCP\IURLGenerator;
|
||
|
use OCP\Search\IProvider;
|
||
|
use OCP\Search\ISearchQuery;
|
||
|
use OCP\Search\SearchResult;
|
||
|
use OCP\Search\SearchResultEntry;
|
||
|
|
||
|
use function urlencode;
|
||
|
|
||
|
class SearchProvider implements IProvider {
|
||
|
|
||
|
/** @var IURLGenerator */
|
||
|
private $url;
|
||
|
|
||
|
public function __construct(
|
||
|
IURLGenerator $url
|
||
|
) {
|
||
|
$this->url = $url;
|
||
|
}
|
||
|
|
||
|
public function getId(): string {
|
||
|
return Application::APP_ID;
|
||
|
}
|
||
|
|
||
|
public function getName(): string {
|
||
|
return 'Radio';
|
||
|
}
|
||
|
|
||
|
public function getOrder(string $route, array $routeParameters): int {
|
||
|
if (strpos($route, 'files' . '.') === 0) {
|
||
|
return 25;
|
||
|
} elseif (strpos($route, Application::APP_ID . '.') === 0) {
|
||
|
return -1;
|
||
|
}
|
||
|
return 4;
|
||
|
}
|
||
|
|
||
|
public function search(IUser $user, ISearchQuery $query): SearchResult {
|
||
|
// create SearchResultEntry from Note
|
||
|
$result = [new SearchResultEntry(
|
||
|
'',
|
||
|
'SRF Virus',
|
||
|
'alternative, youth',
|
||
|
$this->url->linkToRouteAbsolute('radio.page.index') . 'search/' . urlencode($query->getTerm()), // FIXME: urlencode working?
|
||
|
'icon-notes-trans'
|
||
|
)];
|
||
|
return SearchResult::complete(
|
||
|
$this->getName(),
|
||
|
$result
|
||
|
);
|
||
|
}
|
||
|
}
|