diff --git a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadPostalCodes.php b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadPostalCodes.php index 6e3d1781b..26ce7415e 100644 --- a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadPostalCodes.php +++ b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadPostalCodes.php @@ -22,6 +22,8 @@ namespace Chill\MainBundle\DataFixtures\ORM; +use Chill\MainBundle\Doctrine\Model\Point; +use Chill\MainBundle\Entity\Country; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Doctrine\Persistence\ObjectManager; @@ -40,21 +42,41 @@ class LoadPostalCodes extends AbstractFixture implements OrderedFixtureInterface return 50; } - public static $refs = array(); + public static $refs = []; public function load(ObjectManager $manager) { - $lines = str_getcsv(self::$codes, "\n"); - $belgium = $manager->getRepository('ChillMainBundle:Country') - ->findOneBy(array('countryCode' => 'BE')); + echo "loading postal codes... \n"; + $this->loadPostalCodeCSV($manager, self::$postalCodeBelgium, 'BE'); + $this->loadPostalCodeCSV($manager, self::$postalCodeFrance, 'FR'); + } + + private function loadPostalCodeCSV(ObjectManager $manager, string $csv, string $countryCode) { + + $lines = str_getcsv($csv, "\n"); + $country = $manager->getRepository(Country::class) + ->findOneBy(['countryCode' => $countryCode]); foreach($lines as $line) { $code = str_getcsv($line); $c = new PostalCode(); - $c->setCountry($belgium) + $c->setCountry($country) ->setCode($code[0]) - ->setName(\ucwords(\strtolower($code[2]))) + ->setName(\ucwords(\strtolower($code[1]))) ; + + if (NULL != $code[3]){ + $c->setRefPostalCodeId($code[3]); + } + + if (NULL != $code[4] & NULL != $code[5]){ + $c->setCenter(Point::fromLonLat((float) $code[5], (float) $code[4])); + } + + if (NULL != $code[6]){ + $c->setPostalCodeSource($code[6]); + } + $manager->persist($c); $ref = 'postal_code_'.$code[0]; @@ -66,40 +88,342 @@ class LoadPostalCodes extends AbstractFixture implements OrderedFixtureInterface $manager->flush(); } - - private static $codes = <<