mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
try to fix some things
This commit is contained in:
parent
cdd21c94c6
commit
1e146f542e
@ -19,6 +19,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
|||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
|
use Symfony\Component\Serializer\Annotation\Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity(repositoryClass=ResidentialAddressRepository::class)
|
* @ORM\Entity(repositoryClass=ResidentialAddressRepository::class)
|
||||||
@ -48,6 +49,7 @@ class ResidentialAddress
|
|||||||
* @ORM\ManyToOne(targetEntity=Person::class)
|
* @ORM\ManyToOne(targetEntity=Person::class)
|
||||||
* @ORM\JoinColumn(nullable=true)
|
* @ORM\JoinColumn(nullable=true)
|
||||||
* @Groups({"read"})
|
* @Groups({"read"})
|
||||||
|
* @Context(normalizationContext={"groups"={"minimal"}})
|
||||||
*/
|
*/
|
||||||
private ?Person $hostPerson = null;
|
private ?Person $hostPerson = null;
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ use Chill\PersonBundle\Entity\Person;
|
|||||||
use Chill\PersonBundle\Entity\Person\ResidentialAddress;
|
use Chill\PersonBundle\Entity\Person\ResidentialAddress;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,18 +32,37 @@ class ResidentialAddressRepository extends ServiceEntityRepository
|
|||||||
parent::__construct($registry, ResidentialAddress::class);
|
parent::__construct($registry, ResidentialAddress::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findCurrentResidentialAddressByPerson(Person $person, ?DateTimeImmutable $at = null): ?ResidentialAddress
|
/**
|
||||||
|
* @param Person $person
|
||||||
|
* @param DateTimeImmutable|null $at
|
||||||
|
* @return array|ResidentialAddress[]|null
|
||||||
|
*/
|
||||||
|
public function findCurrentResidentialAddressByPerson(Person $person, ?DateTimeImmutable $at = null): array
|
||||||
|
{
|
||||||
|
return $this->buildQueryFindCurrentResidentialAddresses($person, $at)
|
||||||
|
->select('ra')
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildQueryFindCurrentResidentialAddresses(Person $person, ?DateTimeImmutable $at = null): QueryBuilder
|
||||||
{
|
{
|
||||||
$addresses = $this->findBy(['person' => $person], ['startDate' => 'DESC']);
|
|
||||||
$date = null === $at ? new DateTimeImmutable('today') : $at;
|
$date = null === $at ? new DateTimeImmutable('today') : $at;
|
||||||
|
$qb = $this->createQueryBuilder('ra');
|
||||||
|
|
||||||
foreach ($addresses as $a) {
|
$dateFilter = $qb->expr()->andX(
|
||||||
if ($a->getStartDate() < $date && $a->getEndDate() > $date) {
|
$qb->expr()->lte('ra.startDate', ':dateIn'),
|
||||||
return $a;
|
$qb->expr()->orX(
|
||||||
}
|
$qb->expr()->isNull('ra.endDate'),
|
||||||
}
|
$qb->expr()->gte('ra.endDate', ':dateIn')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return null;
|
$qb
|
||||||
|
->where($dateFilter)
|
||||||
|
->setParameter('dateIn', $date, Types::DATE_IMMUTABLE);
|
||||||
|
|
||||||
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
|
@ -128,42 +128,42 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="item-col mx-3">
|
<div class="item-col mx-3" v-if="this.showResidentialAddresses && (person.current_residential_addresses || []).length > 0">
|
||||||
<div class="float-button bottom">
|
<div class="float-button bottom">
|
||||||
<div class="box">
|
<div class="box" >
|
||||||
<ul class="list-content fa-ul">
|
<ul class="list-content fa-ul">
|
||||||
<li v-if="person.current_residential_address">
|
<li v-for="addr in person.current_residential_addresses">
|
||||||
<i class="fa fa-li fa-map-marker"></i>
|
<i class="fa fa-li fa-map-marker"></i>
|
||||||
<div v-if="person.current_residential_address.address">
|
<div v-if="addr.address">
|
||||||
<address-render-box
|
<address-render-box
|
||||||
:address="person.current_residential_address.address"
|
:address="addr.address"
|
||||||
:isMultiline="isMultiline">
|
:isMultiline="isMultiline">
|
||||||
</address-render-box>
|
</address-render-box>
|
||||||
<p>({{ $t('renderbox.residential_address') }})</p>
|
<p>({{ $t('renderbox.residential_address') }})</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="person.current_residential_address.hostPerson" class="mt-3">
|
<div v-else-if="addr.hostPerson" class="mt-3">
|
||||||
<p>{{ $t('renderbox.located_at') }}:</p>
|
<p>{{ $t('renderbox.located_at') }}:</p>
|
||||||
<span class="chill-entity entity-person badge-person">
|
<span class="chill-entity entity-person badge-person">
|
||||||
<person-text
|
<person-text
|
||||||
v-if="person.current_residential_address.hostPerson"
|
v-if="addr.hostPerson"
|
||||||
:person="person.current_residential_address.hostPerson"
|
:person="addr.hostPerson"
|
||||||
></person-text>
|
></person-text>
|
||||||
</span>
|
</span>
|
||||||
<address-render-box v-if="person.current_residential_address.hostPerson.address"
|
<address-render-box v-if="addr.hostPerson.address"
|
||||||
:address="person.current_residential_address.hostPerson.address"
|
:address="addr.hostPerson.address"
|
||||||
:isMultiline="isMultiline">
|
:isMultiline="isMultiline">
|
||||||
</address-render-box>
|
</address-render-box>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="person.current_residential_address.hostThirdParty" class="mt-3">
|
<div v-else-if="addr.hostThirdParty" class="mt-3">
|
||||||
<p>{{ $t('renderbox.located_at') }}:</p>
|
<p>{{ $t('renderbox.located_at') }}:</p>
|
||||||
<span class="chill-entity entity-person badge-thirdparty">
|
<span class="chill-entity entity-person badge-thirdparty">
|
||||||
<third-party-text
|
<third-party-text
|
||||||
v-if="person.current_residential_address.hostThirdParty"
|
v-if="addr.hostThirdParty"
|
||||||
:thirdparty="person.current_residential_address.hostThirdParty"
|
:thirdparty="addr.hostThirdParty"
|
||||||
></third-party-text>
|
></third-party-text>
|
||||||
</span>
|
</span>
|
||||||
<address-render-box v-if="person.current_residential_address.hostThirdParty.address"
|
<address-render-box v-if="addr.hostThirdParty.address"
|
||||||
:address="person.current_residential_address.hostThirdParty.address"
|
:address="addr.hostThirdParty.address"
|
||||||
:isMultiline="isMultiline">
|
:isMultiline="isMultiline">
|
||||||
</address-render-box>
|
</address-render-box>
|
||||||
</div>
|
</div>
|
||||||
@ -216,7 +216,25 @@ export default {
|
|||||||
PersonText,
|
PersonText,
|
||||||
ThirdPartyText
|
ThirdPartyText
|
||||||
},
|
},
|
||||||
props: ['person', 'options', 'render', 'returnPath'],
|
props: {
|
||||||
|
person: {
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
type: Object,
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
render: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
returnPath: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
showResidentialAddresses: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
isMultiline: function() {
|
isMultiline: function() {
|
||||||
if(this.options.isMultiline){
|
if(this.options.isMultiline){
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
addNoData: true,
|
addNoData: true,
|
||||||
isMultiline: true
|
isMultiline: true
|
||||||
}"
|
}"
|
||||||
|
:show-residential-addresses="true"
|
||||||
></person-render-box>
|
></person-render-box>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,6 +22,7 @@ use DateTime;
|
|||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||||
@ -35,7 +36,9 @@ use function array_key_exists;
|
|||||||
class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwareInterface, PersonJsonNormalizerInterface
|
class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwareInterface, PersonJsonNormalizerInterface
|
||||||
{
|
{
|
||||||
use DenormalizerAwareTrait;
|
use DenormalizerAwareTrait;
|
||||||
|
|
||||||
use NormalizerAwareTrait;
|
use NormalizerAwareTrait;
|
||||||
|
|
||||||
use ObjectToPopulateTrait;
|
use ObjectToPopulateTrait;
|
||||||
|
|
||||||
private CenterResolverManagerInterface $centerResolverManager;
|
private CenterResolverManagerInterface $centerResolverManager;
|
||||||
@ -177,29 +180,37 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
|
|||||||
*/
|
*/
|
||||||
public function normalize($person, $format = null, array $context = [])
|
public function normalize($person, $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
|
$groups = $context[AbstractNormalizer::GROUPS] ?? [];
|
||||||
$household = $person->getCurrentHousehold();
|
$household = $person->getCurrentHousehold();
|
||||||
$currentResidentialAddress = $this->residentialAddressRepository->findCurrentResidentialAddressByPerson($person);
|
$currentResidentialAddresses = $this->residentialAddressRepository->findCurrentResidentialAddressByPerson($person);
|
||||||
|
|
||||||
return [
|
$data = [
|
||||||
'type' => 'person',
|
'type' => 'person',
|
||||||
'id' => $person->getId(),
|
'id' => $person->getId(),
|
||||||
'text' => $this->render->renderString($person, ['addAge' => false]),
|
'text' => $this->render->renderString($person, ['addAge' => false]),
|
||||||
'textAge' => $this->render->renderString($person, ['addAge' => true]),
|
'textAge' => $this->render->renderString($person, ['addAge' => true]),
|
||||||
'firstName' => $person->getFirstName(),
|
'firstName' => $person->getFirstName(),
|
||||||
'lastName' => $person->getLastName(),
|
'lastName' => $person->getLastName(),
|
||||||
|
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress(), $format, $context),
|
||||||
'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $context),
|
'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $context),
|
||||||
'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $context),
|
'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $context),
|
||||||
'age' => $this->normalizer->normalize($person->getAge(), $format, $context),
|
'age' => $this->normalizer->normalize($person->getAge(), $format, $context),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (in_array("minimal", $groups) && 1 === count($context)) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_merge($data, [
|
||||||
'centers' => $this->normalizer->normalize($this->centerResolverManager->resolveCenters($person), $format, $context),
|
'centers' => $this->normalizer->normalize($this->centerResolverManager->resolveCenters($person), $format, $context),
|
||||||
'phonenumber' => $person->getPhonenumber(),
|
'phonenumber' => $person->getPhonenumber(),
|
||||||
'mobilenumber' => $person->getMobilenumber(),
|
'mobilenumber' => $person->getMobilenumber(),
|
||||||
'email' => $person->getEmail(),
|
'email' => $person->getEmail(),
|
||||||
'altNames' => $this->normalizeAltNames($person->getAltNames()),
|
'altNames' => $this->normalizeAltNames($person->getAltNames()),
|
||||||
'gender' => $person->getGender(),
|
'gender' => $person->getGender(),
|
||||||
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress(), $format, $context),
|
|
||||||
'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null,
|
'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null,
|
||||||
'current_residential_address' => $currentResidentialAddress ? $this->normalizer->normalize($currentResidentialAddress, $format, $context) : null,
|
'current_residential_addresses' => $currentResidentialAddresses ? $this->normalizer->normalize($currentResidentialAddresses, $format, $context) : null,
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsDenormalization($data, $type, $format = null)
|
public function supportsDenormalization($data, $type, $format = null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user