beginning to implement search
This commit is contained in:
parent
d21ea0b78c
commit
0199897841
@ -16,21 +16,10 @@
|
||||
<dependencies>
|
||||
<nextcloud min-version="20" max-version="20"/>
|
||||
</dependencies>
|
||||
<commands>
|
||||
<command>OCA\Radio\Command\Search</command>
|
||||
</commands>
|
||||
<navigations>
|
||||
<navigation>
|
||||
<name>Radio</name>
|
||||
<route>radio.page.index</route>
|
||||
</navigation>
|
||||
</navigations>
|
||||
<activity>
|
||||
<settings>
|
||||
<setting>OCA\Radio\Activity\Setting</setting>
|
||||
</settings>
|
||||
<providers>
|
||||
<provider>OCA\Radio\Activity\Provider</provider>
|
||||
</providers>
|
||||
</activity>
|
||||
</info>
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace OCA\Radio\AppInfo;
|
||||
|
||||
use OCA\Radio\Search\SearchProvider;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
@ -20,6 +21,7 @@ class Application extends App implements IBootstrap {
|
||||
|
||||
public function register(IRegistrationContext $context): void {
|
||||
|
||||
$context->registerSearchProvider(SearchProvider::class);
|
||||
$context->registerService('request', static function ($c) {
|
||||
return $c->get(IRequest::class);
|
||||
});
|
||||
|
59
lib/Search/SearchProvider.php
Normal file
59
lib/Search/SearchProvider.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?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
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user