From fc3eda7b761063d2cd768f0bc994b8bd45cd9ffa Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 12 Dec 2024 15:40:41 +0100 Subject: [PATCH 1/7] Initial setup of controller and templates --- .../Controller/CalendarController.php | 29 +++++++++++++++++++ .../Resources/views/Calendar/_list.html.twig | 4 +++ ...ncelCalendarByAccompanyingCourse.html.twig | 5 ++++ .../Calendar/cancelCalendarByPerson.html.twig | 5 ++++ .../translations/messages.fr.yml | 3 +- 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig create mode 100644 src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 94db03b1f..4793dbe1b 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -111,6 +111,35 @@ class CalendarController extends AbstractController ]); } + #[Route(path: '/{_locale}/calendar/calendar/{id}/cancel', name: 'chill_calendar_calendar_cancel')] + + public function cancelAction(Calendar $calendar, Request $request): Response + { + $this->denyAccessUnlessGranted(CalendarVoter::EDIT, $calendar); + + [$person, $accompanyingPeriod] = [$calendar->getPerson(), $calendar->getAccompanyingPeriod()]; + + if ($accompanyingPeriod instanceof AccompanyingPeriod) { + $view = '@ChillCalendar/Calendar/cancelCalendarByAccompanyingCourse.html.twig'; +// $redirectRoute = $this->generateUrl('chill_calendar_calendar_list_by_period', ['id' => $accompanyingPeriod->getId()]); + } elseif ($person instanceof Person) { + $view = '@ChillCalendar/Calendar/cancelCalendarByPerson.html.twig'; +// $redirectRoute = $this->generateUrl('chill_calendar_calendar_list_by_person', ['id' => $person->getId()]); + } else { + throw new \RuntimeException('nor person or accompanying period'); + } + + // Cancellation form + + + return $this->render($view, [ + 'calendar' => $calendar, +// 'delete_form' => $form->createView(), + 'accompanyingCourse' => $accompanyingPeriod, + 'person' => $person, + ]); + } + /** * Edit a calendar item. */ diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig index cff5c00cc..6b11256f8 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig @@ -219,6 +219,10 @@ class="btn btn-update "> {% endif %} +
  • + {{ 'cancel'|trans }} +
  • {% if is_granted('CHILL_CALENDAR_CALENDAR_DELETE', calendar) %}
  • Date: Mon, 16 Dec 2024 19:08:42 +0100 Subject: [PATCH 2/7] Add cancel reason form --- .../Controller/CalendarController.php | 22 +++++++++-- .../ChillCalendarBundle/Form/CancelType.php | 37 +++++++++++++++++++ ...ncelCalendarByAccompanyingCourse.html.twig | 17 +++++++++ .../Calendar/cancelCalendarByPerson.html.twig | 17 +++++++++ 4 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 src/Bundle/ChillCalendarBundle/Form/CancelType.php diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 4793dbe1b..d036b6b1e 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -13,6 +13,7 @@ namespace Chill\CalendarBundle\Controller; use Chill\CalendarBundle\Entity\Calendar; use Chill\CalendarBundle\Form\CalendarType; +use Chill\CalendarBundle\Form\CancelType; use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface; use Chill\CalendarBundle\Repository\CalendarACLAwareRepositoryInterface; use Chill\CalendarBundle\Security\Voter\CalendarVoter; @@ -30,11 +31,13 @@ use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\ThirdPartyBundle\Entity\ThirdParty; +use Doctrine\ORM\EntityManagerInterface; use http\Exception\UnexpectedValueException; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Form; +use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -60,6 +63,7 @@ class CalendarController extends AbstractController private readonly UserRepositoryInterface $userRepository, private readonly TranslatorInterface $translator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, + private readonly EntityManagerInterface $em, ) {} /** @@ -119,22 +123,32 @@ class CalendarController extends AbstractController [$person, $accompanyingPeriod] = [$calendar->getPerson(), $calendar->getAccompanyingPeriod()]; + $form = $this->createForm(CancelType::class, $calendar); + if ($accompanyingPeriod instanceof AccompanyingPeriod) { $view = '@ChillCalendar/Calendar/cancelCalendarByAccompanyingCourse.html.twig'; -// $redirectRoute = $this->generateUrl('chill_calendar_calendar_list_by_period', ['id' => $accompanyingPeriod->getId()]); + $redirectRoute = $this->generateUrl('chill_calendar_calendar_list_by_period', ['id' => $accompanyingPeriod->getId()]); } elseif ($person instanceof Person) { $view = '@ChillCalendar/Calendar/cancelCalendarByPerson.html.twig'; -// $redirectRoute = $this->generateUrl('chill_calendar_calendar_list_by_person', ['id' => $person->getId()]); + $redirectRoute = $this->generateUrl('chill_calendar_calendar_list_by_person', ['id' => $person->getId()]); } else { throw new \RuntimeException('nor person or accompanying period'); } - // Cancellation form + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $this->em->persist($calendar); + $this->em->flush(); + + $this->addFlash('success', $this->translator->trans('calender.calendar item has been canceled!')); + + return new RedirectResponse($redirectRoute); + } return $this->render($view, [ 'calendar' => $calendar, -// 'delete_form' => $form->createView(), + 'form' => $form->createView(), 'accompanyingCourse' => $accompanyingPeriod, 'person' => $person, ]); diff --git a/src/Bundle/ChillCalendarBundle/Form/CancelType.php b/src/Bundle/ChillCalendarBundle/Form/CancelType.php new file mode 100644 index 000000000..c4f790c7d --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Form/CancelType.php @@ -0,0 +1,37 @@ +add('cancelReason', EntityType::class, array( + 'class' => CancelReason::class, + 'required' => false, + 'choice_label' => function (CancelReason $cancelReason) { + return $this->translatableStringHelper->localize($cancelReason->getName()); + }, + )); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => Calendar::class, + + ]); + } +} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig index 19659c627..10841bf9f 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig @@ -3,3 +3,20 @@ {% set activeRouteKey = 'chill_calendar_calendar_list' %} {% block title 'chill_calendar.cancel_calendar_item'|trans %} + +{% block content %} + + {{ form(form) }} + + + +{% endblock %} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig index b3db97e0f..867a5b548 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig @@ -3,3 +3,20 @@ {% set activeRouteKey = 'chill_calendar_calendar_list' %} {% block title 'chill_calendar.cancel_calendar_item'|trans %} + +{% block content %} + + {{ form_row(form.cancelReason) }} + + + +{% endblock %} From d0d3be9bc1dd862834339b4993e7beb49b4b1311 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 17 Dec 2024 09:35:52 +0100 Subject: [PATCH 3/7] Fix form to submit cancel reason --- .../Controller/CalendarController.php | 1 + .../views/Calendar/cancelCalendarByPerson.html.twig | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index d036b6b1e..65037c005 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -124,6 +124,7 @@ class CalendarController extends AbstractController [$person, $accompanyingPeriod] = [$calendar->getPerson(), $calendar->getAccompanyingPeriod()]; $form = $this->createForm(CancelType::class, $calendar); + $form->add('submit', SubmitType::class); if ($accompanyingPeriod instanceof AccompanyingPeriod) { $view = '@ChillCalendar/Calendar/cancelCalendarByAccompanyingCourse.html.twig'; diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig index 867a5b548..d6f71cc13 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig @@ -6,17 +6,24 @@ {% block content %} + {{ form_start(form) }} + {{ form_row(form.cancelReason) }} + {{ form_end(form) }} + {% endblock %} From cce79de7117aa1204840facfc44c9714e0f0a1ac Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 17 Dec 2024 16:04:05 +0100 Subject: [PATCH 4/7] Add translation, make reason required, and change template for form --- .../Controller/CalendarController.php | 10 ++++++++-- src/Bundle/ChillCalendarBundle/Form/CancelType.php | 6 +++--- .../cancelCalendarByAccompanyingCourse.html.twig | 13 ++++++++++--- .../translations/messages.fr.yml | 1 + 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 65037c005..293cbeae6 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -119,6 +119,11 @@ class CalendarController extends AbstractController public function cancelAction(Calendar $calendar, Request $request): Response { + // Add voter + // Deal with sms being sent or not + // Communicate cancellation with the remote calendar. + + $this->denyAccessUnlessGranted(CalendarVoter::EDIT, $calendar); [$person, $accompanyingPeriod] = [$calendar->getPerson(), $calendar->getAccompanyingPeriod()]; @@ -139,10 +144,11 @@ class CalendarController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->em->persist($calendar); + + $calendar->setStatus($calendar::STATUS_CANCELED); $this->em->flush(); - $this->addFlash('success', $this->translator->trans('calender.calendar item has been canceled!')); + $this->addFlash('success', $this->translator->trans('chill_calendar.calendar_canceled')); return new RedirectResponse($redirectRoute); } diff --git a/src/Bundle/ChillCalendarBundle/Form/CancelType.php b/src/Bundle/ChillCalendarBundle/Form/CancelType.php index c4f790c7d..dc7c4d049 100644 --- a/src/Bundle/ChillCalendarBundle/Form/CancelType.php +++ b/src/Bundle/ChillCalendarBundle/Form/CancelType.php @@ -18,13 +18,13 @@ class CancelType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('cancelReason', EntityType::class, array( + $builder->add('cancelReason', EntityType::class, [ 'class' => CancelReason::class, - 'required' => false, + 'required' => true, 'choice_label' => function (CancelReason $cancelReason) { return $this->translatableStringHelper->localize($cancelReason->getName()); }, - )); + ]); } public function configureOptions(OptionsResolver $resolver) diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig index 10841bf9f..cc378d3cb 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig @@ -6,17 +6,24 @@ {% block content %} - {{ form(form) }} + {{ form_start(form) }} + + {{ form_row(form.cancelReason) }} + {{ form_end(form) }} + {% endblock %} diff --git a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml index e35a46d97..527fabb12 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -45,6 +45,7 @@ crud: chill_calendar: cancel_calendar_item: Annuler rendez-vous + calendar_canceled: Le rendez-vous a été annulé Document: Document d'un rendez-vous form: The main user is mandatory. He will organize the appointment.: L'utilisateur principal est obligatoire. Il est l'organisateur de l'événement. From e76e815c49cebd70d04d35a1b08d1c85b4da1f11 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 18 Dec 2024 13:20:17 +0100 Subject: [PATCH 5/7] Only show cancel button with EDIT permission --- .../Resources/views/Calendar/_list.html.twig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig index 6b11256f8..b77859e83 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig @@ -213,16 +213,18 @@ class="btn btn-show ">
  • {% endif %} + {% if is_granted('CHILL_CALENDAR_CALENDAR_EDIT', calendar) %}
  • - {% endif %}
  • {{ 'cancel'|trans }}
  • + {% endif %} + {% if is_granted('CHILL_CALENDAR_CALENDAR_DELETE', calendar) %}
  • Date: Wed, 18 Dec 2024 13:36:20 +0100 Subject: [PATCH 6/7] Use a different button type --- .../Resources/views/Calendar/_list.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig index b77859e83..46da9a911 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/_list.html.twig @@ -221,7 +221,7 @@
  • {{ 'cancel'|trans }} + class="btn btn-remove">{{ 'cancel'|trans }}
  • {% endif %} From 5c85f0478b7df0c4c1b4b05a6673fe0f94b3cc6a Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 18 Dec 2024 13:48:56 +0100 Subject: [PATCH 7/7] Set the sms status to 'canceled' --- .../ChillCalendarBundle/Controller/CalendarController.php | 3 +-- ...t_message_canceled.twig => short_message_canceled.txt.twig} | 0 2 files changed, 1 insertion(+), 2 deletions(-) rename src/Bundle/ChillCalendarBundle/Resources/views/CalendarShortMessage/{short_message_canceled.twig => short_message_canceled.txt.twig} (100%) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 293cbeae6..3cd2926e5 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -119,11 +119,9 @@ class CalendarController extends AbstractController public function cancelAction(Calendar $calendar, Request $request): Response { - // Add voter // Deal with sms being sent or not // Communicate cancellation with the remote calendar. - $this->denyAccessUnlessGranted(CalendarVoter::EDIT, $calendar); [$person, $accompanyingPeriod] = [$calendar->getPerson(), $calendar->getAccompanyingPeriod()]; @@ -146,6 +144,7 @@ class CalendarController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $calendar->setStatus($calendar::STATUS_CANCELED); + $calendar->setSmsStatus($calendar::SMS_CANCEL_PENDING); $this->em->flush(); $this->addFlash('success', $this->translator->trans('chill_calendar.calendar_canceled')); diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/CalendarShortMessage/short_message_canceled.twig b/src/Bundle/ChillCalendarBundle/Resources/views/CalendarShortMessage/short_message_canceled.txt.twig similarity index 100% rename from src/Bundle/ChillCalendarBundle/Resources/views/CalendarShortMessage/short_message_canceled.twig rename to src/Bundle/ChillCalendarBundle/Resources/views/CalendarShortMessage/short_message_canceled.txt.twig