diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php index fbb66b6bb..474cd1216 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php @@ -21,14 +21,18 @@ namespace Chill\PersonBundle\DataFixtures\ORM; +use Chill\MainBundle\Entity\PostalCode; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; +use Chill\ThirdPartyBundle\Entity\ThirdParty; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Doctrine\Persistence\ObjectManager; use Chill\PersonBundle\Entity\Person; use Faker\Factory; use Faker\Generator; +use Nelmio\Alice\Loader\NativeLoader; +use Nelmio\Alice\ObjectSet; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes; use Chill\MainBundle\Entity\Address; @@ -215,6 +219,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con $accompanyingPeriod->addSocialIssue($this->getRandomSocialIssue()); if (\random_int(0, 10) > 3) { + $accompanyingPeriod->setAddressLocation($this->createAddress()); + $manager->persist($accompanyingPeriod->getAddressLocation()); $workflow = $this->workflowRegistry->get($accompanyingPeriod); $workflow->apply($accompanyingPeriod, 'confirm'); } @@ -262,6 +268,29 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con echo "add person'".$p->__toString()."'\n"; } + private function createAddress(): Address + { + $loader = new NativeLoader(); + $objectSet = $loader->loadData([ + Address::class => [ + 'address' => [ + 'street' => '', + 'streetNumber' => '', + 'validFrom' => '', + 'postCode' => $this->getPostalCode() + ], + ], + ]); + + return $objectSet->getObjects()['address']; + } + + private function getPostalCode(): PostalCode + { + $ref = LoadPostalCodes::$refs[\array_rand(LoadPostalCodes::$refs)]; + + return $this->getReference($ref); + } /** * Create a random point