adding addresses to accompanying period

This commit is contained in:
Julien Fastré 2021-07-31 23:16:00 +02:00 committed by Marc Ducobu
parent 0e2e7155fb
commit 9f7c0dcd09

View File

@ -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' => '<fr_FR:streetName()>',
'streetNumber' => '<fr_FR:buildingNumber()>',
'validFrom' => '<dateTimeBetween(\'-1 year\', \'now\')>',
'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