em = $em; $this->tokenStorage = $tokenStorage; $this->authorizationHelper = $authorizationHelper; $this->paginatorFactory = $paginatorFactory; } public function getOrder(): int { return 59866; } public function isActiveByDefault(): bool { return false; } public function renderResult(array $terms, $start = 0, $limit = 50, $options = array(), $format = 'html') { $centers = $this->authorizationHelper ->getReachableCenters( $this->tokenStorage->getToken()->getUser(), new Role(ThirdPartyVoter::SHOW) ); $total = $this->count($centers, $terms); $paginator = $this->paginatorFactory->create($total); // replace types in terms by types in query $terms['types'] = $options[SearchInterface::REQUEST_QUERY_PARAMETERS]['t']; $terms['is_active'] = true; if ($format === 'json') { return [ 'results' => $this->em->getRepository(ThirdParty::class) ->findByMemberOfCenters($centers, $start, $limit, $terms, ['array', ['tp.id', 'tp.name AS text']]), 'more' => $paginator->hasNextPage() ]; } } public function supports($domain, $format): bool { return self::NAME === $domain and $format === 'json'; } protected function count($centers, $terms): int { return $this->em->getRepository(ThirdParty::class) ->countByMemberOfCenters($centers, $terms); } }