mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
216 lines
6.2 KiB
PHP
216 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace Chill\PersonBundle\Controller;
|
|
|
|
use Chill\MainBundle\Entity\Address;
|
|
use Chill\PersonBundle\Form\HouseholdType;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Translation\TranslatorInterface;
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|
use Chill\PersonBundle\Entity\Household\Household;
|
|
use Chill\PersonBundle\Entity\Household\Position;
|
|
|
|
/**
|
|
* @Route("/{_locale}/person/household")
|
|
*/
|
|
class HouseholdController extends AbstractController
|
|
{
|
|
private TranslatorInterface $translator;
|
|
|
|
/**
|
|
* @param TranslatorInterface $translator
|
|
*/
|
|
public function __construct(TranslatorInterface $translator)
|
|
{
|
|
$this->translator = $translator;
|
|
}
|
|
|
|
/**
|
|
* @Route(
|
|
* "/{household_id}/summary",
|
|
* name="chill_person_household_summary",
|
|
* methods={"GET", "HEAD"}
|
|
* )
|
|
* @ParamConverter("household", options={"id" = "household_id"})
|
|
*/
|
|
public function summary(Request $request, Household $household)
|
|
{
|
|
// TODO ACL
|
|
|
|
$positions = $this->getDoctrine()->getManager()
|
|
->getRepository(Position::class)
|
|
->findAll()
|
|
;
|
|
|
|
// little performance improvement:
|
|
// initialize members collection, which will avoid
|
|
// some queries
|
|
$household->getMembers()->initialize();
|
|
return $this->render('@ChillPerson/Household/summary.html.twig',
|
|
[
|
|
'household' => $household,
|
|
'positions' => $positions
|
|
]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @Route(
|
|
* "/{household_id}/members",
|
|
* name="chill_person_household_members",
|
|
* methods={"GET", "HEAD"}
|
|
* )
|
|
* @ParamConverter("household", options={"id" = "household_id"})
|
|
*/
|
|
public function members(Request $request, Household $household)
|
|
{
|
|
// TODO ACL
|
|
$positions = $this->getDoctrine()->getManager()
|
|
->getRepository(Position::class)
|
|
->findAll()
|
|
;
|
|
|
|
// little performance improvement:
|
|
// initialize members collection, which will avoid
|
|
// some queries
|
|
$household->getMembers()->initialize();
|
|
|
|
if ($request->query->has('edit')) {
|
|
$form = $this->createMetadataForm($household);
|
|
} else {
|
|
$form = null;
|
|
}
|
|
|
|
return $this->render('@ChillPerson/Household/members.html.twig',
|
|
[
|
|
'household' => $household,
|
|
'positions' => $positions,
|
|
'form' => NULL !== $form ? $form->createView(): $form
|
|
]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @Route(
|
|
* "/{household_id}/addresses",
|
|
* name="chill_person_household_addresses",
|
|
* methods={"GET", "HEAD"}
|
|
* )
|
|
* @ParamConverter("household", options={"id" = "household_id"})
|
|
*/
|
|
public function addresses(Request $request, Household $household)
|
|
{
|
|
// TODO ACL
|
|
|
|
//TODO put these lines into a validator constraint on household->getAddress
|
|
$addresses = $household->getAddresses();
|
|
$cond = True;
|
|
for ($i=0; $i < count($addresses) - 1; $i++) {
|
|
if ($addresses[$i]->getValidFrom() != $addresses[$i + 1]->getValidTo()) {
|
|
$cond = False;
|
|
}
|
|
}
|
|
|
|
return $this->render('@ChillPerson/Household/addresses.html.twig',
|
|
[
|
|
'household' => $household
|
|
]
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
* @Route(
|
|
* "/{household_id}/address/move",
|
|
* name="chill_person_household_address_move",
|
|
* methods={"GET", "HEAD", "POST"}
|
|
* )
|
|
* @ParamConverter("household", options={"id" = "household_id"})
|
|
*/
|
|
public function addressMove(Request $request, Household $household)
|
|
{
|
|
// TODO ACL
|
|
|
|
return $this->render('@ChillPerson/Household/address_move.html.twig',
|
|
[
|
|
'household' => $household
|
|
]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @Route(
|
|
* "/{household_id}/address/edit",
|
|
* name="chill_person_household_address_edit",
|
|
* methods={"GET", "HEAD", "POST"}
|
|
* )
|
|
* @ParamConverter("household", options={"id" = "household_id"})
|
|
*/
|
|
public function addressEdit(Request $request, Household $household)
|
|
{
|
|
// TODO ACL
|
|
//$address = $this->findAddressById($household, $address_id); //TODO
|
|
|
|
|
|
return $this->render('@ChillPerson/Household/address_edit.html.twig',
|
|
[
|
|
'household' => $household,
|
|
//'address' => $address,
|
|
]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @Route(
|
|
* "/{household_id}/members/metadata/edit",
|
|
* name="chill_person_household_members_metadata_edit",
|
|
* methods={"GET", "POST"}
|
|
* )
|
|
* @ParamConverter("household", options={"id" = "household_id"})
|
|
*/
|
|
public function editHouseholdMetadata(Request $request, Household $household)
|
|
{
|
|
// TODO ACL
|
|
$form = $this->createMetadataForm($household);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isSubmitted() and $form->isValid()) {
|
|
$this->getDoctrine()->getManager()->flush();
|
|
|
|
$this->addFlash('success', $this->translator->trans('household.data_saved'));
|
|
|
|
return $this->redirectToRoute('chill_person_household_members', [
|
|
'household_id' => $household->getId()
|
|
]);
|
|
}
|
|
|
|
return $this->render('@ChillPerson/Household/edit_member_metadata.html.twig', [
|
|
'household' => $household,
|
|
'form' => $form->createView()
|
|
]);
|
|
}
|
|
|
|
private function createMetadataForm(Household $household): FormInterface
|
|
{
|
|
$form = $this->createForm(
|
|
HouseholdType::class,
|
|
$household,
|
|
[
|
|
'action' => $this->generateUrl(
|
|
'chill_person_household_members_metadata_edit',
|
|
[
|
|
'household_id' => $household->getId()
|
|
]
|
|
)
|
|
]
|
|
);
|
|
|
|
return $form;
|
|
}
|
|
}
|