From 49d1f780012d653c66005ca8adc124a4b57d7d4a Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 17 Feb 2025 09:21:29 +0100 Subject: [PATCH] WIP fusion accompanyingperiodwork: controller, form, templates --- ...ompanyingPeriodWorkDuplicateController.php | 77 +++++++++++++++++++ .../Form/FindAccompanyingPeriodWorkType.php | 29 +++++++ .../PickAccompanyingPeriodWorkDynamicType.php | 49 ++++++++++++ .../AccompanyingPeriodWorkRenderBox.vue | 22 ++++++ .../assign_acpw_duplicate.html.twig | 38 +++++++++ 5 files changed, 215 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php create mode 100644 src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php create mode 100644 src/Bundle/ChillPersonBundle/Form/Type/PickAccompanyingPeriodWorkDynamicType.php create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/AccompanyingPeriodWorkRenderBox.vue create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php new file mode 100644 index 000000000..321b1812a --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php @@ -0,0 +1,77 @@ +accompanyingPeriodWorkRepository->find($id); + + if (null === $acpw1) { + throw $this->createNotFoundException("Accompanying period work with id {$id} not".' found on this server'); + } + + $this->denyAccessUnlessGranted( + 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE', + $acpw1, + 'You are not allowed to merge this accompanying period work' + ); + + $form = $this->createForm(FindAccompanyingPeriodWorkType::class); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $acpw2 = $form->get('person')->getData(); + + // Validation: Ensure person1 is not the same as person2 + if ($acpw1->getId() === $acpw2->getId()) { + $this->addFlash('error', $this->translator->trans('The entities you are trying to merge cannot be the same')); + + return $this->redirectToRoute('chill_person_accompanying_period_work_show', ['id' => $acpw1->getId()]); + } + + $direction = $form->get('direction')->getData(); + + if ('starting' === $direction) { + $params = [ + 'acpw1_id' => $acpw1->getId(), + 'acpw2_id' => $acpw2->getId(), + ]; + } else { + $params = [ + 'acpw1_id' => $acpw2->getId(), + 'acpw2_id' => $acpw1->getId(), + ]; + } + +// return $this->redirectToRoute('chill_person_acpw_duplicate_confirm', $params); + } + + return $this->render('@ChillPerson/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig', [ + 'accompanyingCourse' => $acpw1->getAccompanyingPeriod(), + 'acpw' => $acpw1, + 'form' => $form->createView(), + ]); + } +} diff --git a/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php b/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php new file mode 100644 index 000000000..69ade244b --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php @@ -0,0 +1,29 @@ +add('acpw', PickAccompanyingPeriodWorkDynamicType::class) + ->add('direction', HiddenType::class, [ + 'data' => 'starting', + ]); + } +} diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickAccompanyingPeriodWorkDynamicType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickAccompanyingPeriodWorkDynamicType.php new file mode 100644 index 000000000..8936b41c6 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickAccompanyingPeriodWorkDynamicType.php @@ -0,0 +1,49 @@ +addViewTransformer(new EntityToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'], 'accompanyingPeriodWork')); + } + + public function buildView(FormView $view, FormInterface $form, array $options) + { + $view->vars['types'] = ['accompanyingPeriodWork']; + $view->vars['uniqid'] = uniqid('pick_acpw_dyn'); + $view->vars['as_id'] = true === $options['as_id'] ? '1' : '0'; + $view->vars['submit_on_adding_new_entity'] = true === $options['submit_on_adding_new_entity'] ? '1' : '0'; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setDefault('multiple', false) + ->setAllowedTypes('multiple', ['bool']) + ->setDefault('compound', false) + ->setDefault('suggested', []) + ->setDefault('as_id', false) + ->setAllowedTypes('as_id', ['bool']) + ->setDefault('submit_on_adding_new_entity', false) + ->setAllowedTypes('submit_on_adding_new_entity', ['bool']); + } + + public function getBlockPrefix() + { + return 'pick_entity_dynamic'; + } + +} diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/AccompanyingPeriodWorkRenderBox.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/AccompanyingPeriodWorkRenderBox.vue new file mode 100644 index 000000000..c1b13b319 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/AccompanyingPeriodWorkRenderBox.vue @@ -0,0 +1,22 @@ + + + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig new file mode 100644 index 000000000..7a3467f34 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig @@ -0,0 +1,38 @@ +{% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %} + +{% set activeRouteKey = 'chill_person_accompanying_period_work_assign_duplicate' %} + +{% block title %}{{ 'Assign an accompanying period work duplicate' }}{% endblock %} + + +{% block content %} +
+ +

{{ 'Assign an accompanying period work duplicate'|trans }}

+ + {{ form_start(form) }} + {{ form_rest(form) }} + + + + {{ form_end(form) }} + +
+{% endblock %} + +{% block js %} + {{ encore_entry_script_tags('mod_pickentity_type') }} +{% endblock %} + +{% block css %} + {{ encore_entry_link_tags('mod_pickentity_type') }} +{% endblock %}