prepareQuery($query, $paramFetcher); $factory = $this->getDateTimeFactory(); $begin = $paramFetcher->get('begin'); if (\is_string($begin) && $begin !== '') { $query->setBegin($factory->createDateTime($begin)); } $end = $paramFetcher->get('end'); if (\is_string($end) && $end !== '') { $query->setEnd($factory->createDateTime($end)); } /** @var array $status */ $status = $paramFetcher->get('status'); if (\is_array($status)) { foreach ($status as $s) { $query->addStatus($s); } } /** @var array $customers */ $customers = $paramFetcher->get('customers'); foreach ($customerRepository->findByIds(array_unique($customers)) as $customer) { if (!$this->isGranted('access', $customer)) { throw $this->createAccessDeniedException('Cannot access Customer: ' . $customer->getId()); } $query->addCustomer($customer); } $data = $this->repository->getPagerfantaForQuery($query); $view = new View($data, 200); $view->getContext()->setGroups(self::GROUPS_COLLECTION); return $this->viewHandler->handle($view); } /** * Fetch invoice */ #[IsGranted('view_invoice')] #[IsGranted(new Expression("is_granted('access', subject.getCustomer())"), 'invoice')] #[OA\Response(response: 200, description: 'Returns one invoice', content: new OA\JsonContent(ref: '#/components/schemas/Invoice'))] #[Route(methods: ['GET'], path: '/{id}', name: 'get_invoice', requirements: ['id' => '\d+'])] public function getAction(Invoice $invoice): Response { $view = new View($invoice, 200); $view->getContext()->setGroups(self::GROUPS_ENTITY); return $this->viewHandler->handle($view); } }