cloud_bbb/lib/Search/Provider.php

96 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2022-10-16 14:11:28 +02:00
<?php
declare(strict_types=1);
namespace OCA\BigBlueButton\Search;
use OCA\BigBlueButton\AppInfo\Application;
use OCA\BigBlueButton\Service\RoomService;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Search\IProvider;
use OCP\Search\ISearchQuery;
use OCP\Search\SearchResult;
use OCP\Search\SearchResultEntry;
class Provider implements IProvider {
/** @var RoomService */
private $service;
/** @var IL10N */
private $l10n;
/** @var IURLGenerator */
private $urlGenerator;
public function __construct(RoomService $service, IL10N $l10n, IURLGenerator $urlGenerator) {
$this->service = $service;
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
}
public function getId(): string {
return Application::ID;
}
public function getName(): string {
return 'BBB';
}
public function getOrder(string $route, array $routeParameters): int {
if (strpos($route, Application::ID . '.') === 0) {
return -1;
}
2022-10-16 14:11:28 +02:00
return Application::ORDER;
}
private function getAccess(string $access): string {
switch ($access) {
case 'public':
2022-10-16 14:11:28 +02:00
$translatedAccess = $this->l10n->t('Public');
break;
case 'password':
$translatedAccess = $this->l10n->t('Internal + Password protection for guests');
break;
case 'waiting_room':
$translatedAccess = $this->l10n->t('Internal + Waiting room for guests');
break;
case 'waiting_room_all':
$translatedAccess = $this->l10n->t('Waiting room for all users');
break;
case 'internal':
$translatedAccess = $this->l10n->t('Internal');
break;
case 'internal_restricted':
$translatedAccess = $this->l10n->t('Internal restricted');
break;
}
return $translatedAccess;
}
public function search(IUser $user, ISearchQuery $query): SearchResult {
2022-10-16 14:11:28 +02:00
$rooms = $this->service->search(
$user,
$query
);
2022-10-26 19:29:28 +02:00
$results = [];
foreach ($rooms as $room) {
2022-10-26 19:29:28 +02:00
$results[] = new SearchResultEntry(
'',
$room->getName(),
$this->getAccess($room->getAccess()),
$this->urlGenerator->linkToRouteAbsolute('bbb.page.index'),
$this->urlGenerator->imagePath('bbb', 'app-grey.svg')
);
}
2022-10-16 14:11:28 +02:00
return SearchResult::complete(
2022-10-16 14:11:28 +02:00
'BBB',
$results
2022-10-16 14:11:28 +02:00
);
}
}