From 2926965400309ea76fa9e4b98311c56c33258528 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 17 Feb 2022 15:08:12 +0100 Subject: [PATCH 01/11] move residentialAddress entity to the ChillPerson bundle --- .../migrations/Version20220217133607.php | 38 +++++++++++++++++++ .../ResidentialAddressController.php | 6 +-- .../Entity/Person}/ResidentialAddress.php | 7 ++-- .../Form}/ResidentialAddressType.php | 6 ++- .../ResidentialAddressRepository.php | 4 +- 5 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20220217133607.php rename src/Bundle/{ChillMainBundle/Entity => ChillPersonBundle/Entity/Person}/ResidentialAddress.php (94%) rename src/Bundle/{ChillMainBundle/Form/Type => ChillPersonBundle/Form}/ResidentialAddressType.php (91%) rename src/Bundle/{ChillMainBundle => ChillPersonBundle}/Repository/ResidentialAddressRepository.php (94%) diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220217133607.php b/src/Bundle/ChillMainBundle/migrations/Version20220217133607.php new file mode 100644 index 000000000..b2be09645 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20220217133607.php @@ -0,0 +1,38 @@ +addSql('ALTER TABLE IF EXISTS chill_main_residential_address RENAME TO chill_person_residential_address;'); + $this->addSql('ALTER SEQUENCE IF EXISTS chill_main_residential_address_id_seq RENAME TO chill_person_residential_address_id_seq;'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE IF EXISTS chill_person_residential_address RENAME TO chill_main_residential_address;'); + $this->addSql('ALTER SEQUENCE IF EXISTS chill_person_residential_address_id_seq RENAME TO chill_main_residential_address_id_seq;'); + } +} diff --git a/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php b/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php index 8b266208a..a2330bf88 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php @@ -11,9 +11,9 @@ declare(strict_types=1); namespace Chill\PersonBundle\Controller; -use Chill\MainBundle\Entity\ResidentialAddress; -use Chill\MainBundle\Form\Type\ResidentialAddressType; -use Chill\MainBundle\Repository\ResidentialAddressRepository; +use Chill\PersonBundle\Entity\Person\ResidentialAddress; +use Chill\PersonBundle\Form\Type\ResidentialAddressType; +use Chill\PersonBundle\Repository\ResidentialAddressRepository; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; diff --git a/src/Bundle/ChillMainBundle/Entity/ResidentialAddress.php b/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php similarity index 94% rename from src/Bundle/ChillMainBundle/Entity/ResidentialAddress.php rename to src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php index 7763ea9d5..b2f10ac08 100644 --- a/src/Bundle/ChillMainBundle/Entity/ResidentialAddress.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php @@ -9,10 +9,11 @@ declare(strict_types=1); -namespace Chill\MainBundle\Entity; +namespace Chill\PersonBundle\Entity\Person; +use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; -use Chill\MainBundle\Repository\ResidentialAddressRepository; +use Chill\PersonBundle\Repository\ResidentialAddressRepository; use Chill\PersonBundle\Entity\Person; use Chill\ThirdPartyBundle\Entity\ThirdParty; use DateTimeImmutable; @@ -20,7 +21,7 @@ use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass=ResidentialAddressRepository::class) - * @ORM\Table(name="chill_main_residential_address") + * @ORM\Table(name="chill_person_residential_address") */ class ResidentialAddress { diff --git a/src/Bundle/ChillMainBundle/Form/Type/ResidentialAddressType.php b/src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php similarity index 91% rename from src/Bundle/ChillMainBundle/Form/Type/ResidentialAddressType.php rename to src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php index 0ebe47fef..e7577f336 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/ResidentialAddressType.php +++ b/src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php @@ -9,9 +9,11 @@ declare(strict_types=1); -namespace Chill\MainBundle\Form\Type; +namespace Chill\PersonBundle\Form\Type; -use Chill\MainBundle\Entity\ResidentialAddress; +use Chill\MainBundle\Form\Type\CommentType; +use Chill\MainBundle\Form\Type\PickAddressType; +use Chill\PersonBundle\Entity\Person\ResidentialAddress; use Chill\PersonBundle\Form\Type\PickPersonDynamicType; use Chill\ThirdPartyBundle\Form\Type\PickThirdpartyDynamicType; use Symfony\Component\Form\AbstractType; diff --git a/src/Bundle/ChillMainBundle/Repository/ResidentialAddressRepository.php b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php similarity index 94% rename from src/Bundle/ChillMainBundle/Repository/ResidentialAddressRepository.php rename to src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php index 05cdfdf6c..fedbe8824 100644 --- a/src/Bundle/ChillMainBundle/Repository/ResidentialAddressRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php @@ -9,9 +9,9 @@ declare(strict_types=1); -namespace Chill\MainBundle\Repository; +namespace Chill\PersonBundle\Repository; -use Chill\MainBundle\Entity\ResidentialAddress; +use Chill\PersonBundle\Entity\Person\ResidentialAddress; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; From 24fc7a216b03a56027c3ba63b979f54ee0cf8fa7 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 17 Feb 2022 15:42:37 +0100 Subject: [PATCH 02/11] person: add current residential address in normalizer --- .../Repository/ResidentialAddressRepository.php | 17 +++++++++++++++++ .../Normalizer/PersonJsonNormalizer.php | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php index fedbe8824..4807fb65e 100644 --- a/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php @@ -11,10 +11,14 @@ declare(strict_types=1); namespace Chill\PersonBundle\Repository; +use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person\ResidentialAddress; +use DateTimeImmutable; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + /** * @method ResidentialAddress|null find($id, $lockMode = null, $lockVersion = null) * @method ResidentialAddress|null findOneBy(array $criteria, array $orderBy = null) @@ -28,6 +32,19 @@ class ResidentialAddressRepository extends ServiceEntityRepository parent::__construct($registry, ResidentialAddress::class); } + public function findCurrentResidentialAddressByPerson(Person $person, ?DateTimeImmutable $at = null): ?ResidentialAddress + { + $addresses = $this->findBy(['person' => $person], ['startDate' => 'DESC']); + $date = null === $at ? new DateTimeImmutable('today') : $at; + + foreach ($addresses as $a) { + if($a->getStartDate() < $date && $a->getEndDate() > $date) { + return $a; + } + } + return null; + } + // /** // * @return ResidentialAddress[] Returns an array of ResidentialAddress objects // */ diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index e91748de8..492575b81 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\PersonAltName; use Chill\PersonBundle\Repository\PersonRepository; +use Chill\PersonBundle\Repository\ResidentialAddressRepository; use DateTime; use DateTimeImmutable; use Doctrine\Common\Collections\Collection; @@ -51,14 +52,18 @@ class PersonJsonNormalizer implements private PersonRepository $repository; + private ResidentialAddressRepository $residentialAddressRepository; + public function __construct( ChillEntityRenderExtension $render, PersonRepository $repository, - CenterResolverManagerInterface $centerResolverManager + CenterResolverManagerInterface $centerResolverManager, + ResidentialAddressRepository $residentialAddressRepository ) { $this->render = $render; $this->repository = $repository; $this->centerResolverManager = $centerResolverManager; + $this->residentialAddressRepository = $residentialAddressRepository; } public function denormalize($data, $type, $format = null, array $context = []) @@ -181,6 +186,7 @@ class PersonJsonNormalizer implements public function normalize($person, $format = null, array $context = []) { $household = $person->getCurrentHousehold(); + $currentResidentialAddress = $this->residentialAddressRepository->findCurrentResidentialAddressByPerson($person); return [ 'type' => 'person', @@ -200,6 +206,7 @@ class PersonJsonNormalizer implements '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_residential_address' => $currentResidentialAddress ? $this->normalizer->normalize($currentResidentialAddress->getAddress()): null ]; } From c302f2dcf9aa21fa08d8ea576acbeb2cbef3f244 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 17 Feb 2022 16:29:51 +0100 Subject: [PATCH 03/11] PersonRenderBox: add residential address --- .../vuejs/_components/Entity/PersonRenderBox.vue | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue index dd26db217..84c1f25e6 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue @@ -115,7 +115,21 @@ - + + +
+ +
    +
  • + ICI l'adresse de résidence, if any + + + +
  • +
+
From baf9b6e1ae3586f90179efef0bd24eb3404cb081 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 17 Feb 2022 18:04:50 +0100 Subject: [PATCH 04/11] residential address: correct normalization --- .../Serializer/Normalizer/PersonJsonNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index 492575b81..6d2790ab1 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -206,7 +206,7 @@ class PersonJsonNormalizer implements '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_residential_address' => $currentResidentialAddress ? $this->normalizer->normalize($currentResidentialAddress->getAddress()): null + 'current_residential_address' => $currentResidentialAddress ? $this->normalizer->normalize($currentResidentialAddress, $format, $context): null ]; } From 6e1b95aa60740458dbf98b86723340ab5c8ac745 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 17 Feb 2022 18:05:34 +0100 Subject: [PATCH 05/11] residential address: show residential address or info in PersonRenderBox + add ThirdPartyText --- .../Resources/public/vuejs/_js/i18n.js | 3 +- .../Entity/Person/ResidentialAddress.php | 6 ++ .../_components/Entity/PersonRenderBox.vue | 58 +++++++++++++++---- .../views/ResidentialAddress/list.html.twig | 2 +- .../_components/Entity/ThirdPartyText.vue | 29 ++++++++++ 5 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/Entity/ThirdPartyText.vue diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.js index 0f2b52568..32049dcdd 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.js @@ -69,7 +69,8 @@ const messages = { }, holder: "Titulaire", years_old: "an | {n} an | {n} ans", - + residential_address: "Adresse de résidence", + located_at: "réside chez" } } }; diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php b/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php index b2f10ac08..c59511552 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\PersonBundle\Repository\ResidentialAddressRepository; use Chill\PersonBundle\Entity\Person; use Chill\ThirdPartyBundle\Entity\ThirdParty; +use Symfony\Component\Serializer\Annotation\Groups; use DateTimeImmutable; use Doctrine\ORM\Mapping as ORM; @@ -28,6 +29,7 @@ class ResidentialAddress /** * @ORM\ManyToOne(targetEntity=Address::class) * @ORM\JoinColumn(nullable=true) + * @Groups({"read"}) */ private ?Address $address = null; @@ -38,18 +40,21 @@ class ResidentialAddress /** * @ORM\Column(type="datetime_immutable", nullable=true) + * @Groups({"read"}) */ private ?DateTimeImmutable $endDate = null; /** * @ORM\ManyToOne(targetEntity=Person::class) * @ORM\JoinColumn(nullable=true) + * @Groups({"read"}) */ private ?Person $hostPerson = null; /** * @ORM\ManyToOne(targetEntity=ThirdParty::class) * @ORM\JoinColumn(nullable=true) + * @Groups({"read"}) */ private ?ThirdParty $hostThirdParty = null; @@ -68,6 +73,7 @@ class ResidentialAddress /** * @ORM\Column(type="datetime_immutable") + * @Groups({"read"}) */ private ?DateTimeImmutable $startDate = null; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue index 84c1f25e6..648319079 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue @@ -117,18 +117,50 @@ -
+
+
+
+
    +
  • + +
    + + +

    ({{ $t('renderbox.residential_address') }})

    +
    +
    +

    {{ $t('renderbox.located_at') }}:

    + + + + + +
    +
    +

    {{ $t('renderbox.located_at') }}:

    + + + + + +
    -
      -
    • - ICI l'adresse de résidence, if any - - - -
    • -
    +
  • +
+
+
@@ -162,6 +194,7 @@ import AddressRenderBox from 'ChillMainAssets/vuejs/_components/Entity/AddressRe import Confidential from 'ChillMainAssets/vuejs/_components/Confidential.vue'; import BadgeEntity from 'ChillMainAssets/vuejs/_components/BadgeEntity.vue'; import PersonText from 'ChillPersonAssets/vuejs/_components/Entity/PersonText.vue'; +import ThirdPartyText from 'ChillThirdPartyAssets/vuejs/_components/Entity/ThirdPartyText.vue'; export default { name: "PersonRenderBox", @@ -169,7 +202,8 @@ export default { AddressRenderBox, Confidential, BadgeEntity, - PersonText + PersonText, + ThirdPartyText }, props: ['person', 'options', 'render', 'returnPath'], computed: { diff --git a/src/Bundle/ChillPersonBundle/Resources/views/ResidentialAddress/list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/ResidentialAddress/list.html.twig index 69e12f36d..4cba32e47 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/ResidentialAddress/list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/ResidentialAddress/list.html.twig @@ -62,7 +62,7 @@
  • {{ "Address of"|trans}} - {{ a.hostThirdParty|chill_entity_render_box }} + {{ a.hostThirdParty|chill_entity_render_box }}
  • {% if a.hostThirdParty.address is not null %} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/Entity/ThirdPartyText.vue b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/Entity/ThirdPartyText.vue new file mode 100644 index 000000000..621a9f8b8 --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/Entity/ThirdPartyText.vue @@ -0,0 +1,29 @@ + + + From c5d2953ecb4a94ec426b08f21cf9eaeff94bf945 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 18 Feb 2022 09:15:13 +0100 Subject: [PATCH 06/11] php code fix for Residential Address --- .../migrations/Version20220217133607.php | 14 +++++++------- .../Controller/ResidentialAddressController.php | 2 +- .../Entity/Person/ResidentialAddress.php | 4 ++-- .../Form/ResidentialAddressType.php | 1 - .../Repository/ResidentialAddressRepository.php | 5 ++--- .../Serializer/Normalizer/PersonJsonNormalizer.php | 4 +--- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220217133607.php b/src/Bundle/ChillMainBundle/migrations/Version20220217133607.php index b2be09645..b6c6106f1 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20220217133607.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20220217133607.php @@ -15,10 +15,16 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; /** - * Rename residential_address table + * Rename residential_address table. */ final class Version20220217133607 extends AbstractMigration { + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE IF EXISTS chill_person_residential_address RENAME TO chill_main_residential_address;'); + $this->addSql('ALTER SEQUENCE IF EXISTS chill_person_residential_address_id_seq RENAME TO chill_main_residential_address_id_seq;'); + } + public function getDescription(): string { return 'Rename residential_address table'; @@ -29,10 +35,4 @@ final class Version20220217133607 extends AbstractMigration $this->addSql('ALTER TABLE IF EXISTS chill_main_residential_address RENAME TO chill_person_residential_address;'); $this->addSql('ALTER SEQUENCE IF EXISTS chill_main_residential_address_id_seq RENAME TO chill_person_residential_address_id_seq;'); } - - public function down(Schema $schema): void - { - $this->addSql('ALTER TABLE IF EXISTS chill_person_residential_address RENAME TO chill_main_residential_address;'); - $this->addSql('ALTER SEQUENCE IF EXISTS chill_person_residential_address_id_seq RENAME TO chill_main_residential_address_id_seq;'); - } } diff --git a/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php b/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php index a2330bf88..f77a4150c 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php @@ -11,10 +11,10 @@ declare(strict_types=1); namespace Chill\PersonBundle\Controller; +use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person\ResidentialAddress; use Chill\PersonBundle\Form\Type\ResidentialAddressType; use Chill\PersonBundle\Repository\ResidentialAddressRepository; -use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\FormType; diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php b/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php index c59511552..33cc41dc1 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php @@ -13,12 +13,12 @@ namespace Chill\PersonBundle\Entity\Person; use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; -use Chill\PersonBundle\Repository\ResidentialAddressRepository; use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Repository\ResidentialAddressRepository; use Chill\ThirdPartyBundle\Entity\ThirdParty; -use Symfony\Component\Serializer\Annotation\Groups; use DateTimeImmutable; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation\Groups; /** * @ORM\Entity(repositoryClass=ResidentialAddressRepository::class) diff --git a/src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php b/src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php index e7577f336..b34395daf 100644 --- a/src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php +++ b/src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php @@ -14,7 +14,6 @@ namespace Chill\PersonBundle\Form\Type; use Chill\MainBundle\Form\Type\CommentType; use Chill\MainBundle\Form\Type\PickAddressType; use Chill\PersonBundle\Entity\Person\ResidentialAddress; -use Chill\PersonBundle\Form\Type\PickPersonDynamicType; use Chill\ThirdPartyBundle\Form\Type\PickThirdpartyDynamicType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\DateType; diff --git a/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php index 4807fb65e..11ea823fd 100644 --- a/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php @@ -17,8 +17,6 @@ use DateTimeImmutable; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; -use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; - /** * @method ResidentialAddress|null find($id, $lockMode = null, $lockVersion = null) * @method ResidentialAddress|null findOneBy(array $criteria, array $orderBy = null) @@ -38,10 +36,11 @@ class ResidentialAddressRepository extends ServiceEntityRepository $date = null === $at ? new DateTimeImmutable('today') : $at; foreach ($addresses as $a) { - if($a->getStartDate() < $date && $a->getEndDate() > $date) { + if ($a->getStartDate() < $date && $a->getEndDate() > $date) { return $a; } } + return null; } diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index 6d2790ab1..66c7a1145 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -41,9 +41,7 @@ class PersonJsonNormalizer implements NormalizerInterface { use DenormalizerAwareTrait; - use NormalizerAwareTrait; - use ObjectToPopulateTrait; private CenterResolverManagerInterface $centerResolverManager; @@ -206,7 +204,7 @@ class PersonJsonNormalizer implements '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_residential_address' => $currentResidentialAddress ? $this->normalizer->normalize($currentResidentialAddress, $format, $context): null + 'current_residential_address' => $currentResidentialAddress ? $this->normalizer->normalize($currentResidentialAddress, $format, $context) : null, ]; } From 57175e1c0b9f44ac3117a56f3fb746da09f60313 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 18 Feb 2022 09:18:09 +0100 Subject: [PATCH 07/11] upd CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae2c248e7..1cc494f42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to * date versioning for test releases ## Unreleased +* [person] residential address: show residential address or info in PersonRenderBox, refactor Residential Address (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/439) + * AddPersons: remove ul-li html tags from AddPersons (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/419) * [person]: AddPersons: allow creation of person or thirdparty only (no users) (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/422) * [person]: AddPersons: allow creation of person or thirdparty depending on allowed types (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/422) From 1e146f542eb1e44a666f4f48af76e2c9add78dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 28 Feb 2022 16:09:52 +0100 Subject: [PATCH 08/11] try to fix some things --- .../Entity/Person/ResidentialAddress.php | 2 + .../ResidentialAddressRepository.php | 37 +++++++++++--- .../_components/Entity/PersonRenderBox.vue | 50 +++++++++++++------ .../vuejs/_components/OnTheFly/Person.vue | 1 + .../Normalizer/PersonJsonNormalizer.php | 21 ++++++-- 5 files changed, 82 insertions(+), 29 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php b/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php index 33cc41dc1..cb82f766a 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/ResidentialAddress.php @@ -19,6 +19,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty; use DateTimeImmutable; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; +use Symfony\Component\Serializer\Annotation\Context; /** * @ORM\Entity(repositoryClass=ResidentialAddressRepository::class) @@ -48,6 +49,7 @@ class ResidentialAddress * @ORM\ManyToOne(targetEntity=Person::class) * @ORM\JoinColumn(nullable=true) * @Groups({"read"}) + * @Context(normalizationContext={"groups"={"minimal"}}) */ private ?Person $hostPerson = null; diff --git a/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php index 11ea823fd..743a7d9f4 100644 --- a/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php @@ -15,6 +15,8 @@ use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person\ResidentialAddress; use DateTimeImmutable; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ManagerRegistry; /** @@ -30,18 +32,37 @@ class ResidentialAddressRepository extends ServiceEntityRepository 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; + $qb = $this->createQueryBuilder('ra'); - foreach ($addresses as $a) { - if ($a->getStartDate() < $date && $a->getEndDate() > $date) { - return $a; - } - } + $dateFilter = $qb->expr()->andX( + $qb->expr()->lte('ra.startDate', ':dateIn'), + $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; } // /** diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue index 2f3c191b3..2ded0840b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue @@ -128,42 +128,42 @@ -
    +
    -
    +
      -
    • +
    • -
      +

      ({{ $t('renderbox.residential_address') }})

      -
      +

      {{ $t('renderbox.located_at') }}:

      -
      -
      +

      {{ $t('renderbox.located_at') }}:

      -
      @@ -216,7 +216,25 @@ export default { PersonText, 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: { isMultiline: function() { if(this.options.isMultiline){ diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue index e007ee94d..366ecd6b7 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue @@ -15,6 +15,7 @@ addNoData: true, isMultiline: true }" + :show-residential-addresses="true" >
      diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index 4026518c9..a79a2f6cd 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -22,6 +22,7 @@ use DateTime; use DateTimeImmutable; use Doctrine\Common\Collections\Collection; use Symfony\Component\Serializer\Exception\UnexpectedValueException; +use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; @@ -35,7 +36,9 @@ use function array_key_exists; class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwareInterface, PersonJsonNormalizerInterface { use DenormalizerAwareTrait; + use NormalizerAwareTrait; + use ObjectToPopulateTrait; private CenterResolverManagerInterface $centerResolverManager; @@ -177,29 +180,37 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar */ public function normalize($person, $format = null, array $context = []) { + $groups = $context[AbstractNormalizer::GROUPS] ?? []; $household = $person->getCurrentHousehold(); - $currentResidentialAddress = $this->residentialAddressRepository->findCurrentResidentialAddressByPerson($person); + $currentResidentialAddresses = $this->residentialAddressRepository->findCurrentResidentialAddressByPerson($person); - return [ + $data = [ '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), + ]; + + if (in_array("minimal", $groups) && 1 === count($context)) { + return $data; + } + + return array_merge($data, [ 'centers' => $this->normalizer->normalize($this->centerResolverManager->resolveCenters($person), $format, $context), 'phonenumber' => $person->getPhonenumber(), 'mobilenumber' => $person->getMobilenumber(), 'email' => $person->getEmail(), 'altNames' => $this->normalizeAltNames($person->getAltNames()), '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_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) From a7240e8cc6fa7a7699cfeef2a02188ce55fa76f7 Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 1 Mar 2022 14:15:39 +0100 Subject: [PATCH 09/11] PersonJsonNormalizer: fix circular reference with residential address --- .../Serializer/Normalizer/PersonJsonNormalizer.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index a79a2f6cd..f13a6d40d 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -197,7 +197,7 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar 'age' => $this->normalizer->normalize($person->getAge(), $format, $context), ]; - if (in_array("minimal", $groups) && 1 === count($context)) { + if (in_array("minimal", $groups) && 1 === count($groups)) { return $data; } @@ -209,7 +209,9 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar 'altNames' => $this->normalizeAltNames($person->getAltNames()), 'gender' => $person->getGender(), 'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null, - 'current_residential_addresses' => $currentResidentialAddresses ? $this->normalizer->normalize($currentResidentialAddresses, $format, $context) : null, + 'current_residential_addresses' => $currentResidentialAddresses ? + $this->normalizer->normalize($currentResidentialAddresses, $format, $context) : + null, ]); } From 48a32f240386a8e809c00ef14de51b3583037307 Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 1 Mar 2022 14:36:22 +0100 Subject: [PATCH 10/11] residential address: filter by person in the repository --- .../Repository/ResidentialAddressRepository.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php index 743a7d9f4..b5d64a31a 100644 --- a/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php @@ -50,6 +50,8 @@ class ResidentialAddressRepository extends ServiceEntityRepository $date = null === $at ? new DateTimeImmutable('today') : $at; $qb = $this->createQueryBuilder('ra'); + + $dateFilter = $qb->expr()->andX( $qb->expr()->lte('ra.startDate', ':dateIn'), $qb->expr()->orX( @@ -60,7 +62,9 @@ class ResidentialAddressRepository extends ServiceEntityRepository $qb ->where($dateFilter) - ->setParameter('dateIn', $date, Types::DATE_IMMUTABLE); + ->setParameter('dateIn', $date, Types::DATE_IMMUTABLE) + ->andWhere('ra.person = :person') + ->setParameter('person', $person); return $qb; } From 5695bb0e9e086c1694630b2e86f346a733b00486 Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 1 Mar 2022 14:36:47 +0100 Subject: [PATCH 11/11] add missing key in v-for loop --- .../public/vuejs/_components/Entity/PersonRenderBox.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue index 2ded0840b..f2cf1f7bd 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/PersonRenderBox.vue @@ -132,7 +132,7 @@
        -
      • +