From b561b12213fdea66ac8c9247ca823f3e6871ddbf Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 16 Dec 2024 19:08:42 +0100 Subject: [PATCH] Add cancel reason form --- .../Controller/CalendarController.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 61b9c860b..a742a4e98 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -37,6 +37,7 @@ 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; @@ -166,22 +167,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, ]);