mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,36 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Form\HouseholdType;
|
||||
use Chill\PersonBundle\Repository\Household\PositionRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
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\Security\Core\Security;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
use Chill\PersonBundle\Repository\Household\PositionRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/person/household")
|
||||
*/
|
||||
class HouseholdController extends AbstractController
|
||||
{
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
private PositionRepository $positionRepository;
|
||||
|
||||
private Security $security;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
private Security $security;
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
TranslatorInterface $translator,
|
||||
@@ -46,51 +51,14 @@ class HouseholdController extends AbstractController
|
||||
|
||||
/**
|
||||
* @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->positionRepository
|
||||
->findByActiveOrdered()
|
||||
;
|
||||
|
||||
// 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/summary.html.twig',
|
||||
[
|
||||
'household' => $household,
|
||||
'positions' => $positions,
|
||||
'form' => NULL !== $form ? $form->createView() : null,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/{household_id}/accompanying-period",
|
||||
* name="chill_person_household_accompanying_period",
|
||||
* methods={"GET", "HEAD"}
|
||||
* )
|
||||
* @ParamConverter("household", options={"id" = "household_id"})
|
||||
* "/{household_id}/accompanying-period",
|
||||
* name="chill_person_household_accompanying_period",
|
||||
* methods={"GET", "HEAD"}
|
||||
* )
|
||||
* @ParamConverter("household", options={"id": "household_id"})
|
||||
*/
|
||||
public function accompanyingPeriod(Request $request, Household $household)
|
||||
{
|
||||
|
||||
$currentMembers = $household->getCurrentPersons();
|
||||
$accompanyingPeriods = [];
|
||||
|
||||
@@ -100,9 +68,8 @@ class HouseholdController extends AbstractController
|
||||
foreach ($accompanyingPeriodsMember as $accompanyingPeriod) {
|
||||
if (!$this->security->isGranted(AccompanyingPeriodVoter::SEE, $accompanyingPeriod)) {
|
||||
continue;
|
||||
} else {
|
||||
$accompanyingPeriods[$accompanyingPeriod->getId()] = $accompanyingPeriod;
|
||||
}
|
||||
$accompanyingPeriods[$accompanyingPeriod->getId()] = $accompanyingPeriod;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,93 +82,44 @@ class HouseholdController extends AbstractController
|
||||
foreach ($accompanyingPeriodsOldMember as $accompanyingPeriod) {
|
||||
if (!$this->security->isGranted(AccompanyingPeriodVoter::SEE, $accompanyingPeriod)) {
|
||||
continue;
|
||||
} else {
|
||||
$id = $accompanyingPeriod->getId();
|
||||
}
|
||||
$id = $accompanyingPeriod->getId();
|
||||
|
||||
if (!array_key_exists($id, $accompanyingPeriodsOld) && !array_key_exists($id, $accompanyingPeriods)) {
|
||||
$accompanyingPeriodsOld[$id] = $accompanyingPeriod;
|
||||
}
|
||||
if (!array_key_exists($id, $accompanyingPeriodsOld) && !array_key_exists($id, $accompanyingPeriods)) {
|
||||
$accompanyingPeriodsOld[$id] = $accompanyingPeriod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/Household/accompanying_period.html.twig',
|
||||
return $this->render(
|
||||
'@ChillPerson/Household/accompanying_period.html.twig',
|
||||
[
|
||||
'household' => $household,
|
||||
'accompanying_periods' => $accompanyingPeriods,
|
||||
'accompanying_periods_old' => $accompanyingPeriodsOld
|
||||
'accompanying_periods_old' => $accompanyingPeriodsOld,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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"})
|
||||
* "/{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_id = $request->query->get('address_id');
|
||||
$address = $this->getDoctrine()->getManager()
|
||||
->getRepository(Address::class)
|
||||
->find($address_id)
|
||||
;
|
||||
->find($address_id);
|
||||
|
||||
return $this->render('@ChillPerson/Household/address_edit.html.twig',
|
||||
return $this->render(
|
||||
'@ChillPerson/Household/address_edit.html.twig',
|
||||
[
|
||||
'household' => $household,
|
||||
'address' => $address,
|
||||
@@ -211,32 +129,61 @@ class HouseholdController extends AbstractController
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/{household_id}/relationship",
|
||||
* name="chill_person_household_relationship",
|
||||
* methods={"GET", "HEAD"}
|
||||
* )
|
||||
* @ParamConverter("household", options={"id" = "household_id"})
|
||||
* "/{household_id}/addresses",
|
||||
* name="chill_person_household_addresses",
|
||||
* methods={"GET", "HEAD"}
|
||||
* )
|
||||
* @ParamConverter("household", options={"id": "household_id"})
|
||||
*/
|
||||
public function showRelationship(Request $request, Household $household)
|
||||
public function addresses(Request $request, Household $household)
|
||||
{
|
||||
$jsonString = $this->serializer->serialize($household->getCurrentPersons(),
|
||||
'json', [ AbstractNormalizer::GROUPS => ['read']]);
|
||||
// TODO ACL
|
||||
|
||||
return $this->render('@ChillPerson/Household/relationship.html.twig',
|
||||
//TODO put these lines into a validator constraint on household->getAddress
|
||||
$addresses = $household->getAddresses();
|
||||
$cond = true;
|
||||
|
||||
for ($i = 0; count($addresses) - 1 > $i; ++$i) {
|
||||
if ($addresses[$i]->getValidFrom() != $addresses[$i + 1]->getValidTo()) {
|
||||
$cond = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'@ChillPerson/Household/addresses.html.twig',
|
||||
[
|
||||
'household' => $household,
|
||||
'persons' => $jsonString
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/{household_id}/members/metadata/edit",
|
||||
* name="chill_person_household_members_metadata_edit",
|
||||
* methods={"GET", "POST"}
|
||||
* )
|
||||
* @ParamConverter("household", options={"id" = "household_id"})
|
||||
* "/{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}/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)
|
||||
{
|
||||
@@ -251,32 +198,90 @@ class HouseholdController extends AbstractController
|
||||
$this->addFlash('success', $this->translator->trans('household.data_saved'));
|
||||
|
||||
return $this->redirectToRoute('chill_person_household_summary', [
|
||||
'household_id' => $household->getId()
|
||||
'household_id' => $household->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/Household/edit_member_metadata.html.twig', [
|
||||
'household' => $household,
|
||||
'form' => $form->createView()
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/{household_id}/relationship",
|
||||
* name="chill_person_household_relationship",
|
||||
* methods={"GET", "HEAD"}
|
||||
* )
|
||||
* @ParamConverter("household", options={"id": "household_id"})
|
||||
*/
|
||||
public function showRelationship(Request $request, Household $household)
|
||||
{
|
||||
$jsonString = $this->serializer->serialize(
|
||||
$household->getCurrentPersons(),
|
||||
'json',
|
||||
[AbstractNormalizer::GROUPS => ['read']]
|
||||
);
|
||||
|
||||
return $this->render(
|
||||
'@ChillPerson/Household/relationship.html.twig',
|
||||
[
|
||||
'household' => $household,
|
||||
'persons' => $jsonString,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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->positionRepository
|
||||
->findByActiveOrdered();
|
||||
|
||||
// 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/summary.html.twig',
|
||||
[
|
||||
'household' => $household,
|
||||
'positions' => $positions,
|
||||
'form' => null !== $form ? $form->createView() : null,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function createMetadataForm(Household $household): FormInterface
|
||||
{
|
||||
$form = $this->createForm(
|
||||
return $this->createForm(
|
||||
HouseholdType::class,
|
||||
$household,
|
||||
[
|
||||
'action' => $this->generateUrl(
|
||||
'chill_person_household_members_metadata_edit',
|
||||
[
|
||||
'household_id' => $household->getId()
|
||||
'household_id' => $household->getId(),
|
||||
]
|
||||
)
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user