From dd48795f6470edc2824407ada83c0f3300377552 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 14 Apr 2021 14:49:19 +0200 Subject: [PATCH 01/28] #23 enable postgis in a chil main migration --- .../migrations/Version20210414091001.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20210414091001.php diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210414091001.php b/src/Bundle/ChillMainBundle/migrations/Version20210414091001.php new file mode 100644 index 000000000..7881d9558 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20210414091001.php @@ -0,0 +1,32 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('CREATE EXTENSION IF NOT EXISTS postgis;'); + + } + + public function down(Schema $schema) : void + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('DROP EXTENSION IF NOT EXISTS postgis;'); + } + + public function getDescription(): string + { + return "Enable the postgis extension in public schema"; + } +} From ebd58d422985aee19f183c5e86d08e7ad2e23bd5 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 15 Apr 2021 10:46:29 +0200 Subject: [PATCH 02/28] add more fields to Address entity + rename streetAddress1 and streetAddress2 --- src/Bundle/ChillMainBundle/Entity/Address.php | 235 +++++++++++++++--- 1 file changed, 207 insertions(+), 28 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Address.php b/src/Bundle/ChillMainBundle/Entity/Address.php index 69c39c7b6..1286ba2e0 100644 --- a/src/Bundle/ChillMainBundle/Entity/Address.php +++ b/src/Bundle/ChillMainBundle/Entity/Address.php @@ -28,14 +28,14 @@ class Address * * @ORM\Column(type="string", length=255) */ - private $streetAddress1 = ''; + private $street = ''; /** * @var string * * @ORM\Column(type="string", length=255) */ - private $streetAddress2 = ''; + private $number = ''; /** * @var PostalCode @@ -43,7 +43,56 @@ class Address * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\PostalCode") */ private $postcode; - + + /** + * @var string + * + * @ORM\Column(type="string", length=16, nullable=true) + */ + private $floor; + + /** + * @var string + * + * @ORM\Column(type="string", length=16, nullable=true) + */ + private $corridor; + + /** + * @var string + * + * @ORM\Column(type="string", length=16, nullable=true) + */ + private $steps; + + /** + * @var string + * + * @ORM\Column(type="string", length=255, nullable=true) + */ + private $buildingName; + + /** + * @var string + * + * @ORM\Column(type="string", length=16, nullable=true) + */ + private $flat; + + /** + * @var string + * + * @ORM\Column(type="string", length=255, nullable=true) + */ + private $distribution; + + /** + * @var string + * + * @ORM\Column(type="string", length=255, nullable=true) + */ + private $extra; + /** * Indicates when the address starts validation. Used to build an history * of address. By default, the current date. @@ -53,21 +102,31 @@ class Address * @ORM\Column(type="date") */ private $validFrom; - + + /** + * Indicates when the address ends. Used to build an history + * of address. + * + * @var \DateTime + * + * @ORM\Column(type="date") + */ + private $validTo; + /** * True if the address is a "no address", aka homeless person, ... * * @var bool */ private $isNoAddress = false; - + /** * A list of metadata, added by customizable fields - * + * * @var array */ private $customs = []; - + public function __construct() { $this->validFrom = new \DateTime(); @@ -105,7 +164,7 @@ class Address */ public function getStreetAddress1() { - return $this->streetAddress1; + return $this->street; } /** @@ -129,7 +188,7 @@ class Address */ public function getStreetAddress2() { - return $this->streetAddress2; + return $this->number; } /** @@ -155,7 +214,7 @@ class Address { return $this->postcode; } - + /** * @return \DateTime */ @@ -173,19 +232,19 @@ class Address $this->validFrom = $validFrom; return $this; } - + /** * Get IsNoAddress - * + * * Indicate true if the address is a fake address (homeless, ...) - * + * * @return bool */ public function getIsNoAddress(): bool { return $this->isNoAddress; } - + /** * @return bool */ @@ -196,9 +255,9 @@ class Address /** * Set IsNoAddress - * + * * Indicate true if the address is a fake address (homeless, ...) - * + * * @param bool $isNoAddress * @return $this */ @@ -207,10 +266,10 @@ class Address $this->isNoAddress = $isNoAddress; return $this; } - + /** * Get customs informations in the address - * + * * @return array */ public function getCustoms(): array @@ -220,27 +279,27 @@ class Address /** * Store custom informations in the address - * + * * @param array $customs * @return $this */ public function setCustoms(array $customs): self { $this->customs = $customs; - + return $this; } - + /** * Validate the address. - * + * * Check that: - * + * * * if the address is not home address: * * the postal code is present * * the valid from is not null * * the address street 1 is greater than 2 - * + * * @param ExecutionContextInterface $context * @param array $payload */ @@ -252,18 +311,18 @@ class Address ->atPath('validFrom') ->addViolation(); } - + if ($this->isNoAddress()) { return; } - + if (empty($this->getStreetAddress1())) { $context ->buildViolation("address.street1-should-be-set") ->atPath('streetAddress1') ->addViolation(); } - + if (!$this->getPostcode() instanceof PostalCode) { $context ->buildViolation("address.postcode-should-be-set") @@ -271,7 +330,7 @@ class Address ->addViolation(); } } - + /** * @param Address $original * @return Address @@ -286,5 +345,125 @@ class Address ; } + public function getStreet(): ?string + { + return $this->street; + } + + public function setStreet(string $street): self + { + $this->street = $street; + + return $this; + } + + public function getNumber(): ?string + { + return $this->number; + } + + public function setNumber(string $number): self + { + $this->number = $number; + + return $this; + } + + public function getFloor(): ?string + { + return $this->floor; + } + + public function setFloor(?string $floor): self + { + $this->floor = $floor; + + return $this; + } + + public function getCorridor(): ?string + { + return $this->corridor; + } + + public function setCorridor(?string $corridor): self + { + $this->corridor = $corridor; + + return $this; + } + + public function getSteps(): ?string + { + return $this->steps; + } + + public function setSteps(?string $steps): self + { + $this->steps = $steps; + + return $this; + } + + public function getBuildingName(): ?string + { + return $this->buildingName; + } + + public function setBuildingName(?string $buildingName): self + { + $this->buildingName = $buildingName; + + return $this; + } + + public function getFlat(): ?string + { + return $this->flat; + } + + public function setFlat(?string $flat): self + { + $this->flat = $flat; + + return $this; + } + + public function getDistribution(): ?string + { + return $this->distribution; + } + + public function setDistribution(?string $distribution): self + { + $this->distribution = $distribution; + + return $this; + } + + public function getExtra(): ?string + { + return $this->extra; + } + + public function setExtra(?string $extra): self + { + $this->extra = $extra; + + return $this; + } + + public function getValidTo(): ?\DateTimeInterface + { + return $this->validTo; + } + + public function setValidTo(\DateTimeInterface $validTo): self + { + $this->validTo = $validTo; + + return $this; + } + } From 7d1a1c4004b7d4a6a6489be959a89ae3be91ee5c Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 19 Apr 2021 12:12:55 +0200 Subject: [PATCH 03/28] #32 add point type + Address: add Point field + add null on nullable fields --- .../ChillMainExtension.php | 3 +- .../Doctrine/Type/PointType.php | 72 ++++++++++++++ src/Bundle/ChillMainBundle/Entity/Address.php | 23 +++-- src/Bundle/ChillMainBundle/Entity/Point.php | 96 +++++++++++++++++++ .../ChillMainBundle/Entity/PointException.php | 28 ++++++ 5 files changed, 214 insertions(+), 8 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php create mode 100644 src/Bundle/ChillMainBundle/Entity/Point.php create mode 100644 src/Bundle/ChillMainBundle/Entity/PointException.php diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 234e1203d..ee9608d82 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -188,7 +188,8 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, $container->prependExtensionConfig('doctrine', array( 'dbal' => [ 'types' => [ - 'dateinterval' => \Chill\MainBundle\Doctrine\Type\NativeDateIntervalType::class + 'dateinterval' => \Chill\MainBundle\Doctrine\Type\NativeDateIntervalType::class, + 'json' => \Chill\MainBundle\Doctrine\Type\PointType::class ] ] )); diff --git a/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php b/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php new file mode 100644 index 000000000..ba84177ac --- /dev/null +++ b/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php @@ -0,0 +1,72 @@ +toWKT(); + } + + public function canRequireSQLConversion() + { + return true; + } + + public function convertToPHPValueSQL($sqlExpr, $platform) + { + return 'ST_AsGeoJSON('.$sqlExpr.') '; + } + + public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) + { + return $sqlExpr; + } + + + + + +} + diff --git a/src/Bundle/ChillMainBundle/Entity/Address.php b/src/Bundle/ChillMainBundle/Entity/Address.php index 1286ba2e0..6592c6a3d 100644 --- a/src/Bundle/ChillMainBundle/Entity/Address.php +++ b/src/Bundle/ChillMainBundle/Entity/Address.php @@ -45,49 +45,49 @@ class Address private $postcode; /** - * @var string + * @var string|null * * @ORM\Column(type="string", length=16, nullable=true) */ private $floor; /** - * @var string + * @var string|null * * @ORM\Column(type="string", length=16, nullable=true) */ private $corridor; /** - * @var string + * @var string|null * * @ORM\Column(type="string", length=16, nullable=true) */ private $steps; /** - * @var string + * @var string|null * * @ORM\Column(type="string", length=255, nullable=true) */ private $buildingName; /** - * @var string + * @var string|null * * @ORM\Column(type="string", length=16, nullable=true) */ private $flat; /** - * @var string + * @var string|null * * @ORM\Column(type="string", length=255, nullable=true) */ private $distribution; /** - * @var string + * @var string|null * * @ORM\Column(type="string", length=255, nullable=true) */ @@ -120,6 +120,15 @@ class Address */ private $isNoAddress = false; + /** + * A geospatial field storing the coordinates of the Address + * + * @var Point|null + * + * @ORM\Column(type="Point", nullable=true) + */ + private $point; + /** * A list of metadata, added by customizable fields * diff --git a/src/Bundle/ChillMainBundle/Entity/Point.php b/src/Bundle/ChillMainBundle/Entity/Point.php new file mode 100644 index 000000000..528834e42 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/Point.php @@ -0,0 +1,96 @@ +lat = $lat; + $this->lon = $lon; + } + + public function toGeoJson() { + $array = $this->toArrayGeoJson(); + return \json_encode($array); + } + + public function jsonSerialize() { + return $this->toArrayGeoJson(); + } + + public function toArrayGeoJson() { + return array("type" => "Point", + "coordinates" => array ($this->lon, $this->lat)); + } + + /** + * + * @return string + */ + public function toWKT() { + return 'SRID='.self::$SRID.';POINT('.$this->lon.' '.$this->lat.')'; + } + + /** + * + * @param type $geojson + * @return Point + */ + public static function fromGeoJson($geojson) + { + $a = json_decode($geojson); + //check if the geojson string is correct + if ($a == null or !isset($a->type) or !isset($a->coordinates)){ + throw PointException::badJsonString($geojson); + } + + if ($a->type != "Point"){ + throw PointException::badGeoType(); + } else { + $lat = $a->coordinates[1]; + $lon = $a->coordinates[0]; + return Point::fromLonLat($lon, $lat); + } + + } + + public static function fromLonLat($lon, $lat) + { + if (($lon > -180 && $lon < 180) && ($lat > -90 && $lat < 90)) + { + return new Point($lon, $lat); + } else { + throw PointException::badCoordinates($lon, $lat); + } + } + + public static function fromArrayGeoJson($array) + { + if ($array['type'] == 'Point' && + isset($array['coordinates'])) + { + return self::fromLonLat($array['coordinates'][0], $array['coordinates'][1]); + } + } + + public function getLat() + { + return $this->lat; + } + + public function getLon() + { + return $this->lon; + } +} + + diff --git a/src/Bundle/ChillMainBundle/Entity/PointException.php b/src/Bundle/ChillMainBundle/Entity/PointException.php new file mode 100644 index 000000000..ac024eebf --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/PointException.php @@ -0,0 +1,28 @@ + Date: Tue, 20 Apr 2021 10:55:45 +0200 Subject: [PATCH 04/28] add point type + Address: add Point field : fix dependency injection of the Point type --- .../DependencyInjection/ChillMainExtension.php | 8 ++++++-- .../{Entity => Doctrine/Model}/Point.php | 2 +- .../{Entity => Doctrine/Model}/PointException.php | 2 +- .../ChillMainBundle/Doctrine/Type/PointType.php | 4 ++-- src/Bundle/ChillMainBundle/Entity/Address.php | 15 ++++++++++++++- 5 files changed, 24 insertions(+), 7 deletions(-) rename src/Bundle/ChillMainBundle/{Entity => Doctrine/Model}/Point.php (97%) rename src/Bundle/ChillMainBundle/{Entity => Doctrine/Model}/PointException.php (93%) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index ee9608d82..831853611 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -188,8 +188,12 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, $container->prependExtensionConfig('doctrine', array( 'dbal' => [ 'types' => [ - 'dateinterval' => \Chill\MainBundle\Doctrine\Type\NativeDateIntervalType::class, - 'json' => \Chill\MainBundle\Doctrine\Type\PointType::class + 'dateinterval' => [ + 'class' => \Chill\MainBundle\Doctrine\Type\NativeDateIntervalType::class + ], + 'point' => [ + 'class' => \Chill\MainBundle\Doctrine\Type\PointType::class + ] ] ] )); diff --git a/src/Bundle/ChillMainBundle/Entity/Point.php b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php similarity index 97% rename from src/Bundle/ChillMainBundle/Entity/Point.php rename to src/Bundle/ChillMainBundle/Doctrine/Model/Point.php index 528834e42..869c4c3a6 100644 --- a/src/Bundle/ChillMainBundle/Entity/Point.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php @@ -1,6 +1,6 @@ point; + } + + public function setPoint(?Point $point): self + { + $this->point = $point; + + return $this; + } + } From 0b2f29f1e86996bb7a1f7b8614820b08053fb4cb Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 20 Apr 2021 16:12:17 +0200 Subject: [PATCH 05/28] add migration for address --- src/Bundle/ChillMainBundle/Entity/Address.php | 14 +++--- .../migrations/Version20210420115006.php | 50 +++++++++++++++++++ 2 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20210420115006.php diff --git a/src/Bundle/ChillMainBundle/Entity/Address.php b/src/Bundle/ChillMainBundle/Entity/Address.php index 8a8761ca5..43512a5b2 100644 --- a/src/Bundle/ChillMainBundle/Entity/Address.php +++ b/src/Bundle/ChillMainBundle/Entity/Address.php @@ -36,7 +36,7 @@ class Address * * @ORM\Column(type="string", length=255) */ - private $number = ''; + private $streetNumber = ''; /** * @var PostalCode @@ -108,9 +108,9 @@ class Address * Indicates when the address ends. Used to build an history * of address. * - * @var \DateTime + * @var \DateTime|null * - * @ORM\Column(type="date") + * @ORM\Column(type="date", nullable=true) */ private $validTo; @@ -198,7 +198,7 @@ class Address */ public function getStreetAddress2() { - return $this->number; + return $this->streetNumber; } /** @@ -369,12 +369,12 @@ class Address public function getNumber(): ?string { - return $this->number; + return $this->streetNumber; } - public function setNumber(string $number): self + public function setNumber(string $streetNumber): self { - $this->number = $number; + $this->streetNumber = $streetNumber; return $this; } diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210420115006.php b/src/Bundle/ChillMainBundle/migrations/Version20210420115006.php new file mode 100644 index 000000000..79dea4853 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20210420115006.php @@ -0,0 +1,50 @@ +addSql('ALTER TABLE chill_main_address RENAME COLUMN streetaddress1 TO street;'); + $this->addSql('ALTER TABLE chill_main_address RENAME COLUMN streetaddress2 TO streetNumber;'); + $this->addSql('ALTER TABLE chill_main_address ADD floor VARCHAR(16) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_main_address ADD corridor VARCHAR(16) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_main_address ADD steps VARCHAR(16) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_main_address ADD buildingName VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_main_address ADD flat VARCHAR(16) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_main_address ADD distribution VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_main_address ADD extra VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_main_address ADD validTo DATE DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_main_address ADD point geometry(POINT,4326) DEFAULT NULL'); + } + + + public function down(Schema $schema) : void + { + $this->addSql('ALTER TABLE chill_main_address RENAME COLUMN street TO streetaddress1;'); + $this->addSql('ALTER TABLE chill_main_address RENAME COLUMN streetNumber TO streetaddress2;'); + $this->addSql('ALTER TABLE chill_main_address DROP floor'); + $this->addSql('ALTER TABLE chill_main_address DROP corridor'); + $this->addSql('ALTER TABLE chill_main_address DROP steps'); + $this->addSql('ALTER TABLE chill_main_address DROP buildingName'); + $this->addSql('ALTER TABLE chill_main_address DROP flat'); + $this->addSql('ALTER TABLE chill_main_address DROP distribution'); + $this->addSql('ALTER TABLE chill_main_address DROP extra'); + $this->addSql('ALTER TABLE chill_main_address DROP validTo'); + $this->addSql('ALTER TABLE chill_main_address DROP point'); + } +} From c089960707fd92b4f2a26573a33cc0841a598745 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 22 Apr 2021 09:32:46 +0200 Subject: [PATCH 06/28] add type hinting in Point and PointException --- .../ChillMainBundle/Doctrine/Model/Point.php | 31 +++++++++++-------- .../Doctrine/Model/PointException.php | 7 ++--- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php index 869c4c3a6..a69d3282d 100644 --- a/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php @@ -9,25 +9,29 @@ use \JsonSerializable; * */ class Point implements JsonSerializable { - private $lat; - private $lon; - public static $SRID = '4326'; + private float $lat; + private float $lon; + public static string $SRID = '4326'; - private function __construct($lon, $lat) { + private function __construct($lon, $lat) + { $this->lat = $lat; $this->lon = $lon; } - public function toGeoJson() { + public function toGeoJson(): string + { $array = $this->toArrayGeoJson(); return \json_encode($array); } - public function jsonSerialize() { + public function jsonSerialize(): array + { return $this->toArrayGeoJson(); } - public function toArrayGeoJson() { + public function toArrayGeoJson(): array + { return array("type" => "Point", "coordinates" => array ($this->lon, $this->lat)); } @@ -36,7 +40,8 @@ class Point implements JsonSerializable { * * @return string */ - public function toWKT() { + public function toWKT(): string + { return 'SRID='.self::$SRID.';POINT('.$this->lon.' '.$this->lat.')'; } @@ -45,7 +50,7 @@ class Point implements JsonSerializable { * @param type $geojson * @return Point */ - public static function fromGeoJson($geojson) + public static function fromGeoJson($geojson): Point { $a = json_decode($geojson); //check if the geojson string is correct @@ -63,7 +68,7 @@ class Point implements JsonSerializable { } - public static function fromLonLat($lon, $lat) + public static function fromLonLat($lon, $lat): Point { if (($lon > -180 && $lon < 180) && ($lat > -90 && $lat < 90)) { @@ -73,7 +78,7 @@ class Point implements JsonSerializable { } } - public static function fromArrayGeoJson($array) + public static function fromArrayGeoJson($array): Point { if ($array['type'] == 'Point' && isset($array['coordinates'])) @@ -82,12 +87,12 @@ class Point implements JsonSerializable { } } - public function getLat() + public function getLat(): float { return $this->lat; } - public function getLon() + public function getLon(): float { return $this->lon; } diff --git a/src/Bundle/ChillMainBundle/Doctrine/Model/PointException.php b/src/Bundle/ChillMainBundle/Doctrine/Model/PointException.php index 64a3c4c1f..48d6b9aea 100644 --- a/src/Bundle/ChillMainBundle/Doctrine/Model/PointException.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Model/PointException.php @@ -10,18 +10,17 @@ use \Exception; */ class PointException extends Exception { - public static function badCoordinates($lon, $lat) + public static function badCoordinates($lon, $lat): self { return new self("les coordonnées fournies sont invalides dans le système de projection utilisé (longitude = $lon , latitude = $lat)"); } - public static function badJsonString($str) + public static function badJsonString($str): self { return new self("la chaine JSON n'est pas valide : $str"); - } - public static function badGeoType() + public static function badGeoType(): self { return new self("le type de l'objet GeoJSON est invalide"); } From 7c99f0b3e0a3bfb4b7455c8b270b37b7867bfe72 Mon Sep 17 00:00:00 2001 From: juminet Date: Thu, 22 Apr 2021 07:41:36 +0000 Subject: [PATCH 07/28] array synatx: array() -> [] --- src/Bundle/ChillMainBundle/Doctrine/Model/Point.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php index a69d3282d..3ef5fe768 100644 --- a/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php @@ -32,8 +32,10 @@ class Point implements JsonSerializable { public function toArrayGeoJson(): array { - return array("type" => "Point", - "coordinates" => array ($this->lon, $this->lat)); + return [ + "type" => "Point", + "coordinates" => [ $this->lon, $this->lat ] + ]; } /** From e90ea3168367c8f3e2ba0e3f73f51a8024da808d Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 22 Apr 2021 09:45:12 +0200 Subject: [PATCH 08/28] add type hinting in Point and PointException --- src/Bundle/ChillMainBundle/Doctrine/Model/Point.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php index 3ef5fe768..d987637ce 100644 --- a/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php @@ -13,7 +13,7 @@ class Point implements JsonSerializable { private float $lon; public static string $SRID = '4326'; - private function __construct($lon, $lat) + private function __construct(float $lon, float $lat) { $this->lat = $lat; $this->lon = $lon; @@ -52,7 +52,7 @@ class Point implements JsonSerializable { * @param type $geojson * @return Point */ - public static function fromGeoJson($geojson): Point + public static function fromGeoJson(string $geojson): Point { $a = json_decode($geojson); //check if the geojson string is correct @@ -70,7 +70,7 @@ class Point implements JsonSerializable { } - public static function fromLonLat($lon, $lat): Point + public static function fromLonLat(float $lon, float $lat): Point { if (($lon > -180 && $lon < 180) && ($lat > -90 && $lat < 90)) { @@ -80,7 +80,7 @@ class Point implements JsonSerializable { } } - public static function fromArrayGeoJson($array): Point + public static function fromArrayGeoJson(array $array): Point { if ($array['type'] == 'Point' && isset($array['coordinates'])) From bc4e29141b1535bdf631bb9d7a6f2e04504b51f1 Mon Sep 17 00:00:00 2001 From: juminet Date: Thu, 22 Apr 2021 07:46:22 +0000 Subject: [PATCH 09/28] syntax (null -> NULL and == -> ===) --- src/Bundle/ChillMainBundle/Doctrine/Model/Point.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php index d987637ce..67cf434c0 100644 --- a/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php @@ -56,7 +56,7 @@ class Point implements JsonSerializable { { $a = json_decode($geojson); //check if the geojson string is correct - if ($a == null or !isset($a->type) or !isset($a->coordinates)){ + if (NULL === $a or !isset($a->type) or !isset($a->coordinates)){ throw PointException::badJsonString($geojson); } From 1ec2fbcc161c942a51bb67c8dd57f8e6cbe89610 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 22 Apr 2021 09:49:02 +0200 Subject: [PATCH 10/28] translated exception messages in English --- .../ChillMainBundle/Doctrine/Model/PointException.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Doctrine/Model/PointException.php b/src/Bundle/ChillMainBundle/Doctrine/Model/PointException.php index 48d6b9aea..4e3101435 100644 --- a/src/Bundle/ChillMainBundle/Doctrine/Model/PointException.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Model/PointException.php @@ -12,16 +12,16 @@ class PointException extends Exception { public static function badCoordinates($lon, $lat): self { - return new self("les coordonnées fournies sont invalides dans le système de projection utilisé (longitude = $lon , latitude = $lat)"); + return new self("Input coordinates are not valid in the used coordinate system (longitude = $lon , latitude = $lat)"); } public static function badJsonString($str): self { - return new self("la chaine JSON n'est pas valide : $str"); + return new self("The JSON string is not valid: $str"); } public static function badGeoType(): self { - return new self("le type de l'objet GeoJSON est invalide"); + return new self("The geoJSON object type is not valid"); } } From 8c33d876e80f61a23c3d2c6f46a7710a3749162b Mon Sep 17 00:00:00 2001 From: juminet Date: Thu, 22 Apr 2021 07:53:05 +0000 Subject: [PATCH 11/28] code formatting in PointType --- src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php b/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php index eab3261dd..6b6f7c113 100644 --- a/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php @@ -63,10 +63,5 @@ class PointType extends Type { { return $sqlExpr; } - - - - - } From 69a3c6a9b2bcf7fdfbb5e85eb787c4e52bcaf0b9 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 22 Apr 2021 09:59:46 +0200 Subject: [PATCH 12/28] refine the migration comment --- src/Bundle/ChillMainBundle/migrations/Version20210414091001.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210414091001.php b/src/Bundle/ChillMainBundle/migrations/Version20210414091001.php index 7881d9558..db207c594 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20210414091001.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20210414091001.php @@ -6,7 +6,7 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; /** - * Auto-generated Migration: Please modify to your needs! + * Create the postgis extension */ final class Version20210414091001 extends AbstractMigration { From a709b3afb60255ec36aca890d4101e0465e71f6e Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 22 Apr 2021 12:25:34 +0200 Subject: [PATCH 13/28] add addressReference in Chill Main + migration --- .../Entity/AddressReference.php | 147 ++++++++++++++++++ .../Repository/AddressReferenceRepository.php | 50 ++++++ .../migrations/Version20210422101743.php | 33 ++++ 3 files changed, 230 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Entity/AddressReference.php create mode 100644 src/Bundle/ChillMainBundle/Repository/AddressReferenceRepository.php create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20210422101743.php diff --git a/src/Bundle/ChillMainBundle/Entity/AddressReference.php b/src/Bundle/ChillMainBundle/Entity/AddressReference.php new file mode 100644 index 000000000..8f1678425 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/AddressReference.php @@ -0,0 +1,147 @@ +id; + } + + public function getRefId(): ?string + { + return $this->refId; + } + + public function setRefId(string $refId): self + { + $this->refId = $refId; + + return $this; + } + + public function getStreet(): ?string + { + return $this->street; + } + + public function setStreet(?string $street): self + { + $this->street = $street; + + return $this; + } + + public function getStreetNumber(): ?string + { + return $this->streetNumber; + } + + public function setStreetNumber(?string $streetNumber): self + { + $this->streetNumber = $streetNumber; + + return $this; + } + + public function getPostcode(): ?string + { + return $this->postcode; + } + + public function setPostcode(?string $postcode): self + { + $this->postcode = $postcode; + + return $this; + } + + public function getMunicipalityCode(): ?string + { + return $this->municipalityCode; + } + + public function setMunicipalityCode(?string $municipalityCode): self + { + $this->municipalityCode = $municipalityCode; + + return $this; + } + + public function getSource(): ?string + { + return $this->source; + } + + public function setSource(?string $source): self + { + $this->source = $source; + + return $this; + } + + public function getPoint(): ?string + { + return $this->point; + } + + public function setPoint(string $point): self + { + $this->point = $point; + + return $this; + } +} diff --git a/src/Bundle/ChillMainBundle/Repository/AddressReferenceRepository.php b/src/Bundle/ChillMainBundle/Repository/AddressReferenceRepository.php new file mode 100644 index 000000000..208151420 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Repository/AddressReferenceRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('a.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?AddressReference + { + return $this->createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210422101743.php b/src/Bundle/ChillMainBundle/migrations/Version20210422101743.php new file mode 100644 index 000000000..2d4341155 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20210422101743.php @@ -0,0 +1,33 @@ +addSql('CREATE SEQUENCE chill_main_address_reference_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE chill_main_address_reference (id INT NOT NULL, postcode_id INT DEFAULT NULL, refId VARCHAR(255) NOT NULL, street VARCHAR(255) DEFAULT NULL, streetNumber VARCHAR(255) DEFAULT NULL, municipalityCode VARCHAR(255) DEFAULT NULL, source VARCHAR(255) DEFAULT NULL, point VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_CA6C1BD7EECBFDF1 ON chill_main_address_reference (postcode_id)'); + $this->addSql('ALTER TABLE chill_main_address_reference ADD CONSTRAINT FK_CA6C1BD7EECBFDF1 FOREIGN KEY (postcode_id) REFERENCES chill_main_postal_code (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema) : void + { + $this->addSql('DROP SEQUENCE chill_main_address_reference_id_seq CASCADE'); + $this->addSql('DROP TABLE chill_main_address_reference'); + } +} From ebff36d2571347fca776cdf704b090d559583cac Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 23 Apr 2021 15:13:04 +0200 Subject: [PATCH 14/28] add unit test for class Point --- .../Tests/Doctrine/Model/PointTest.php | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Tests/Doctrine/Model/PointTest.php diff --git a/src/Bundle/ChillMainBundle/Tests/Doctrine/Model/PointTest.php b/src/Bundle/ChillMainBundle/Tests/Doctrine/Model/PointTest.php new file mode 100644 index 000000000..5632bf96a --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Doctrine/Model/PointTest.php @@ -0,0 +1,119 @@ + + */ +class ExportControllerTest extends KernelTestCase +{ + + public function testToWKT() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat); + + $this->assertEquals($point->toWKT(),'SRID=4326;POINT(4.8634 50.47382)'); + } + + public function testToGeojson() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat); + + $this->assertEquals($point->toGeoJson(),'{"type":"Point","coordinates":[4.8634,50.47382]}'); + } + + public function testToArrayGeoJson() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat); + + $this->assertEquals( + $point->toArrayGeoJson(), + [ + 'type' => 'Point', + 'coordinates' => [4.8634, 50.47382] + ] + ); + } + + public function testJsonSerialize() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat); + + $this->assertEquals( + $point->jsonSerialize(), + [ + 'type' => 'Point', + 'coordinates' => [4.8634, 50.47382] + ] + ); + } + + public function testFromGeoJson() + { + $geojson = '{"type":"Point","coordinates":[4.8634,50.47382]}'; + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat);; + + $this->assertEquals($point, Point::fromGeoJson($geojson)); + } + + public function testFromLonLat() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat);; + + $this->assertEquals($point, Point::fromLonLat($lon, $lat)); + } + + public function testFromArrayGeoJson() + { + $array = [ + 'type' => 'Point', + 'coordinates' => [4.8634, 50.47382] + ]; + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat);; + + $this->assertEquals($point, Point::fromArrayGeoJson($array)); + } + + public function testGetLat() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat);; + + $this->assertEquals($lat, $point->getLat()); + } + + public function testGetLon() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat);; + + $this->assertEquals($lon, $point->getLon()); + } + + private function preparePoint($lon, $lat) + { + return Point::fromLonLat($lon, $lat); + } + +} From 05d3d7f5c71b102f599f2273fa708932e2a6f3cf Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 23 Apr 2021 16:48:27 +0200 Subject: [PATCH 15/28] update twig template and AddressType following the changes in Address entity --- src/Bundle/ChillMainBundle/Entity/Address.php | 4 ++-- .../ChillMainBundle/Form/Type/AddressType.php | 16 +++++++------- .../Resources/views/Address/macro.html.twig | 4 ++-- .../Resources/views/Address/edit.html.twig | 18 +++++++-------- .../Resources/views/Address/new.html.twig | 22 +++++++++---------- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Address.php b/src/Bundle/ChillMainBundle/Entity/Address.php index 43512a5b2..e01c3f540 100644 --- a/src/Bundle/ChillMainBundle/Entity/Address.php +++ b/src/Bundle/ChillMainBundle/Entity/Address.php @@ -367,12 +367,12 @@ class Address return $this; } - public function getNumber(): ?string + public function getStreetNumber(): ?string { return $this->streetNumber; } - public function setNumber(string $streetNumber): self + public function setStreetNumber(string $streetNumber): self { $this->streetNumber = $streetNumber; diff --git a/src/Bundle/ChillMainBundle/Form/Type/AddressType.php b/src/Bundle/ChillMainBundle/Form/Type/AddressType.php index 4a0e222b8..68cfdda09 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/AddressType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/AddressType.php @@ -33,8 +33,8 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; * A type to create/update Address entity * * Options: - * - * - `has_valid_from` (boolean): show if an entry "has valid from" must be + * + * - `has_valid_from` (boolean): show if an entry "has valid from" must be * shown. * - `null_if_empty` (boolean): replace the address type by null if the street * or the postCode is empty. This is useful when the address is not required and @@ -45,10 +45,10 @@ class AddressType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('streetAddress1', TextType::class, array( + ->add('street', TextType::class, array( 'required' => !$options['has_no_address'] // true if has no address is false )) - ->add('streetAddress2', TextType::class, array( + ->add('streetNumber', TextType::class, array( 'required' => false )) ->add('postCode', PostalCodeType::class, array( @@ -57,7 +57,7 @@ class AddressType extends AbstractType 'required' => !$options['has_no_address'] // true if has no address is false )) ; - + if ($options['has_valid_from']) { $builder ->add('validFrom', DateType::class, array( @@ -67,7 +67,7 @@ class AddressType extends AbstractType ) ); } - + if ($options['has_no_address']) { $builder ->add('isNoAddress', ChoiceType::class, [ @@ -79,12 +79,12 @@ class AddressType extends AbstractType 'label' => 'address.address_homeless' ]); } - + if ($options['null_if_empty'] === TRUE) { $builder->setDataMapper(new AddressDataMapper()); } } - + public function configureOptions(OptionsResolver $resolver) { $resolver diff --git a/src/Bundle/ChillMainBundle/Resources/views/Address/macro.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Address/macro.html.twig index 165d7c280..5de175169 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Address/macro.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Address/macro.html.twig @@ -6,8 +6,8 @@
{{ 'address.consider homeless'|trans }}
{% endif %}
- {% if address.streetAddress1 is not empty %}

{{ address.streetAddress1 }}

{% endif %} - {% if address.streetAddress2 is not empty %}

{{ address.streetAddress2 }}

{% endif %} + {% if address.street is not empty %}

{{ address.street }}

{% endif %} + {% if address.streetNumber is not empty %}

{{ address.streetNumber }}

{% endif %} {% if address.postCode is not empty %}

{{ address.postCode.code }} {{ address.postCode.name }}

{{ address.postCode.country.name|localize_translatable_string }}

diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Address/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Address/edit.html.twig index eea76b5fe..b516dfb83 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Address/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Address/edit.html.twig @@ -21,17 +21,17 @@ {% block title 'Update address for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) %} {% block personcontent %} - +

{{ 'Update address for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}

- + {{ form_start(form) }} - + {{ form_row(form.isNoAddress) }} - {{ form_row(form.streetAddress1) }} - {{ form_row(form.streetAddress2) }} + {{ form_row(form.street) }} + {{ form_row(form.streetNumber) }} {{ form_row(form.postCode) }} {{ form_row(form.validFrom) }} - + - + {{ form_end(form) }} - -{% endblock personcontent %} \ No newline at end of file + +{% endblock personcontent %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Address/new.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Address/new.html.twig index 9e94d7804..70cc51e53 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Address/new.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Address/new.html.twig @@ -21,21 +21,21 @@ {% block title %}{{ 'New address for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %} {% block personcontent %} - +

{{ 'New address for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}

- + {{ form_start(form) }} - + {{ form_row(form.isNoAddress) }} - {{ form_row(form.streetAddress1) }} - {{ form_errors(form.streetAddress1) }} - {{ form_row(form.streetAddress2) }} - {{ form_errors(form.streetAddress2) }} + {{ form_row(form.street) }} + {{ form_errors(form.street) }} + {{ form_row(form.streetNumber) }} + {{ form_errors(form.streetNumber) }} {{ form_row(form.postCode) }} {{ form_errors(form.postCode) }} {{ form_row(form.validFrom) }} {{ form_errors(form.validFrom) }} - +
- + {{ form_end(form) }} - -{% endblock personcontent %} \ No newline at end of file + +{% endblock personcontent %} From bec0700d396fe5e8934cb12dd87c2c3a23d4ec3d Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 30 Apr 2021 13:27:33 +0200 Subject: [PATCH 16/28] Point model: better handling of exception --- src/Bundle/ChillMainBundle/Doctrine/Model/Point.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php index 67cf434c0..43c21ae59 100644 --- a/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Model/Point.php @@ -60,14 +60,14 @@ class Point implements JsonSerializable { throw PointException::badJsonString($geojson); } - if ($a->type != "Point"){ + if ($a->type != 'Point'){ throw PointException::badGeoType(); - } else { - $lat = $a->coordinates[1]; - $lon = $a->coordinates[0]; - return Point::fromLonLat($lon, $lat); } + $lat = $a->coordinates[1]; + $lon = $a->coordinates[0]; + + return Point::fromLonLat($lon, $lat); } public static function fromLonLat(float $lon, float $lat): Point From 91860afd8036150b977d72a55a4cf36c88c2a768 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 30 Apr 2021 13:51:45 +0200 Subject: [PATCH 17/28] check if point value is null for 2 methods in PointType --- .../ChillMainBundle/Doctrine/Type/PointType.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php b/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php index 6b6f7c113..086b566da 100644 --- a/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php +++ b/src/Bundle/ChillMainBundle/Doctrine/Type/PointType.php @@ -36,7 +36,11 @@ class PointType extends Type { */ public function convertToPHPValue($value, AbstractPlatform $platform) { - return Point::fromGeoJson($value); + if ($value === NULL){ + return NULL; + } else { + return Point::fromGeoJson($value); + } } public function getName() @@ -46,7 +50,11 @@ class PointType extends Type { public function convertToDatabaseValue($value, AbstractPlatform $platform) { - return $value->toWKT(); + if ($value === NULL){ + return NULL; + } else { + return $value->toWKT(); + } } public function canRequireSQLConversion() From e9d142f3e8c9ae0d375467c170e20a308762c552 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 30 Apr 2021 14:15:20 +0200 Subject: [PATCH 18/28] define legacy functions for Address --- src/Bundle/ChillMainBundle/Entity/Address.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Address.php b/src/Bundle/ChillMainBundle/Entity/Address.php index e01c3f540..9e9022e31 100644 --- a/src/Bundle/ChillMainBundle/Entity/Address.php +++ b/src/Bundle/ChillMainBundle/Entity/Address.php @@ -154,7 +154,7 @@ class Address } /** - * Set streetAddress1 + * Set streetAddress1 (legacy function) * * @param string $streetAddress1 * @@ -162,13 +162,13 @@ class Address */ public function setStreetAddress1($streetAddress1) { - $this->streetAddress1 = $streetAddress1 === NULL ? '' : $streetAddress1; + $this->street = $streetAddress1 === NULL ? '' : $streetAddress1; return $this; } /** - * Get streetAddress1 + * Get streetAddress1 (legacy function) * * @return string */ @@ -178,7 +178,7 @@ class Address } /** - * Set streetAddress2 + * Set streetAddress2 (legacy function) * * @param string $streetAddress2 * @@ -186,13 +186,13 @@ class Address */ public function setStreetAddress2($streetAddress2) { - $this->streetAddress2 = $streetAddress2 === NULL ? '' : $streetAddress2; + $this->streetNumber = $streetAddress2 === NULL ? '' : $streetAddress2; return $this; } /** - * Get streetAddress2 + * Get streetAddress2 (legacy function) * * @return string */ From c5faa0b99d1c4d9440f19f54e2e136a409ee23c8 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 30 Apr 2021 15:15:47 +0200 Subject: [PATCH 19/28] update the address fixture by adding some points --- .../DataFixtures/ORM/LoadPeople.php | 122 ++++++++++-------- 1 file changed, 71 insertions(+), 51 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php index fa20d3457..e8697ff28 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php @@ -29,6 +29,7 @@ use Chill\PersonBundle\Entity\Person; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes; use Chill\MainBundle\Entity\Address; +use Chill\MainBundle\Doctrine\Model\Point; /** * Load people into database @@ -37,17 +38,17 @@ use Chill\MainBundle\Entity\Address; * @author Marc Ducobu */ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface -{ - +{ + use \Symfony\Component\DependencyInjection\ContainerAwareTrait; - + protected $faker; - + public function __construct() { $this->faker = \Faker\Factory::create('fr_FR'); } - + public function prepare() { //prepare days, month, years @@ -56,57 +57,57 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con $this->years[] = $y; $y = $y +1; } while ($y >= 1990); - + $m = 1; do { $this->month[] = $m; $m = $m +1; } while ($m >= 12); - + $d = 1; do { $this->day[] = $d; $d = $d + 1; } while ($d <= 28); } - + public function getOrder() { return 10000; } - + public function load(ObjectManager $manager) { $this->loadRandPeople($manager); $this->loadExpectedPeople($manager); - + $manager->flush(); } - + public function loadExpectedPeople(ObjectManager $manager) { echo "loading expected people...\n"; - + foreach ($this->peoples as $person) { $this->addAPerson($this->fillWithDefault($person), $manager); } } - + public function loadRandPeople(ObjectManager $manager) { echo "loading rand people...\n"; - + $this->prepare(); - + $chooseLastNameOrTri = array('tri', 'tri', 'name', 'tri'); - + $i = 0; - + do { $i++; - + $sex = $this->genders[array_rand($this->genders)]; - + if ($chooseLastNameOrTri[array_rand($chooseLastNameOrTri)] === 'tri' ) { $length = rand(2, 3); $lastName = ''; @@ -117,13 +118,13 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con } else { $lastName = $this->lastNames[array_rand($this->lastNames)]; } - + if ($sex === Person::MALE_GENDER) { $firstName = $this->firstNamesMale[array_rand($this->firstNamesMale)]; } else { $firstName = $this->firstNamesFemale[array_rand($this->firstNamesFemale)]; } - + // add an address on 80% of the created people if (rand(0,100) < 80) { $address = $this->getRandomAddress(); @@ -137,7 +138,7 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con } else { $address = null; } - + $person = array( 'FirstName' => $firstName, 'LastName' => $lastName, @@ -147,15 +148,15 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con 'Address' => $address, 'maritalStatus' => $this->maritalStatusRef[array_rand($this->maritalStatusRef)] ); - + $this->addAPerson($this->fillWithDefault($person), $manager); - + } while ($i <= 100); } - + /** * fill a person array with default value - * + * * @param string[] $specific */ private function fillWithDefault(array $specific) @@ -171,10 +172,10 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con 'Address' => null ), $specific); } - + /** * create a new person from array data - * + * * @param array $person * @param ObjectManager $manager * @throws \Exception @@ -200,35 +201,51 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con $this->addAccompanyingPeriods($p, $value, $manager); break; } - + //try to add the data using the setSomething function, // if not possible, fallback to addSomething function if (method_exists($p, 'set'.$key)) { call_user_func(array($p, 'set'.$key), $value); } elseif (method_exists($p, 'add'.$key)) { // if we have a "addSomething", we may have multiple items to add - // so, we set the value in an array if it is not an array, and + // so, we set the value in an array if it is not an array, and // will call the function addSomething multiple times if (!is_array($value)) { $value = array($value); } - + foreach($value as $v) { if ($v !== NULL) { call_user_func(array($p, 'add'.$key), $v); } } - - } + + } } $manager->persist($p); echo "add person'".$p->__toString()."'\n"; } - + + /** - * Creata a random address - * + * Create a random point + * + * @return Point + */ + private function getRandomPoint() + { + $lonBrussels = 4.35243; + $latBrussels = 50.84676; + $lon = $lonBrussels + 0.01 * rand(-5, 5); + $lat = $latBrussels + 0.01 * rand(-5, 5); + return Point::fromLonLat($lon, $lat); + } + + + /** + * Create a random address + * * @return Address */ private function getRandomAddress() @@ -238,13 +255,16 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con ->setStreetAddress2( rand(0,9) > 5 ? $this->faker->streetAddress : '' ) + ->setPoint( + rand(0,9) > 5 ? $this->getRandomPoint() : NULL + ) ->setPostcode($this->getReference( LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)] )) ->setValidFrom($this->faker->dateTimeBetween('-5 years')) ; } - + private function getCountry($countryCode) { if ($countryCode === NULL) { @@ -257,30 +277,30 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con private $maritalStatusRef = ['ms_single', 'ms_married', 'ms_widow', 'ms_separat', 'ms_divorce', 'ms_legalco', 'ms_unknown']; - + private $firstNamesMale = array("Jean", "Mohamed", "Alfred", "Robert", "Justin", "Brian", "Compère", "Jean-de-Dieu", "Charles", "Pierre", "Luc", "Mathieu", "Alain", "Etienne", "Eric", "Corentin", "Gaston", "Spirou", "Fantasio", "Mahmadou", "Mohamidou", "Vursuv", "Youssef" ); - + private $firstNamesFemale = array("Svedana", "Sevlatina", "Irène", "Marcelle", "Corentine", "Alfonsine", "Caroline", "Solange", "Gostine", "Fatoumata", "Nicole", "Groseille", "Chana", "Oxana", "Ivana", "Julie", "Tina", "Adèle" ); - + private $lastNames = array("Diallo", "Bah", "Gaillot", "Martin"); - + private $lastNamesTrigrams = array("fas", "tré", "hu", 'blart', 'van', 'der', 'lin', 'den', 'ta', 'mi', 'net', 'gna', 'bol', 'sac', 'ré', 'jo', 'du', 'pont', 'cas', 'tor', 'rob', 'al', 'ma', 'gone', 'car',"fu", "ka", "lot", "no", "va", "du", "bu", "su", "jau", "tte", 'sir', "lo", 'to', "cho", "car", 'mo','zu', 'qi', 'mu'); - + private $genders = array(Person::MALE_GENDER, Person::FEMALE_GENDER); - + private $years = array(); - + private $month = array(); - + private $day = array(); - + private $peoples = array( array( 'LastName' => "Depardieu", @@ -362,21 +382,21 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con 'maritalStatus' => 'ms_legalco' ), ); - - + + private function addAccompanyingPeriods(Person $person, array $periods, ObjectManager $manager) { foreach ($periods as $period) { - + echo "adding new past Accompanying Period..\n"; - + /** @var AccompanyingPeriod $accompanyingPeriod */ $accompanyingPeriod = new AccompanyingPeriod(new \DateTime($period['from'])); $accompanyingPeriod ->setClosingDate(new \DateTime($period['to'])) ->setRemark($period['remark']) ; - + $person->addAccompanyingPeriod($accompanyingPeriod); } } From a1895ec65f7967d2b9560aa0f275041e2cfecf73 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 3 May 2021 11:18:31 +0200 Subject: [PATCH 20/28] fixture for addressReference - WIP --- .../Controller/AddressReferenceController.php | 49 ++++++++++ .../ORM/LoadAddressReferences.php | 96 +++++++++++++++++++ .../Entity/AddressReference.php | 12 ++- ...22101743.php => Version20210503085107.php} | 12 +-- 4 files changed, 160 insertions(+), 9 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Controller/AddressReferenceController.php create mode 100644 src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php rename src/Bundle/ChillMainBundle/migrations/{Version20210422101743.php => Version20210503085107.php} (75%) diff --git a/src/Bundle/ChillMainBundle/Controller/AddressReferenceController.php b/src/Bundle/ChillMainBundle/Controller/AddressReferenceController.php new file mode 100644 index 000000000..f505de235 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/AddressReferenceController.php @@ -0,0 +1,49 @@ +dispatcher->dispatch( + AccompanyingPeriodPrivacyEvent::ACCOMPANYING_PERIOD_PRIVACY_EVENT, + new AccompanyingPeriodPrivacyEvent($addressReference, [ + 'action' => 'showApi' + ]) + ); + + switch ($_format) { + case 'json': + return $this->json($addressReference); + default: + throw new BadRequestException('Unsupported format'); + } + + } +} diff --git a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php new file mode 100644 index 000000000..a546210ce --- /dev/null +++ b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php @@ -0,0 +1,96 @@ +faker = \Faker\Factory::create('fr_FR'); + } + + /** + * + * @var ContainerInterface + */ + private $container; + + public function setContainer(ContainerInterface $container = null) + { + $this->container = $container; + } + + public function getOrder() { + return 30; + } + + + /** + * Create a random point + * + * @return Point + */ + private function getRandomPoint() + { + $lonBrussels = 4.35243; + $latBrussels = 50.84676; + $lon = $lonBrussels + 0.01 * rand(-5, 5); + $lat = $latBrussels + 0.01 * rand(-5, 5); + return Point::fromLonLat($lon, $lat); + } + + /** + * Create a random reference address + * + * @return AddressReference + */ + private function getRandomAddressReference() + { + $ar= new AddressReference(); + + $ar->setRefId($this->faker->phoneNumber); + $ar->setStreet($this->faker->streetAddress); + $ar->setStreetNumber(rand(0,199)); + $ar ->setPoint($this->getRandomPoint()); + $ar->setPostcode($this->getReference( + LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)] + )); + + $ar->setMunicipalityCode($ar->getPostcode()); + dump($ar); + + return $ar + ; + } + + public function load(ObjectManager $manager) { + + echo "loading some reference address... \n"; + + for ($i=0; $i<10; $i++) { + $ar = $this->getRandomAddressReference(); + $manager->persist($ar); + } + + $manager->flush(); + } + + +} diff --git a/src/Bundle/ChillMainBundle/Entity/AddressReference.php b/src/Bundle/ChillMainBundle/Entity/AddressReference.php index 8f1678425..d7a0e0156 100644 --- a/src/Bundle/ChillMainBundle/Entity/AddressReference.php +++ b/src/Bundle/ChillMainBundle/Entity/AddressReference.php @@ -4,6 +4,7 @@ namespace Chill\MainBundle\Entity; use Chill\MainBundle\Entity\AddressReferenceRepository; use Doctrine\ORM\Mapping as ORM; +use Chill\MainBundle\Doctrine\Model\Point; /** * @ORM\Entity(repositoryClass=AddressReferenceRepository::class) @@ -52,10 +53,15 @@ class AddressReference private $source; /** - * @ORM\Column(type="string", length=255) + * A geospatial field storing the coordinates of the Address + * + * @var Point + * + * @ORM\Column(type="point") */ private $point; + public function getId(): ?int { return $this->id; @@ -133,12 +139,12 @@ class AddressReference return $this; } - public function getPoint(): ?string + public function getPoint(): ?Point { return $this->point; } - public function setPoint(string $point): self + public function setPoint(?Point $point): self { $this->point = $point; diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210422101743.php b/src/Bundle/ChillMainBundle/migrations/Version20210503085107.php similarity index 75% rename from src/Bundle/ChillMainBundle/migrations/Version20210422101743.php rename to src/Bundle/ChillMainBundle/migrations/Version20210503085107.php index 2d4341155..f693777a0 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20210422101743.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20210503085107.php @@ -8,24 +8,24 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; /** - * Add AddressReference + * Add a AddressReference table for storing authoritative address data */ -final class Version20210422101743 extends AbstractMigration +final class Version20210503085107 extends AbstractMigration { - public function getDescription() : string + public function getDescription(): string { return 'Add a AddressReference table for storing authoritative address data'; } - public function up(Schema $schema) : void + public function up(Schema $schema): void { $this->addSql('CREATE SEQUENCE chill_main_address_reference_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE chill_main_address_reference (id INT NOT NULL, postcode_id INT DEFAULT NULL, refId VARCHAR(255) NOT NULL, street VARCHAR(255) DEFAULT NULL, streetNumber VARCHAR(255) DEFAULT NULL, municipalityCode VARCHAR(255) DEFAULT NULL, source VARCHAR(255) DEFAULT NULL, point VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE chill_main_address_reference (id INT NOT NULL, postcode_id INT DEFAULT NULL, refId VARCHAR(255) NOT NULL, street VARCHAR(255) DEFAULT NULL, streetNumber VARCHAR(255) DEFAULT NULL, municipalityCode VARCHAR(255) DEFAULT NULL, source VARCHAR(255) DEFAULT NULL, point geometry(POINT,4326) NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_CA6C1BD7EECBFDF1 ON chill_main_address_reference (postcode_id)'); $this->addSql('ALTER TABLE chill_main_address_reference ADD CONSTRAINT FK_CA6C1BD7EECBFDF1 FOREIGN KEY (postcode_id) REFERENCES chill_main_postal_code (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); } - public function down(Schema $schema) : void + public function down(Schema $schema): void { $this->addSql('DROP SEQUENCE chill_main_address_reference_id_seq CASCADE'); $this->addSql('DROP TABLE chill_main_address_reference'); From 17c01d9b463e6d2ae6310ab945547b2f000f9842 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 3 May 2021 12:18:21 +0200 Subject: [PATCH 21/28] fix fixture for address reference --- .../ORM/LoadAddressReferences.php | 5 ++-- .../Entity/AddressReference.php | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php index a546210ce..63de2eb21 100644 --- a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php +++ b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php @@ -38,7 +38,7 @@ class LoadAddressReferences extends AbstractFixture implements ContainerAwareInt } public function getOrder() { - return 30; + return 51; } @@ -73,8 +73,7 @@ class LoadAddressReferences extends AbstractFixture implements ContainerAwareInt LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)] )); - $ar->setMunicipalityCode($ar->getPostcode()); - dump($ar); + $ar->setMunicipalityCode($ar->getPostcode()->getCode()); return $ar ; diff --git a/src/Bundle/ChillMainBundle/Entity/AddressReference.php b/src/Bundle/ChillMainBundle/Entity/AddressReference.php index d7a0e0156..944cab81b 100644 --- a/src/Bundle/ChillMainBundle/Entity/AddressReference.php +++ b/src/Bundle/ChillMainBundle/Entity/AddressReference.php @@ -103,18 +103,30 @@ class AddressReference return $this; } - public function getPostcode(): ?string - { - return $this->postcode; - } - - public function setPostcode(?string $postcode): self + /** + * Set postcode + * + * @param PostalCode $postcode + * + * @return Address + */ + public function setPostcode(PostalCode $postcode = null) { $this->postcode = $postcode; return $this; } + /** + * Get postcode + * + * @return PostalCode + */ + public function getPostcode() + { + return $this->postcode; + } + public function getMunicipalityCode(): ?string { return $this->municipalityCode; From 1587c762f89215d139cdf93ef74003b9e9d5be68 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 3 May 2021 14:34:23 +0200 Subject: [PATCH 22/28] better fixture for AddressReference --- .../DataFixtures/ORM/LoadAddressReferences.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php index 63de2eb21..81bd1d909 100644 --- a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php +++ b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAddressReferences.php @@ -65,8 +65,8 @@ class LoadAddressReferences extends AbstractFixture implements ContainerAwareInt { $ar= new AddressReference(); - $ar->setRefId($this->faker->phoneNumber); - $ar->setStreet($this->faker->streetAddress); + $ar->setRefId($this->faker->numerify('ref-id-######')); + $ar->setStreet($this->faker->streetName); $ar->setStreetNumber(rand(0,199)); $ar ->setPoint($this->getRandomPoint()); $ar->setPostcode($this->getReference( From ce859697b50798ab5d5e296b9cedf125a36d8009 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 3 May 2021 17:16:45 +0200 Subject: [PATCH 23/28] Use json endpoint for showing address with Vuejs Components (WIP) --- ...ceController.php => AddressController.php} | 42 +++++++---- .../Resources/public/js/Address/App.vue | 43 ++++++++++++ .../Address/components/AccompanyingCourse.vue | 26 +++++++ .../js/Address/components/PersonItem.vue | 25 +++++++ .../Address/components/PersonsAssociated.vue | 69 +++++++++++++++++++ .../js/Address/components/Requestor.vue | 16 +++++ .../Resources/public/js/Address/index.js | 8 +++ .../Resources/public/js/Address/store/.keep | 0 .../Resources/views/Address/list.html.twig | 30 ++++++-- .../ChillPersonBundle/chill.webpack.config.js | 4 +- 10 files changed, 241 insertions(+), 22 deletions(-) rename src/Bundle/ChillMainBundle/Controller/{AddressReferenceController.php => AddressController.php} (52%) create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/App.vue create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/AccompanyingCourse.vue create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonItem.vue create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonsAssociated.vue create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/Requestor.vue create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/index.js create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/store/.keep diff --git a/src/Bundle/ChillMainBundle/Controller/AddressReferenceController.php b/src/Bundle/ChillMainBundle/Controller/AddressController.php similarity index 52% rename from src/Bundle/ChillMainBundle/Controller/AddressReferenceController.php rename to src/Bundle/ChillMainBundle/Controller/AddressController.php index f505de235..1aeb39062 100644 --- a/src/Bundle/ChillMainBundle/Controller/AddressReferenceController.php +++ b/src/Bundle/ChillMainBundle/Controller/AddressController.php @@ -7,17 +7,39 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\Routing\Annotation\Route; +use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\AddressReference; - /** - * Class AccompanyingCourseController + * Class AddressController * - * @package Chill\PersonBundle\Controller + * @package Chill\MainBundle\Controller */ -class AddressReferenceController extends AbstractController +class AddressController extends AbstractController { + + /** + * Get API Data for showing endpoint + * + * @Route( + * "/{_locale}/main/api/1.0/address/{address_id}/show.{_format}", + * name="chill_main_address_api_show" + * ) + * @ParamConverter("address", options={"id": "address_id"}) + */ + public function showAddress(Address $address, $_format): Response + { + // TODO check ACL ? + switch ($_format) { + case 'json': + return $this->json($address); + default: + throw new BadRequestException('Unsupported format'); + } + } + + /** * Get API Data for showing endpoint * @@ -27,17 +49,9 @@ class AddressReferenceController extends AbstractController * ) * @ParamConverter("addressReference", options={"id": "address_reference_id"}) */ - public function showAPI(AddressReference $addressReference, $_format): Response + public function showAddressReference(AddressReference $addressReference, $_format): Response { - // TODO check ACL on AccompanyingPeriod - - $this->dispatcher->dispatch( - AccompanyingPeriodPrivacyEvent::ACCOMPANYING_PERIOD_PRIVACY_EVENT, - new AccompanyingPeriodPrivacyEvent($addressReference, [ - 'action' => 'showApi' - ]) - ); - + // TODO check ACL ? switch ($_format) { case 'json': return $this->json($addressReference); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/App.vue new file mode 100644 index 000000000..924747c4e --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/App.vue @@ -0,0 +1,43 @@ + + + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/AccompanyingCourse.vue b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/AccompanyingCourse.vue new file mode 100644 index 000000000..d08798c00 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/AccompanyingCourse.vue @@ -0,0 +1,26 @@ + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonItem.vue b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonItem.vue new file mode 100644 index 000000000..f75f0779b --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonItem.vue @@ -0,0 +1,25 @@ + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonsAssociated.vue b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonsAssociated.vue new file mode 100644 index 000000000..f4ccf6964 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonsAssociated.vue @@ -0,0 +1,69 @@ + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/Requestor.vue b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/Requestor.vue new file mode 100644 index 000000000..75a95e241 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/Requestor.vue @@ -0,0 +1,16 @@ + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/index.js b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/index.js new file mode 100644 index 000000000..b524398f7 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/index.js @@ -0,0 +1,8 @@ +import App from './App.vue'; +import { createApp } from 'vue'; + +const app = createApp({ + template: `` +}) +.component('app', App) +.mount('#address'); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/store/.keep b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/store/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig index 9e91e486c..1e39cf705 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig @@ -23,9 +23,9 @@ {% block title %}{{ 'Addresses\'history for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}{% endblock %} {% block personcontent %} - +

{{ 'Addresses\'history for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}

- + @@ -48,11 +48,11 @@ {% for address in person.addresses %} - + - + + + +
+ + {{ encore_entry_script_tags('address') }} + + + {% endfor %} {% endif %}
{{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }} {{ address_macros._render(address, { 'with_valid_from' : false, 'has_no_address': true } ) }}
  • @@ -61,11 +61,26 @@
- + + + + + +
- -{% endblock personcontent %} \ No newline at end of file + +{% endblock personcontent %} diff --git a/src/Bundle/ChillPersonBundle/chill.webpack.config.js b/src/Bundle/ChillPersonBundle/chill.webpack.config.js index 9d7a33d02..8e2c60ef2 100644 --- a/src/Bundle/ChillPersonBundle/chill.webpack.config.js +++ b/src/Bundle/ChillPersonBundle/chill.webpack.config.js @@ -7,6 +7,8 @@ module.exports = function(encore, entries) encore.addAliases({ ChillPersonAssets: __dirname + '/Resources/public' }); - + encore.addEntry('accompanying_course', __dirname + '/Resources/public/js/AccompanyingCourse/index.js'); + encore.addEntry('address', __dirname + '/Resources/public/js/Address/index.js'); + }; From 86c177bbbbe8f1a58a066ad04fcc949f23e0532d Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 4 May 2021 17:26:47 +0200 Subject: [PATCH 24/28] remove vuejs address component --- .../Resources/public/js/Address/App.vue | 43 ------------ .../Address/components/AccompanyingCourse.vue | 26 ------- .../js/Address/components/PersonItem.vue | 25 ------- .../Address/components/PersonsAssociated.vue | 69 ------------------- .../js/Address/components/Requestor.vue | 16 ----- .../Resources/public/js/Address/index.js | 8 --- .../Resources/public/js/Address/store/.keep | 0 .../Resources/views/Address/list.html.twig | 9 --- .../ChillPersonBundle/chill.webpack.config.js | 2 - 9 files changed, 198 deletions(-) delete mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/App.vue delete mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/AccompanyingCourse.vue delete mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonItem.vue delete mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonsAssociated.vue delete mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/Requestor.vue delete mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/index.js delete mode 100644 src/Bundle/ChillPersonBundle/Resources/public/js/Address/store/.keep diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/App.vue deleted file mode 100644 index 924747c4e..000000000 --- a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/App.vue +++ /dev/null @@ -1,43 +0,0 @@ - - - - - diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/AccompanyingCourse.vue b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/AccompanyingCourse.vue deleted file mode 100644 index d08798c00..000000000 --- a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/AccompanyingCourse.vue +++ /dev/null @@ -1,26 +0,0 @@ - - - diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonItem.vue b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonItem.vue deleted file mode 100644 index f75f0779b..000000000 --- a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonItem.vue +++ /dev/null @@ -1,25 +0,0 @@ - - - diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonsAssociated.vue b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonsAssociated.vue deleted file mode 100644 index f4ccf6964..000000000 --- a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/PersonsAssociated.vue +++ /dev/null @@ -1,69 +0,0 @@ - - - diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/Requestor.vue b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/Requestor.vue deleted file mode 100644 index 75a95e241..000000000 --- a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/components/Requestor.vue +++ /dev/null @@ -1,16 +0,0 @@ - - - diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/index.js b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/index.js deleted file mode 100644 index b524398f7..000000000 --- a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import App from './App.vue'; -import { createApp } from 'vue'; - -const app = createApp({ - template: `` -}) -.component('app', App) -.mount('#address'); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/Address/store/.keep b/src/Bundle/ChillPersonBundle/Resources/public/js/Address/store/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig index 1e39cf705..8a2aeee42 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Address/list.html.twig @@ -62,15 +62,6 @@ - -
- - {{ encore_entry_script_tags('address') }} - - - {% endfor %} {% endif %} diff --git a/src/Bundle/ChillPersonBundle/chill.webpack.config.js b/src/Bundle/ChillPersonBundle/chill.webpack.config.js index 8e2c60ef2..7987ee124 100644 --- a/src/Bundle/ChillPersonBundle/chill.webpack.config.js +++ b/src/Bundle/ChillPersonBundle/chill.webpack.config.js @@ -9,6 +9,4 @@ module.exports = function(encore, entries) }); encore.addEntry('accompanying_course', __dirname + '/Resources/public/js/AccompanyingCourse/index.js'); - encore.addEntry('address', __dirname + '/Resources/public/js/Address/index.js'); - }; From f61af9d02a17b31dda4926245666c7a5f4fbf94e Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 5 May 2021 11:44:55 +0200 Subject: [PATCH 25/28] add household and householdmembers entities + migration --- .../Entity/Household/Household.php | 24 +++ .../Entity/Household/HouseholdMembers.php | 153 ++++++++++++++++++ .../Household/HouseholdMembersRepository.php | 50 ++++++ .../Household/HouseholdRepository.php | 50 ++++++ .../migrations/Version20210505093408.php | 41 +++++ 5 files changed, 318 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Entity/Household/Household.php create mode 100644 src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php create mode 100644 src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php create mode 100644 src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20210505093408.php diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php new file mode 100644 index 000000000..304321ac8 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -0,0 +1,24 @@ +id; + } +} diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php new file mode 100644 index 000000000..80864ecd0 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php @@ -0,0 +1,153 @@ +id; + } + + public function getPosition(): ?string + { + return $this->position; + } + + public function setPosition(?string $position): self + { + $this->position = $position; + + return $this; + } + + public function getStartDate(): ?\DateTimeInterface + { + return $this->startDate; + } + + public function setStartDate(\DateTimeInterface $startDate): self + { + $this->startDate = $startDate; + + return $this; + } + + public function getEndDate(): ?\DateTimeInterface + { + return $this->endDate; + } + + public function setEndDate(\DateTimeInterface $endDate): self + { + $this->endDate = $endDate; + + return $this; + } + + public function getComment(): ?string + { + return $this->comment; + } + + public function setComment(?string $comment): self + { + $this->comment = $comment; + + return $this; + } + + public function getSharedHousehold(): ?bool + { + return $this->sharedHousehold; + } + + public function setSharedHousehold(bool $sharedHousehold): self + { + $this->sharedHousehold = $sharedHousehold; + + return $this; + } + + public function getPerson(): ?Person + { + return $this->person; + } + + public function setPerson(?Person $person): self + { + $this->person = $person; + + return $this; + } + + public function getHousehold(): ?Household + { + return $this->household; + } + + public function setHousehold(?Household $household): self + { + $this->household = $household; + + return $this; + } +} diff --git a/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php new file mode 100644 index 000000000..feea6d44d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('h') + ->andWhere('h.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('h.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?HouseholdMembers + { + return $this->createQueryBuilder('h') + ->andWhere('h.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php new file mode 100644 index 000000000..38522806c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('h') + ->andWhere('h.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('h.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?Household + { + return $this->createQueryBuilder('h') + ->andWhere('h.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210505093408.php b/src/Bundle/ChillPersonBundle/migrations/Version20210505093408.php new file mode 100644 index 000000000..cf5a93164 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210505093408.php @@ -0,0 +1,41 @@ +addSql('CREATE SEQUENCE Household_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE HouseholdMembers_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE Household (id INT NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE HouseholdMembers (id INT NOT NULL, person_id INT DEFAULT NULL, household_id INT DEFAULT NULL, position VARCHAR(255) DEFAULT NULL, startDate DATE NOT NULL, endDate DATE NOT NULL, comment VARCHAR(255) DEFAULT NULL, sharedHousehold BOOLEAN NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_4D1FB288217BBB47 ON HouseholdMembers (person_id)'); + $this->addSql('CREATE INDEX IDX_4D1FB288E79FF843 ON HouseholdMembers (household_id)'); + $this->addSql('ALTER TABLE HouseholdMembers ADD CONSTRAINT FK_4D1FB288217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE HouseholdMembers ADD CONSTRAINT FK_4D1FB288E79FF843 FOREIGN KEY (household_id) REFERENCES Household (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE HouseholdMembers DROP CONSTRAINT FK_4D1FB288E79FF843'); + $this->addSql('ALTER TABLE HouseholdMembers DROP CONSTRAINT FK_4D1FB288217BBB47'); + $this->addSql('DROP SEQUENCE Household_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE HouseholdMembers_id_seq CASCADE'); + $this->addSql('DROP TABLE Household'); + $this->addSql('DROP TABLE HouseholdMembers'); + } +} From 0a894b0db1cacc3b1b24e836cd04e7fc6674fa44 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 5 May 2021 18:24:58 +0200 Subject: [PATCH 26/28] add new fields on Address and Household --- src/Bundle/ChillMainBundle/Entity/Address.php | 24 +++++++++- .../Entity/Household/Household.php | 46 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Address.php b/src/Bundle/ChillMainBundle/Entity/Address.php index 9e9022e31..36eda09c2 100644 --- a/src/Bundle/ChillMainBundle/Entity/Address.php +++ b/src/Bundle/ChillMainBundle/Entity/Address.php @@ -5,6 +5,7 @@ namespace Chill\MainBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Chill\MainBundle\Doctrine\Model\Point; +use Chill\ThirdPartyBundle\Entity\ThirdParty; /** * Address @@ -130,6 +131,16 @@ class Address */ private $point; + /** + * A ThirdParty reference for person's addresses that are linked to a third party + * + * @var ThirdParty|null + * + * @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty") + * @ORM\JoinColumn(nullable=true) + */ + private $linkedToThirdParty; + /** * A list of metadata, added by customizable fields * @@ -142,7 +153,6 @@ class Address $this->validFrom = new \DateTime(); } - /** * Get id * @@ -487,5 +497,17 @@ class Address return $this; } + public function getLinkedToThirdParty() + { + return $this->linkedToThirdParty; + } + + public function setLinkedToThirdParty($linkedToThirdParty): self + { + $this->linkedToThirdParty = $linkedToThirdParty; + + return $this; + } + } diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index 304321ac8..a12741dee 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -4,6 +4,8 @@ namespace Chill\PersonBundle\Entity\Household; use Chill\PersonBundle\Repository\Household\HouseholdRepository; use Doctrine\ORM\Mapping as ORM; +use Doctrine\Common\Collections\Collection; +use Chill\MainBundle\Entity\Address; /** * @ORM\Entity(repositoryClass=HouseholdRepository::class) @@ -21,4 +23,48 @@ class Household { return $this->id; } + + /** + * Addresses + * @var Collection + * + * @ORM\ManyToMany( + * targetEntity="Chill\MainBundle\Entity\Address", + * cascade={"persist", "remove", "merge", "detach"}) + * @ORM\JoinTable(name="chill_person_household_to_addresses") + * @ORM\OrderBy({"validFrom" = "DESC"}) + */ + private $addresses; + + + /** + * @param Address $address + * @return $this + */ + public function addAddress(Address $address) + { + $this->addresses[] = $address; + + return $this; + } + + /** + * @param Address $address + */ + public function removeAddress(Address $address) + { + $this->addresses->removeElement($address); + } + + /** + * By default, the addresses are ordered by date, descending (the most + * recent first) + * + * @return \Chill\MainBundle\Entity\Address[] + */ + public function getAddresses() + { + return $this->addresses; + } + } From 4770758aeeb5cc204129a068dc81a3785143415b Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 6 May 2021 12:36:58 +0200 Subject: [PATCH 27/28] add migrations for addresse on household + add linkedtothirdparty on address --- .../migrations/Version20210505153727.php | 33 +++++++++++++++++++ .../migrations/Version20210505154316.php | 33 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20210505153727.php create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20210505154316.php diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210505153727.php b/src/Bundle/ChillMainBundle/migrations/Version20210505153727.php new file mode 100644 index 000000000..c1fff5b9e --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20210505153727.php @@ -0,0 +1,33 @@ +addSql('ALTER TABLE chill_main_address ADD linkedToThirdParty_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_main_address ADD CONSTRAINT FK_165051F6114B8DD9 FOREIGN KEY (linkedToThirdParty_id) REFERENCES chill_3party.third_party (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_165051F6114B8DD9 ON chill_main_address (linkedToThirdParty_id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_address DROP CONSTRAINT FK_165051F6114B8DD9'); + $this->addSql('DROP INDEX IDX_165051F6114B8DD9'); + $this->addSql('ALTER TABLE chill_main_address DROP linkedToThirdParty_id'); + } +} diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210505154316.php b/src/Bundle/ChillPersonBundle/migrations/Version20210505154316.php new file mode 100644 index 000000000..bb3a56337 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210505154316.php @@ -0,0 +1,33 @@ +addSql('CREATE TABLE chill_person_household_to_addresses (household_id INT NOT NULL, address_id INT NOT NULL, PRIMARY KEY(household_id, address_id))'); + $this->addSql('CREATE INDEX IDX_7109483E79FF843 ON chill_person_household_to_addresses (household_id)'); + $this->addSql('CREATE INDEX IDX_7109483F5B7AF75 ON chill_person_household_to_addresses (address_id)'); + $this->addSql('ALTER TABLE chill_person_household_to_addresses ADD CONSTRAINT FK_7109483E79FF843 FOREIGN KEY (household_id) REFERENCES Household (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_person_household_to_addresses ADD CONSTRAINT FK_7109483F5B7AF75 FOREIGN KEY (address_id) REFERENCES chill_main_address (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP TABLE chill_person_household_to_addresses'); + } +} From 1b8462b40d40a2d6833d3bd3e937cfd3e255f818 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 7 May 2021 10:27:11 +0200 Subject: [PATCH 28/28] update validto field in chill_main_address for legacy --- .../migrations/Version20210505153727.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210505153727.php b/src/Bundle/ChillMainBundle/migrations/Version20210505153727.php index c1fff5b9e..42161ba84 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20210505153727.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20210505153727.php @@ -22,6 +22,26 @@ final class Version20210505153727 extends AbstractMigration $this->addSql('ALTER TABLE chill_main_address ADD linkedToThirdParty_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE chill_main_address ADD CONSTRAINT FK_165051F6114B8DD9 FOREIGN KEY (linkedToThirdParty_id) REFERENCES chill_3party.third_party (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('CREATE INDEX IDX_165051F6114B8DD9 ON chill_main_address (linkedToThirdParty_id)'); + $this->addSql(' + CREATE TABLE chill_main_address_legacy AS + TABLE chill_main_address; + '); + $this->addSql(' + WITH hydrated_addresses AS ( + SELECT *, rank() OVER (PARTITION BY pa_a.person_id ORDER BY validfrom) + FROM chill_main_address AS aa JOIN chill_person_persons_to_addresses AS pa_a ON aa.id = pa_a.address_id + ) + UPDATE chill_main_address AS b + SET validto = ( + SELECT validfrom - INTERVAL \'1 DAY\' + FROM hydrated_addresses + WHERE hydrated_addresses.id = ( + SELECT a1.id + FROM hydrated_addresses AS a1 JOIN hydrated_addresses AS a2 ON a2.person_id = a1.person_id AND a2.rank = (a1.rank-1) + WHERE a2.id = b.id + ) + ); + '); } public function down(Schema $schema): void @@ -29,5 +49,10 @@ final class Version20210505153727 extends AbstractMigration $this->addSql('ALTER TABLE chill_main_address DROP CONSTRAINT FK_165051F6114B8DD9'); $this->addSql('DROP INDEX IDX_165051F6114B8DD9'); $this->addSql('ALTER TABLE chill_main_address DROP linkedToThirdParty_id'); + $this->addSql('DROP TABLE IF EXISTS chill_main_address_legacy'); + $this->addSql(' + UPDATE chill_main_address + SET validto = null; + '); } }