diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index 9abd85f64..ae7c00ce1 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -275,4 +275,60 @@ class AccompanyingCourseController extends Controller 'accompanying_period_id' => $period->getId(), ]); } + + /** + * @Route("/{_locale}/parcours/{accompanying_period_id}/open", name="chill_person_accompanying_course_reopen") + * @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"}) + */ + public function reOpenAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response + { + //$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $accompanyingCourse); + + // $form = $this->createForm(AccompanyingCourseType::class, $accompanyingCourse, [ + // 'validation_groups' => [AccompanyingPeriod::STEP_CLOSED], + // ]); + + $form = $this->createFormBuilder([])->getForm(); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + + $accompanyingCourse->reOpen(); + $em->flush(); + + return $this->redirectToRoute('chill_person_accompanying_course_index', [ + 'accompanying_period_id' => $accompanyingCourse->getId(), + ]); + + //TODO: delete motif de cloture and date de cloture (NULL) + //TODO: which redirection? + //TODO workflow stuff? + //TODO: error handling + // $workflow = $this->registry->get($accompanyingCourse); + + // if ($workflow->can($accompanyingCourse, 'close')) { + // $workflow->apply($accompanyingCourse, 'close'); + + // $em->flush(); + + // return $this->redirectToRoute('chill_person_accompanying_course_index', [ + // 'accompanying_period_id' => $accompanyingCourse->getId(), + // ]); + // } + // /** @var ConstraintViolationListInterface $errors */ + // $errors = $this->validator->validate($accompanyingCourse, null, [$accompanyingCourse::STEP_CLOSED]); + // $this->addFlash('error', $this->translator->trans('It is not possible to close this course')); + + // foreach ($errors as $e) { + // /** @var ConstraintViolationInterface $e */ + // $this->addFlash('error', $e->getMessage()); + // } + } + + return $this->render('@ChillPerson/AccompanyingCourse/reopen.html.twig', [ + 'form' => $form->createView(), + 'accompanyingCourse' => $accompanyingCourse, + ]); + } } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index dedef0a17..8f0ac7d17 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -996,6 +996,7 @@ class AccompanyingPeriod implements { $this->setClosingDate(null); $this->setClosingMotive(null); + $this->setStep(AccompanyingPeriod::STEP_CONFIRMED); } /** diff --git a/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php b/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php index 60455b201..3b8cca55b 100644 --- a/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php +++ b/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php @@ -82,6 +82,15 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface $workflow = $this->registry->get($period, 'accompanying_period_lifecycle'); + if (null !== $period->getClosingDate()) { + $menu->addChild($this->translator->trans('Re-open Accompanying Course'), [ + 'route' => 'chill_person_accompanying_course_reopen', + 'routeParameters' => [ + 'accompanying_period_id' => $period->getId(), + ], ]) + ->setExtras(['order' => 99998]); + } + if ($workflow->can($period, 'close')) { $menu->addChild($this->translator->trans('Close Accompanying Course'), [ 'route' => 'chill_person_accompanying_course_close', diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/close.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/close.html.twig index f0c819b35..64c2dd86b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/close.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/close.html.twig @@ -1,5 +1,7 @@ {% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %} +{% block title %}{{ 'Close accompanying course'|trans }}{% endblock %} + {% block content %}