mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 14:24:24 +00:00
96 lines
2.2 KiB
PHP
96 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Chill\MainBundle\DataFixtures\ORM;
|
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture;
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
use Doctrine\Persistence\ObjectManager;
|
|
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
|
|
use Chill\MainBundle\Entity\AddressReference;
|
|
use Chill\MainBundle\Doctrine\Model\Point;
|
|
|
|
/**
|
|
* Load reference addresses into database
|
|
*
|
|
* @author Champs Libres
|
|
*/
|
|
class LoadAddressReferences extends AbstractFixture implements ContainerAwareInterface, OrderedFixtureInterface {
|
|
|
|
|
|
protected $faker;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->faker = \Faker\Factory::create('fr_FR');
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @var ContainerInterface
|
|
*/
|
|
private $container;
|
|
|
|
public function setContainer(ContainerInterface $container = null)
|
|
{
|
|
$this->container = $container;
|
|
}
|
|
|
|
public function getOrder() {
|
|
return 51;
|
|
}
|
|
|
|
|
|
/**
|
|
* 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->numerify('ref-id-######'));
|
|
$ar->setStreet($this->faker->streetName);
|
|
$ar->setStreetNumber(rand(0,199));
|
|
$ar ->setPoint($this->getRandomPoint());
|
|
$ar->setPostcode($this->getReference(
|
|
LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)]
|
|
));
|
|
|
|
$ar->setMunicipalityCode($ar->getPostcode()->getCode());
|
|
|
|
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();
|
|
}
|
|
|
|
|
|
}
|