accompanyingPeriodWorkEvaluationRepository = $accompanyingPeriodWorkEvaluationRepository; $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; $this->serializer = $serializer; $this->paginatorFactory = $paginatorFactory; $this->security = $security; } /** * @Route("/api/1.0/person/docgen/template/by-evaluation/{id}.{_format}", * requirements={"format": "json"}) */ public function listTemplateByEvaluation(Evaluation $evaluation, string $_format): JsonResponse { if ('json' !== $_format) { throw new BadRequestHttpException('format not supported'); } $evaluations = array_filter( $this->docGeneratorTemplateRepository ->findByEntity(AccompanyingPeriodWorkEvaluation::class), static function (DocGeneratorTemplate $t) use ($evaluation) { $ids = $t->getOptions()['evaluations'] ?? []; return in_array($evaluation->getId(), $ids, true); } ); $paginator = $this->paginatorFactory->create(count($evaluations)); $paginator->setItemsPerPage(count($evaluations)); return new JsonResponse($this->serializer->serialize( new Collection(array_values($evaluations), $paginator), 'json', [ AbstractNormalizer::GROUPS => ['read'], ] ), JsonResponse::HTTP_OK, [], true); } /** * @Route("/api/1.0/person/accompanying-period/work/evaluation/my-near-end") */ public function myWorksNearEndDate(Request $request): JsonResponse { $total = $this->accompanyingPeriodWorkEvaluationRepository ->countNearMaxDateByUser($this->security->getUser()); if ($request->query->getBoolean('countOnly', false)) { return new JsonResponse( $this->serializer->serialize(new Counter($total), 'json', ['groups' => 'read']), JsonResponse::HTTP_OK, [], true ); } $paginator = $this->paginatorFactory->create($total); $works = $this->accompanyingPeriodWorkEvaluationRepository ->findNearMaxDateByUser( $this->security->getUser(), $paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber() ); $collection = new Collection($works, $paginator); return new JsonResponse( $this->serializer->serialize($collection, 'json', ['groups' => 'read']), JsonResponse::HTTP_OK, [], true ); } }