urlGenerator = $urlGenerator; $this->circleService = $circleService; } /** * @param string $needle * * @return list */ public function search(string $needle): array { $result = []; foreach (self::$SERVICES as $entry) { /** @var ISearch $service */ $service = Server::get($entry); $result = array_merge($result, $service->search($needle)); } return $result; } /** * @param string $term * @param array $options * * @return UnifiedSearchResult[] * @throws RequestBuilderException */ public function unifiedSearch(string $term, array $options): array { $result = []; $probe = $this->generateSearchProbe($term, $options); try { $circles = $this->circleService->getCircles($probe); } catch (InitiatorNotFoundException $e) { return []; } $iconPath = $this->urlGenerator->imagePath(Application::APP_ID, 'circles.svg'); $icon = $this->urlGenerator->getAbsoluteURL($iconPath); foreach ($circles as $circle) { $result[] = new UnifiedSearchResult( '', $circle->getDisplayName(), $circle->getDescription(), $circle->getUrl(), $icon ); } return $result; } /** * @param string $term * @param array $options * * @return CircleProbe */ private function generateSearchProbe(string $term, array $options): CircleProbe { $probe = new CircleProbe(); switch ($this->getInt('level', $options)) { case Member::LEVEL_MEMBER: $probe->mustBeMember(); break; case Member::LEVEL_MODERATOR: $probe->mustBeModerator(); break; case Member::LEVEL_ADMIN: $probe->mustBeAdmin(); break; case Member::LEVEL_OWNER: $probe->mustBeOwner(); break; } $probe->filterHiddenCircles() ->filterBackendCircles(); $circle = new Circle(); $circle->setDisplayName($term); $probe->setFilterCircle($circle); return $probe; } }