adaptations after having merged ticket-app-master

This commit is contained in:
2025-12-22 17:23:50 +01:00
parent 43d6a86627
commit 35d91762d3
42 changed files with 194 additions and 157 deletions

View File

@@ -14,11 +14,11 @@ namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
use Chill\MainBundle\Serializer\Model\Collection;
use Chill\PersonBundle\PersonIdentifier\PersonIdentifierManagerInterface;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\SerializerInterface;
final readonly class PersonIdentifierListApiController

View File

@@ -29,7 +29,7 @@ final class PersonIdentifiersType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
foreach ($this->identifierManager->getWorkers() as $k => $worker) {
foreach ($this->identifierManager->getWorkers() as $worker) {
if (!$worker->getDefinition()->isEditableByUsers()) {
continue;
}

View File

@@ -32,8 +32,13 @@ final readonly class PersonIdentifierWorkerNormalizer implements NormalizerInter
];
}
public function supportsNormalization($data, ?string $format = null): bool
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
{
return $data instanceof PersonIdentifierWorker;
}
public function getSupportedTypes(?string $format): array
{
return 'json' === $format ? [PersonIdentifierWorker::class => true] : [];
}
}

View File

@@ -17,6 +17,9 @@ use Chill\PersonBundle\PersonIdentifier\PersonIdentifierManagerInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends \Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository<\Chill\PersonBundle\Entity\Identifier\PersonIdentifier>
*/
class PersonIdentifierRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry, private readonly PersonIdentifierManagerInterface $personIdentifierManager)

View File

@@ -42,10 +42,10 @@ class PersonDocGenNormalizer implements
public function __construct(private readonly PersonRenderInterface $personRender, private readonly RelationshipRepository $relationshipRepository, private readonly TranslatableStringHelper $translatableStringHelper, private readonly SummaryBudgetInterface $summaryBudget) {}
public function normalize($person, $format = null, array $context = []): string|int|float|bool|\ArrayObject|array|null
public function normalize($data, $format = null, array $context = []): string|int|float|bool|\ArrayObject|array|null
{
try {
$context = $this->addCircularToContext($person, $context);
$context = $this->addCircularToContext($data, $context);
} catch (CircularReferenceException) {
return [
'isNull' => true,
@@ -54,7 +54,7 @@ class PersonDocGenNormalizer implements
];
}
/** @var Person $person */
/** @var Person $data */
$dateContext = $context;
$dateContext['docgen:expects'] = \DateTimeInterface::class;
$addressContext = array_merge($context, ['docgen:expects' => Address::class]);
@@ -69,53 +69,53 @@ class PersonDocGenNormalizer implements
]);
$genderContext = array_merge($context, ['docgen:expects' => Gender::class]);
if (null === $person) {
if (null === $data) {
return $this->normalizeNullValue($format, $context);
}
if (!$person instanceof Person) {
if (!$data instanceof Person) {
throw new UnexpectedValueException();
}
$data = [
'type' => 'person',
'id' => $person->getId(),
'id' => $data->getId(),
'isNull' => false,
'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expects' => Civility::class])),
'firstName' => $person->getFirstName(),
'lastName' => $person->getLastName(),
'civility' => $this->normalizer->normalize($data->getCivility(), $format, array_merge($context, ['docgen:expects' => Civility::class])),
'firstName' => $data->getFirstName(),
'lastName' => $data->getLastName(),
'altNames' => \implode(
', ',
\array_map(
static fn (PersonAltName $altName) => $altName->getLabel(),
$person->getAltNames()->toArray()
$data->getAltNames()->toArray()
)
),
'text' => $this->personRender->renderString($person, []),
'age' => (int) $person->getAge(),
'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $dateContext),
'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $dateContext),
'gender' => null !== ($g = $person->getGender()) ? $this->translatableStringHelper->localize($g->getLabel()) : '',
'genderEntity' => $this->normalizer->normalize($person->getGender(), $format, $genderContext),
'maritalStatus' => null !== ($ms = $person->getMaritalStatus()) ? $this->translatableStringHelper->localize($ms->getName()) : '',
'maritalStatusDate' => $this->normalizer->normalize($person->getMaritalStatusDate(), $format, $dateContext),
'maritalStatusComment' => $this->normalizer->normalize($person->getMaritalStatusComment(), $format, $dateContext),
'email' => $person->getEmail(),
'firstPhoneNumber' => $this->normalizer->normalize($person->getPhonenumber() ?? $person->getMobilenumber(), $format, $phonenumberContext),
'fixPhoneNumber' => $this->normalizer->normalize($person->getPhonenumber(), $format, $phonenumberContext),
'mobilePhoneNumber' => $this->normalizer->normalize($person->getMobilenumber(), $format, $phonenumberContext),
'nationality' => null !== ($c = $person->getNationality()) ? $this->translatableStringHelper->localize($c->getName()) : '',
'placeOfBirth' => $person->getPlaceOfBirth(),
'memo' => $person->getMemo(),
'numberOfChildren' => (string) $person->getNumberOfChildren(),
'address' => $this->normalizer->normalize($person->getCurrentPersonAddress(), $format, $addressContext),
'resources' => $this->normalizer->normalize($person->getResources(), $format, $personResourceContext),
'center' => $this->normalizer->normalize($person->getCenter(), $format, $centerContext),
'text' => $this->personRender->renderString($data, []),
'age' => (int) $data->getAge(),
'birthdate' => $this->normalizer->normalize($data->getBirthdate(), $format, $dateContext),
'deathdate' => $this->normalizer->normalize($data->getDeathdate(), $format, $dateContext),
'gender' => null !== ($g = $data->getGender()) ? $this->translatableStringHelper->localize($g->getLabel()) : '',
'genderEntity' => $this->normalizer->normalize($data->getGender(), $format, $genderContext),
'maritalStatus' => null !== ($ms = $data->getMaritalStatus()) ? $this->translatableStringHelper->localize($ms->getName()) : '',
'maritalStatusDate' => $this->normalizer->normalize($data->getMaritalStatusDate(), $format, $dateContext),
'maritalStatusComment' => $this->normalizer->normalize($data->getMaritalStatusComment(), $format, $dateContext),
'email' => $data->getEmail(),
'firstPhoneNumber' => $this->normalizer->normalize($data->getPhonenumber() ?? $data->getMobilenumber(), $format, $phonenumberContext),
'fixPhoneNumber' => $this->normalizer->normalize($data->getPhonenumber(), $format, $phonenumberContext),
'mobilePhoneNumber' => $this->normalizer->normalize($data->getMobilenumber(), $format, $phonenumberContext),
'nationality' => null !== ($c = $data->getNationality()) ? $this->translatableStringHelper->localize($c->getName()) : '',
'placeOfBirth' => $data->getPlaceOfBirth(),
'memo' => $data->getMemo(),
'numberOfChildren' => (string) $data->getNumberOfChildren(),
'address' => $this->normalizer->normalize($data->getCurrentPersonAddress(), $format, $addressContext),
'resources' => $this->normalizer->normalize($data->getResources(), $format, $personResourceContext),
'center' => $this->normalizer->normalize($data->getCenter(), $format, $centerContext),
];
if ($context['docgen:person:with-household'] ?? false) {
$data['household'] = $this->normalizer->normalize(
$person->getCurrentHousehold(),
$data->getCurrentHousehold(),
$format,
array_merge($context, [
'docgen:expects' => Household::class,
@@ -128,22 +128,22 @@ class PersonDocGenNormalizer implements
if ($context['docgen:person:with-relations'] ?? false) {
$data['relations'] = $this->normalizer->normalize(
new ArrayCollection($this->relationshipRepository->findByPerson($person)),
new ArrayCollection($this->relationshipRepository->findByPerson($data)),
$format,
array_merge($context, [
'docgen:person:with-household' => false,
'docgen:person:with-relation' => false,
'docgen:relationship:counterpart' => $person,
'docgen:relationship:counterpart' => $data,
'docgen:person:with-budget' => false,
])
);
}
if ($context['docgen:person:with-budget'] ?? false) {
$data['budget']['person'] = $this->summaryBudget->getSummaryForPerson($person);
$data['budget']['person'] = $this->summaryBudget->getSummaryForPerson($data);
if ($context['docgen:person:with-household'] ?? false) {
$data['budget']['household'] = $this->summaryBudget->getSummaryForHousehold($person->getCurrentHousehold());
$data['budget']['household'] = $this->summaryBudget->getSummaryForHousehold($data->getCurrentHousehold());
}
}

View File

@@ -148,8 +148,17 @@ final class PersonJsonDenormalizer implements DenormalizerInterface, Denormalize
return $person;
}
public function supportsDenormalization($data, $type, $format = null): bool
public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
{
return Person::class === $type && 'person' === ($data['type'] ?? null) && !isset($data['id']);
}
public function getSupportedTypes(?string $format): array
{
if ('json' === $format) {
return [Person::class => false];
}
return [];
}
}

View File

@@ -18,6 +18,7 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\PersonAltName;
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
@@ -38,50 +39,54 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
private readonly \Chill\PersonBundle\PersonIdentifier\Rendering\PersonIdRenderingInterface $personIdRendering,
) {}
/**
* @param Person $person
* @param string|null $format
*/
public function normalize($person, $format = null, array $context = [])
public function normalize($data, $format = null, array $context = []): array
{
if (!$data instanceof Person) {
throw new UnexpectedValueException(sprintf('Expected %s, got %s', Person::class, is_object($data) ? get_class($data) : gettype($data)));
}
$groups = $context[AbstractNormalizer::GROUPS] ?? [];
if (\is_string($groups)) {
$groups = [$groups];
}
$household = $person->getCurrentHousehold();
$currentResidentialAddresses = $this->residentialAddressRepository->findCurrentResidentialAddressByPerson($person);
$household = $data->getCurrentHousehold();
$currentResidentialAddresses = $this->residentialAddressRepository->findCurrentResidentialAddressByPerson($data);
$data = [
$normalizedData = [
'type' => 'person',
'id' => $person->getId(),
'text' => $this->render->renderString($person, ['addAge' => false]),
'textAge' => $this->render->renderString($person, ['addAge' => true]),
'firstName' => $person->getFirstName(),
'lastName' => $person->getLastName(),
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress(), $format, $context),
'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $context),
'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $context),
'age' => $this->normalizer->normalize($person->getAge(), $format, $context),
'phonenumber' => $this->normalizer->normalize($person->getPhonenumber(), $format, $context),
'mobilenumber' => $this->normalizer->normalize($person->getMobilenumber(), $format, $context),
'email' => $person->getEmail(),
'gender' => $this->normalizer->normalize($person->getGender(), $format, $context),
'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context),
'personId' => $this->personIdRendering->renderPersonId($person),
'identifiers' => $this->normalizer->normalize($person->getIdentifiers(), $format, $context),
'id' => $data->getId(),
'text' => $this->render->renderString($data, ['addAge' => false]),
'textAge' => $this->render->renderString($data, ['addAge' => true]),
'firstName' => $data->getFirstName(),
'lastName' => $data->getLastName(),
'current_household_address' => $this->normalizer->normalize($data->getCurrentHouseholdAddress(), $format, $context),
'birthdate' => $this->normalizer->normalize($data->getBirthdate(), $format, $context),
'deathdate' => $this->normalizer->normalize($data->getDeathdate(), $format, $context),
'age' => $this->normalizer->normalize($data->getAge(), $format, $context),
'phonenumber' => $this->normalizer->normalize($data->getPhonenumber(), $format, $context),
'mobilenumber' => $this->normalizer->normalize($data->getMobilenumber(), $format, $context),
'email' => $data->getEmail(),
'gender' => $this->normalizer->normalize($data->getGender(), $format, $context),
'civility' => $this->normalizer->normalize($data->getCivility(), $format, $context),
'personId' => $this->personIdRendering->renderPersonId($data),
'identifiers' => $this->normalizer->normalize($data->getIdentifiers(), $format, $context),
];
if (\in_array('minimal', $groups, true) && 1 === \count($groups)) {
return $data;
return $normalizedData;
}
return [...$data, 'centers' => $this->normalizer->normalize($this->centerResolverManager->resolveCenters($person), $format, $context), 'altNames' => $this->normalizeAltNames($person->getAltNames()), 'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null, 'current_residential_addresses' => $currentResidentialAddresses ?
$this->normalizer->normalize($currentResidentialAddresses, $format, $context) :
null];
return [
...$normalizedData,
'centers' => $this->normalizer->normalize($this->centerResolverManager->resolveCenters($data), $format, $context),
'altNames' => $this->normalizeAltNames($data->getAltNames()),
'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null,
'current_residential_addresses' => $currentResidentialAddresses ? $this->normalizer->normalize($currentResidentialAddresses, $format, $context) : null,
];
}
public function supportsNormalization($data, $format = null): bool
public function supportsNormalization($data, $format = null, array $context = []): bool
{
return $data instanceof Person && 'json' === $format;
}
@@ -91,7 +96,7 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
*
* @return array<array-key, array<string, string>>
*/
protected function normalizeAltNames(Collection $altNames): array
private function normalizeAltNames(Collection $altNames): array
{
return $altNames
->map(
@@ -105,6 +110,6 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
public function getSupportedTypes(?string $format): array
{
return 'json' === $format ? [Person::class => true] : [];
return 'json' === $format ? [Person::class => false] : [];
}
}

View File

@@ -44,8 +44,13 @@ readonly class PersonJsonReadDenormalizer implements DenormalizerInterface
throw new LogicException();
}
public function supportsDenormalization($data, string $type, ?string $format = null)
public function supportsDenormalization($data, string $type, ?string $format = null, array $context = []): bool
{
return is_array($data) && Person::class === $type && 'person' === ($data['type'] ?? null) && isset($data['id']);
}
public function getSupportedTypes(?string $format): array
{
return 'json' === $format ? [Person::class => true] : [];
}
}