mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
php code fix
This commit is contained in:
parent
c65a73604d
commit
d34462d849
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user