cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,27 +1,36 @@
<?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\CRUD\Controller\ApiController;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\AddressReference;
use Chill\MainBundle\Serializer\Model\Collection;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Repository\Household\HouseholdACLAwareRepositoryInterface;
use Chill\PersonBundle\Repository\Household\HouseholdRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use function array_filter;
use function array_values;
class HouseholdApiController extends ApiController
{
private HouseholdRepository $householdRepository;
private HouseholdACLAwareRepositoryInterface $householdACLAwareRepository;
private HouseholdRepository $householdRepository;
public function __construct(
HouseholdRepository $householdRepository,
HouseholdACLAwareRepositoryInterface $householdACLAwareRepository
@@ -30,53 +39,44 @@ class HouseholdApiController extends ApiController
$this->householdACLAwareRepository = $householdACLAwareRepository;
}
public function householdAddressApi($id, Request $request, string $_format): Response
{
return $this->addRemoveSomething('address', $id, $request, $_format, 'address', Address::class, [ 'groups' => [ 'read' ] ]);
}
/**
* Find Household of people participating to the same AccompanyingPeriod
* @Route("/api/1.0/person/household/by-address-reference/{id}.json",
* name="chill_api_person_household_by_address_reference")
*
* @ParamConverter("person", options={"id" = "person_id"})
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function suggestHouseholdByAccompanyingPeriodParticipationApi(Person $person, string $_format)
public function getHouseholdByAddressReference(AddressReference $addressReference): Response
{
// TODO add acl
// TODO ACL
$this->denyAccessUnlessGranted('ROLE_USER');
$count = $this->householdRepository->countByAccompanyingPeriodParticipation($person);
$paginator = $this->getPaginatorFactory()->create($count);
$households = [];
if ($count !== 0) {
$allHouseholds = $this->householdRepository->findByAccompanyingPeriodParticipation($person,
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
$currentHouseholdPerson = $person->getCurrentHousehold();
foreach ($allHouseholds as $h) {
if ($h !== $currentHouseholdPerson) {
array_push($households, $h);
}
}
if (null !== $currentHouseholdPerson) {
$count = $count - 1;
$paginator = $this->getPaginatorFactory()->create($count);
}
}
$total = $this->householdACLAwareRepository->countByAddressReference($addressReference);
$paginator = $this->getPaginatorFactory()->create($total);
$households = $this->householdACLAwareRepository->findByAddressReference(
$addressReference,
$paginator->getCurrentPageFirstItemNumber(),
$paginator->getItemsPerPage()
);
$collection = new Collection($households, $paginator);
return $this->json($collection, Response::HTTP_OK, [],
[ "groups" => ["read"]]);
return $this->json($collection, Response::HTTP_OK, [], [
AbstractNormalizer::GROUPS => ['read'],
]);
}
public function householdAddressApi($id, Request $request, string $_format): Response
{
return $this->addRemoveSomething('address', $id, $request, $_format, 'address', Address::class, ['groups' => ['read']]);
}
/**
* @Route("/api/1.0/person/address/suggest/by-household/{household_id}.{_format}",
* name="chill_person_address_suggest_by_household",
* requirements={
* "_format"="json"
* name="chill_person_address_suggest_by_household",
* requirements={
* "_format": "json"
* }
* )
* @ParamConverter("household", options={"id" = "household_id"})
* )
* @ParamConverter("household", options={"id": "household_id"})
*/
public function suggestAddressByHousehold(Household $household, string $_format)
{
@@ -90,9 +90,11 @@ class HouseholdApiController extends ApiController
$a = $participation->getAccompanyingPeriod()->getAddressLocation();
$addresses[$a->getId()] = $a;
}
if (null !== $personLocation = $participation
->getAccompanyingPeriod()->getPersonLocation()) {
$a = $personLocation->getCurrentHouseholdAddress();
if (null !== $a) {
$addresses[$a->getId()] = $a;
}
@@ -102,34 +104,59 @@ class HouseholdApiController extends ApiController
// remove the actual address
$actual = $household->getCurrentAddress();
if (null !== $actual) {
$addresses = \array_filter($addresses, fn($a) => $a !== $actual);
$addresses = array_filter($addresses, fn ($a) => $a !== $actual);
}
return $this->json(\array_values($addresses), Response::HTTP_OK, [],
[ 'groups' => [ 'read' ] ]);
return $this->json(
array_values($addresses),
Response::HTTP_OK,
[],
['groups' => ['read']]
);
}
/**
* Find Household of people participating to the same AccompanyingPeriod.
*
* @Route("/api/1.0/person/household/by-address-reference/{id}.json",
* name="chill_api_person_household_by_address_reference")
* @param AddressReference $addressReference
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @ParamConverter("person", options={"id": "person_id"})
*/
public function getHouseholdByAddressReference(AddressReference $addressReference): Response
public function suggestHouseholdByAccompanyingPeriodParticipationApi(Person $person, string $_format)
{
// TODO ACL
$this->denyAccessUnlessGranted('ROLE_USER');
// TODO add acl
$total = $this->householdACLAwareRepository->countByAddressReference($addressReference);
$paginator = $this->getPaginatorFactory()->create($total);
$households = $this->householdACLAwareRepository->findByAddressReference($addressReference,
$paginator->getCurrentPageFirstItemNumber(), $paginator->getItemsPerPage());
$count = $this->householdRepository->countByAccompanyingPeriodParticipation($person);
$paginator = $this->getPaginatorFactory()->create($count);
$households = [];
if (0 !== $count) {
$allHouseholds = $this->householdRepository->findByAccompanyingPeriodParticipation(
$person,
$paginator->getItemsPerPage(),
$paginator->getCurrentPageFirstItemNumber()
);
$currentHouseholdPerson = $person->getCurrentHousehold();
foreach ($allHouseholds as $h) {
if ($h !== $currentHouseholdPerson) {
array_push($households, $h);
}
}
if (null !== $currentHouseholdPerson) {
$count = $count - 1;
$paginator = $this->getPaginatorFactory()->create($count);
}
}
$collection = new Collection($households, $paginator);
return $this->json($collection, Response::HTTP_OK, [], [
AbstractNormalizer::GROUPS => ['read']
]);
return $this->json(
$collection,
Response::HTTP_OK,
[],
['groups' => ['read']]
);
}
}