mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Rename membership edition and add more fixtures
This commit is contained in:
@@ -4,7 +4,7 @@ namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Household\MoveMembersFactory;
|
||||
use Chill\PersonBundle\Household\MembersEditorFactory;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
@@ -12,33 +12,53 @@ use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
|
||||
class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
{
|
||||
private MoveMembersFactory $movementFactory;
|
||||
private MembersEditorFactory $editorFactory;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private CONST NUMBER_OF_HOUSEHOLD = 10;
|
||||
|
||||
public function __construct(MoveMembersFactory $movementFactory, EntityManagerInterface $em)
|
||||
public function __construct(MembersEditorFactory $editorFactory, EntityManagerInterface $em)
|
||||
{
|
||||
$this->movementFactory = $movementFactory;
|
||||
$this->editorFactory = $editorFactory;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
// generate two times the participation. This will lead to
|
||||
// some movement in participation (same people in two differents
|
||||
// households)
|
||||
|
||||
$this->preparePersonIds();
|
||||
|
||||
$this->generateHousehold(
|
||||
$manager,
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
|
||||
);
|
||||
|
||||
$this->preparePersonIds();
|
||||
|
||||
$this->generateHousehold(
|
||||
$manager,
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d', '2015-01-01')
|
||||
);
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
private function generateHousehold(ObjectManager $manager, \DateTimeImmutable $startDate)
|
||||
{
|
||||
for ($i=0; $i < self::NUMBER_OF_HOUSEHOLD; $i++) {
|
||||
$household = new Household();
|
||||
$manager->persist($household);
|
||||
|
||||
$movement = $this->movementFactory->createMovement($household);
|
||||
$movement = $this->editorFactory->createEditor($household);
|
||||
|
||||
// load adults
|
||||
$k = 0;
|
||||
foreach ($this->getRandomPersons(1, 3) as $person) {
|
||||
$date = \DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
|
||||
->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||
$position = $this->getReference(LoadHouseholdPosition::ADULT);
|
||||
|
||||
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
||||
@@ -47,21 +67,26 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
|
||||
// load children
|
||||
foreach ($this->getRandomPersons(0, 3) as $person) {
|
||||
$date = \DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
|
||||
->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||
$position = $this->getReference(LoadHouseholdPosition::CHILD);
|
||||
|
||||
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
||||
$k++;
|
||||
}
|
||||
|
||||
// load children out
|
||||
foreach ($this->getRandomPersons(0, 2) as $person) {
|
||||
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||
$position = $this->getReference(LoadHouseholdPosition::CHILD_OUT);
|
||||
|
||||
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
||||
$k++;
|
||||
}
|
||||
|
||||
foreach ($movement->getPersistable() as $obj) {
|
||||
print($obj->getStartDate()->format('Y-m-d'));
|
||||
$manager->persist($obj);
|
||||
}
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
private function preparePersonIds()
|
||||
|
Reference in New Issue
Block a user