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;
|
namespace Chill\PersonBundle\Config;
|
||||||
|
|
||||||
use function count;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Give help to interact with the config for alt names.
|
* Give help to interact with the config for alt names.
|
||||||
*/
|
*/
|
||||||
@ -69,6 +67,6 @@ class ConfigPersonAltNamesHelper
|
|||||||
*/
|
*/
|
||||||
public function hasAltNames(): bool
|
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\Entity\Address;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
@ -22,9 +23,6 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
use function array_filter;
|
|
||||||
use function array_values;
|
|
||||||
|
|
||||||
class PersonApiController extends ApiController
|
class PersonApiController extends ApiController
|
||||||
{
|
{
|
||||||
private AuthorizationHelper $authorizationHelper;
|
private AuthorizationHelper $authorizationHelper;
|
||||||
@ -56,8 +54,10 @@ class PersonApiController extends ApiController
|
|||||||
static fn (array $data, string $key): array => ['key' => $key, 'labels' => $data],
|
static fn (array $data, string $key): array => ['key' => $key, 'labels' => $data],
|
||||||
$configAltNamesChoices,
|
$configAltNamesChoices,
|
||||||
array_keys($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);
|
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person);
|
||||||
|
|
||||||
$addresses = [];
|
|
||||||
// collect addresses from location in courses
|
// collect addresses from location in courses
|
||||||
foreach ($person->getAccompanyingPeriodParticipations() as $participation) {
|
$addresses = $person
|
||||||
if (null !== $participation->getAccompanyingPeriod()->getAddressLocation()) {
|
->getAccompanyingPeriodParticipations()
|
||||||
$a = $participation->getAccompanyingPeriod()->getAddressLocation();
|
->filter(
|
||||||
$addresses[$a->getId()] = $a;
|
static function (AccompanyingPeriodParticipation $accompanyingPeriodParticipation): bool {
|
||||||
}
|
return null !== $accompanyingPeriodParticipation->getAccompanyingPeriod()->getAddressLocation();
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
->map(
|
||||||
|
static function (AccompanyingPeriodParticipation $accompanyingPeriodParticipation): ?Address {
|
||||||
|
return $accompanyingPeriodParticipation->getAccompanyingPeriod()->getAddressLocation();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// remove the actual address
|
// remove the actual address
|
||||||
$actual = $person->getCurrentHouseholdAddress();
|
$actual = $person->getCurrentHouseholdAddress();
|
||||||
|
|
||||||
if (null !== $actual) {
|
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
|
return $altNames
|
||||||
->map(
|
->map(
|
||||||
static function (PersonAltName $personAltName): array {
|
static function (PersonAltName $personAltName): array {
|
||||||
return ['key' => $personAltName->getKey(), 'label' => $personAltName->getLabel()];
|
return [
|
||||||
|
'key' => $personAltName->getKey(),
|
||||||
|
'label' => $personAltName->getLabel(),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->toArray();
|
->toArray();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user