security = $security; $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; $this->urlGenerator = $urlGenerator; $this->engine = $engine; } /** * @Route("/{_locale}/calendar/docgen/pick/{id}", name="chill_calendar_calendardoc_pick_template") */ public function pickTemplate(Calendar $calendar): Response { if (!$this->security->isGranted(CalendarVoter::SEE, $calendar)) { throw new AccessDeniedException('Not authorized to see this calendar'); } if (0 === $number = $this->docGeneratorTemplateRepository->countByEntity(Calendar::class)) { throw new RuntimeException('should not be redirected to this page if no template'); } if (1 === $number) { $templates = $this->docGeneratorTemplateRepository->findByEntity(Calendar::class); return new RedirectResponse( $this->urlGenerator->generate( 'chill_docgenerator_generate_from_template', [ 'template' => $templates[0]->getId(), 'entityClassName' => Calendar::class, 'entityId' => $calendar->getId(), ] ) ); } return new Response( $this->engine->render('@ChillCalendar/CalendarDoc/pick_template.html.twig', [ 'calendar' => $calendar, 'accompanyingCourse' => $calendar->getAccompanyingPeriod(), ]) ); } }