From d34462d849136b1f7c7b918c8bd3c676a963e240 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 6 Apr 2022 15:34:11 +0200 Subject: [PATCH] php code fix --- .../Controller/HouseholdController.php | 126 +++++++++--------- 1 file changed, 64 insertions(+), 62 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php index c8f14ba21..1f5f21c40 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php @@ -137,68 +137,6 @@ class HouseholdController extends AbstractController ); } - /** - * @Route( - * "/{household_id}/address/edit_valid_from", - * name="chill_person_household_address_valid_from_edit", - * methods={"GET", "HEAD", "POST"} - * ) - * @ParamConverter("household", options={"id": "household_id"}) - */ - public function addressValidFromEdit(Request $request, Household $household) - { - // TODO ACL - - $address_id = $request->query->get('address_id'); - $address = $this->getDoctrine()->getManager() - ->getRepository(Address::class) - ->find($address_id); - - $form = $this->createForm(AddressType::class, $address, []); - - $form->handleRequest($request); - - $addresses = $household->getAddressesOrdered(); - - foreach($addresses as $a) { - if ($a->getId() === $address->getId()){ - $currentValueIndex = array_search($a, $addresses); - } - } - if (count($addresses) > 1 && $currentValueIndex > 0) { - $previousAddress = $addresses[$currentValueIndex - 1]; - $minValidFrom = $previousAddress->getValidTo(); - } else { - $minValidFrom = null; - } - - if (count($addresses) > 1 && count($addresses) > $currentValueIndex + 1) { - $nextAddress = $addresses[$currentValueIndex + 1]; - $maxValidFrom = $nextAddress->getValidFrom(); - } else { - $maxValidFrom = null; - } - - if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->persist($address); - $this->getDoctrine()->getManager()->flush(); - return $this->redirectToRoute('chill_person_household_addresses', [ - 'household_id' => $household->getId() - ]); - } - - return $this->render( - '@ChillPerson/Household/address_valid_from_edit.html.twig', - [ - 'household' => $household, - 'address' => $address, - 'form' => $form->createView(), - 'minValidFrom' => $minValidFrom, - 'maxValidFrom' => $maxValidFrom - ] - ); - } - /** * @Route( * "/{household_id}/addresses", @@ -249,6 +187,70 @@ class HouseholdController extends AbstractController ); } + /** + * @Route( + * "/{household_id}/address/edit_valid_from", + * name="chill_person_household_address_valid_from_edit", + * methods={"GET", "HEAD", "POST"} + * ) + * @ParamConverter("household", options={"id": "household_id"}) + */ + public function addressValidFromEdit(Request $request, Household $household) + { + // TODO ACL + + $address_id = $request->query->get('address_id'); + $address = $this->getDoctrine()->getManager() + ->getRepository(Address::class) + ->find($address_id); + + $form = $this->createForm(AddressType::class, $address, []); + + $form->handleRequest($request); + + $addresses = $household->getAddressesOrdered(); + + foreach ($addresses as $a) { + if ($a->getId() === $address->getId()) { + $currentValueIndex = array_search($a, $addresses, true); + } + } + + if (count($addresses) > 1 && 0 < $currentValueIndex) { + $previousAddress = $addresses[$currentValueIndex - 1]; + $minValidFrom = $previousAddress->getValidTo(); + } else { + $minValidFrom = null; + } + + if (count($addresses) > 1 && count($addresses) > $currentValueIndex + 1) { + $nextAddress = $addresses[$currentValueIndex + 1]; + $maxValidFrom = $nextAddress->getValidFrom(); + } else { + $maxValidFrom = null; + } + + if ($form->isSubmitted() && $form->isValid()) { + $this->getDoctrine()->getManager()->persist($address); + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('chill_person_household_addresses', [ + 'household_id' => $household->getId(), + ]); + } + + return $this->render( + '@ChillPerson/Household/address_valid_from_edit.html.twig', + [ + 'household' => $household, + 'address' => $address, + 'form' => $form->createView(), + 'minValidFrom' => $minValidFrom, + 'maxValidFrom' => $maxValidFrom, + ] + ); + } + /** * @Route( * "/{household_id}/members/metadata/edit",