php code fix

This commit is contained in:
nobohan 2022-04-06 15:34:11 +02:00
parent c65a73604d
commit d34462d849

View File

@ -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",