diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index aa3c5f512..b15f8adb9 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Controller; use Chill\ActivityBundle\Entity\Activity; use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Form\AccompanyingCourseType; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; @@ -279,6 +280,40 @@ class AccompanyingCourseController extends Controller ]); } + /** + * @Route("/{_locale}/person/household/parcours/new", name="chill_household_accompanying_course_new") + */ + public function newHouseholdParcoursAction(Request $request): Response + { + $period = new AccompanyingPeriod(); + $em = $this->getDoctrine()->getManager(); + + if ($request->query->has('household_id')) { + $householdId = $request->query->get('household_id'); + + $household = $em->getRepository(Household::class)->find($householdId); + $members = $household->getCurrentMembers(); + + if (null !== $members) { + foreach ($members as $m) { + $period->addPerson($m->getPerson()); + } + } + } + + $userLocation = $this->getUser()->getCurrentLocation(); + $period->setAdministrativeLocation($userLocation); + + $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::CREATE, $period); + + $em->persist($period); + $em->flush(); + + return $this->redirectToRoute('chill_person_accompanying_course_edit', [ + '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"}) diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/accompanying_period.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/accompanying_period.html.twig index 5a8d2acf8..9cc323274 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/accompanying_period.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/accompanying_period.html.twig @@ -46,13 +46,12 @@ {{ 'Household summary'|trans }} - {#