diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index f1abe9736..db5f2ec16 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -22,6 +22,7 @@ use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\UserRepositoryInterface; use Chill\MainBundle\Templating\Listing\FilterOrderHelper; use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Repository\AccompanyingPeriodRepository; @@ -65,6 +66,8 @@ class CalendarController extends AbstractController private SerializerInterface $serializer; + private TranslatableStringHelperInterface $translatableStringHelper; + private UserRepositoryInterface $userRepository; public function __construct( @@ -75,6 +78,7 @@ class CalendarController extends AbstractController PaginatorFactory $paginator, RemoteCalendarConnectorInterface $remoteCalendarConnector, SerializerInterface $serializer, + TranslatableStringHelperInterface $translatableStringHelper, PersonRepository $personRepository, AccompanyingPeriodRepository $accompanyingPeriodRepository, UserRepositoryInterface $userRepository @@ -86,6 +90,7 @@ class CalendarController extends AbstractController $this->paginator = $paginator; $this->remoteCalendarConnector = $remoteCalendarConnector; $this->serializer = $serializer; + $this->translatableStringHelper = $translatableStringHelper; $this->personRepository = $personRepository; $this->accompanyingPeriodRepository = $accompanyingPeriodRepository; $this->userRepository = $userRepository; @@ -171,8 +176,13 @@ class CalendarController extends AbstractController $form = $this->createForm(CalendarType::class, $entity) ->add('save', SubmitType::class); - if (0 < $this->docGeneratorTemplateRepository->countByEntity(Calendar::class)) { - $form->add('save_and_create_doc', SubmitType::class); + $form->add('save_and_upload_doc', SubmitType::class); + $templates = $this->docGeneratorTemplateRepository->findByEntity(Calendar::class); + + foreach ($templates as $template) { + $form->add('save_and_generate_doc_' . $template->getId(), SubmitType::class, [ + 'label' => $this->translatableStringHelper->localize($template->getName()), + ]); } $form->handleRequest($request); @@ -182,8 +192,18 @@ class CalendarController extends AbstractController $this->addFlash('success', $this->get('translator')->trans('Success : calendar item updated!')); - if ($form->has('save_and_create_doc') && $form->get('save_and_create_doc')->isClicked()) { - return $this->redirectToRoute('chill_calendar_calendardoc_pick_template', ['id' => $entity->getId()]); + if ($form->get('save_and_upload_doc')->isClicked()) { + return $this->redirectToRoute('chill_calendar_calendardoc_new', ['id' => $entity->getId()]); + } + + foreach ($templates as $template) { + if ($form->get('save_and_generate_doc_' . $template->getId())->isClicked()) { + return $this->redirectToRoute('chill_docgenerator_generate_from_template', [ + 'entityClassName' => Calendar::class, + 'entityId' => $entity->getId(), + 'template' => $template->getId(), + ]); + } } return new RedirectResponse($redirectRoute); @@ -201,6 +221,7 @@ class CalendarController extends AbstractController 'accompanyingCourse' => $entity->getAccompanyingPeriod(), 'person' => $entity->getPerson(), 'entity_json' => $entity_array, + 'templates' => $templates, ]); } @@ -333,8 +354,13 @@ class CalendarController extends AbstractController $form = $this->createForm(CalendarType::class, $entity) ->add('save', SubmitType::class); - if (0 < $this->docGeneratorTemplateRepository->countByEntity(Calendar::class)) { - $form->add('save_and_create_doc', SubmitType::class); + $templates = $this->docGeneratorTemplateRepository->findByEntity(Calendar::class); + $form->add('save_and_upload_doc', SubmitType::class); + + foreach ($templates as $template) { + $form->add('save_and_generate_doc_' . $template->getId(), SubmitType::class, [ + 'label' => $this->translatableStringHelper->localize($template->getName()), + ]); } $form->handleRequest($request); @@ -345,8 +371,18 @@ class CalendarController extends AbstractController $this->addFlash('success', $this->get('translator')->trans('Success : calendar item created!')); - if ($form->has('save_and_create_doc') && $form->get('save_and_create_doc')->isClicked()) { - return $this->redirectToRoute('chill_calendar_calendardoc_pick_template', ['id' => $entity->getId()]); + if ($form->get('save_and_upload_doc')->isClicked()) { + return $this->redirectToRoute('chill_calendar_calendardoc_new', ['id' => $entity->getId()]); + } + + foreach ($templates as $template) { + if ($form->get('save_and_generate_doc_' . $template->getId())->isClicked()) { + return $this->redirectToRoute('chill_docgenerator_generate_from_template', [ + 'entityClassName' => Calendar::class, + 'entityId' => $entity->getId(), + 'template' => $template->getId(), + ]); + } } if ('' !== $redirectRoute) { @@ -373,6 +409,7 @@ class CalendarController extends AbstractController 'entity' => $entity, 'form' => $form->createView(), 'entity_json' => $entity_array, + 'templates' => $templates, ]); } diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig index 7d72922d1..df814282a 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig @@ -77,9 +77,26 @@ {{ 'Cancel'|trans|chill_return_path_label }} - {% if form.save_and_create_doc is defined %} + {% if templates|length == 0 %}