mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
cs: Use Collection
more.
This commit is contained in:
parent
c8c5af8d14
commit
acf7142bad
@ -11,8 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Config;
|
||||
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Give help to interact with the config for alt names.
|
||||
*/
|
||||
@ -69,6 +67,6 @@ class ConfigPersonAltNamesHelper
|
||||
*/
|
||||
public function hasAltNames(): bool
|
||||
{
|
||||
return count($this->config) > 0;
|
||||
return [] !== $this->config;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
@ -22,9 +23,6 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
use function array_filter;
|
||||
use function array_values;
|
||||
|
||||
class PersonApiController extends ApiController
|
||||
{
|
||||
private AuthorizationHelper $authorizationHelper;
|
||||
@ -57,7 +55,9 @@ class PersonApiController extends ApiController
|
||||
$configAltNamesChoices,
|
||||
array_keys($configAltNamesChoices)
|
||||
),
|
||||
Response::HTTP_OK, [], ['groups' => ['read']]
|
||||
Response::HTTP_OK,
|
||||
[],
|
||||
['groups' => ['read']]
|
||||
);
|
||||
}
|
||||
|
||||
@ -79,23 +79,32 @@ class PersonApiController extends ApiController
|
||||
{
|
||||
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person);
|
||||
|
||||
$addresses = [];
|
||||
// collect addresses from location in courses
|
||||
foreach ($person->getAccompanyingPeriodParticipations() as $participation) {
|
||||
if (null !== $participation->getAccompanyingPeriod()->getAddressLocation()) {
|
||||
$a = $participation->getAccompanyingPeriod()->getAddressLocation();
|
||||
$addresses[$a->getId()] = $a;
|
||||
$addresses = $person
|
||||
->getAccompanyingPeriodParticipations()
|
||||
->filter(
|
||||
static function (AccompanyingPeriodParticipation $accompanyingPeriodParticipation): bool {
|
||||
return null !== $accompanyingPeriodParticipation->getAccompanyingPeriod()->getAddressLocation();
|
||||
}
|
||||
)
|
||||
->map(
|
||||
static function (AccompanyingPeriodParticipation $accompanyingPeriodParticipation): ?Address {
|
||||
return $accompanyingPeriodParticipation->getAccompanyingPeriod()->getAddressLocation();
|
||||
}
|
||||
);
|
||||
|
||||
// remove the actual address
|
||||
$actual = $person->getCurrentHouseholdAddress();
|
||||
|
||||
if (null !== $actual) {
|
||||
$addresses = array_filter($addresses, static fn ($a) => $a !== $actual);
|
||||
$addresses = $addresses->filter(static fn (?Address $address): bool => $address !== $actual);
|
||||
}
|
||||
|
||||
return $this->json(array_values($addresses), Response::HTTP_OK, [], ['groups' => ['read']]);
|
||||
return $this->json(
|
||||
$addresses->getValues(),
|
||||
Response::HTTP_OK,
|
||||
[],
|
||||
['groups' => ['read']]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -212,7 +212,10 @@ class PersonJsonNormalizer implements
|
||||
return $altNames
|
||||
->map(
|
||||
static function (PersonAltName $personAltName): array {
|
||||
return ['key' => $personAltName->getKey(), 'label' => $personAltName->getLabel()];
|
||||
return [
|
||||
'key' => $personAltName->getKey(),
|
||||
'label' => $personAltName->getLabel(),
|
||||
];
|
||||
}
|
||||
)
|
||||
->toArray();
|
||||
|
Loading…
x
Reference in New Issue
Block a user