diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index 5c11f4802..3b6698875 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -158,4 +158,29 @@ class AccompanyingCourseController extends Controller ]); } + /** + * @Route("/{_locale}/parcours/{accompanying_period_id}/close", name="chill_person_accompanying_course_close") + * @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"}) + */ + + public function closeAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response + { + $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $accompanyingCourse); + + $form = $this->createForm(AccompanyingCourseType::class, $accompanyingCourse); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + + $this->getDoctrine()->getManager()->flush(); + + } + + return $this->render('@ChillPerson/AccompanyingCourse/close.html.twig', [ + 'form' => $form->createView(), + 'accompanyingCourse' => $accompanyingCourse + ]); + } + } diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index 211765330..996215082 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -221,12 +221,17 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac 'places' => [ 'DRAFT', 'CONFIRMED', + 'CLOSED', ], 'transitions' => [ 'confirm' => [ 'from' => 'DRAFT', 'to' => 'CONFIRMED' ], + 'close' => [ + 'from' => 'CONFIRMED', + 'to' => 'CLOSED' + ], ], ], ] diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 15f33abe7..0fdbe35fd 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -94,6 +94,14 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface */ public const STEP_CONFIRMED = 'CONFIRMED'; + /** + * Mark an accompanying period as "closed". + * + * This means that the accompanying period **is** + * closed by the creator + */ + public const STEP_CLOSED = 'CLOSED'; + /** * @var integer * @@ -117,6 +125,8 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface * * @ORM\Column(type="date", nullable=true) * @Groups({"read", "write"}) + * @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CLOSED}) + * @Assert\GreaterThan(propertyPath="openingDate", groups={AccompanyingPeriod::STEP_CLOSED}) */ private $closingDate = null; @@ -166,6 +176,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface * targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive") * @ORM\JoinColumn(nullable=true) * @Groups({"read", "write"}) + * @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CLOSED}) */ private $closingMotive = null; diff --git a/src/Bundle/ChillPersonBundle/Form/AccompanyingCourseType.php b/src/Bundle/ChillPersonBundle/Form/AccompanyingCourseType.php new file mode 100644 index 000000000..a1bdd5c2e --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Form/AccompanyingCourseType.php @@ -0,0 +1,22 @@ +add('closingDate', ChillDateType::class, + [ + 'required' => true, + ]); + + $builder->add('closingMotive', ClosingMotivePickerType::class); + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/close.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/close.html.twig new file mode 100644 index 000000000..f0c819b35 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/close.html.twig @@ -0,0 +1,28 @@ +{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %} + +{% block content %} +