Feature: [Calendar doc] Pick document to generate inside the edit/new form

This commit is contained in:
2022-11-29 15:27:36 +01:00
parent be5f87348b
commit e97a04ab54
3 changed files with 83 additions and 12 deletions

View File

@@ -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;
@@ -64,6 +65,8 @@ class CalendarController extends AbstractController
private SerializerInterface $serializer;
private TranslatableStringHelperInterface $translatableStringHelper;
private UserRepositoryInterface $userRepository;
public function __construct(
@@ -74,6 +77,7 @@ class CalendarController extends AbstractController
PaginatorFactory $paginator,
RemoteCalendarConnectorInterface $remoteCalendarConnector,
SerializerInterface $serializer,
TranslatableStringHelperInterface $translatableStringHelper,
PersonRepository $personRepository,
AccompanyingPeriodRepository $accompanyingPeriodRepository,
UserRepositoryInterface $userRepository
@@ -85,6 +89,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;
@@ -170,8 +175,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);
@@ -181,8 +191,18 @@ class CalendarController extends AbstractController
$this->addFlash('success', $this->get('translator')->trans('Success : calendar item updated!'));
if ($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);
@@ -200,6 +220,7 @@ class CalendarController extends AbstractController
'accompanyingCourse' => $entity->getAccompanyingPeriod(),
'person' => $entity->getPerson(),
'entity_json' => $entity_array,
'templates' => $templates,
]);
}
@@ -330,8 +351,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);
@@ -342,8 +368,18 @@ class CalendarController extends AbstractController
$this->addFlash('success', $this->get('translator')->trans('Success : calendar item created!'));
if ($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);
@@ -366,6 +402,7 @@ class CalendarController extends AbstractController
'entity' => $entity,
'form' => $form->createView(),
'entity_json' => $entity_array,
'templates' => $templates,
]);
}