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 OCA\BigBlueButton\Db\Room;
|
|
|
|
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;
|
|
|
|
use function array_map;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return Application::ORDER;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getAccess(string $access): string {
|
|
|
|
switch ($access) {
|
|
|
|
case 'public':
|
|
|
|
$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 {
|
|
|
|
$rooms = $this->service->search(
|
|
|
|
$user,
|
|
|
|
$query
|
|
|
|
);
|
|
|
|
|
2022-10-26 19:29:28 +02:00
|
|
|
$results = [];
|
|
|
|
|
|
|
|
foreach($rooms as $room) {
|
|
|
|
$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(
|
|
|
|
'BBB',
|
|
|
|
$results
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|