From a1895ec65f7967d2b9560aa0f275041e2cfecf73 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 3 May 2021 11:18:31 +0200 Subject: [PATCH] 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');