cmtracker/src/DataFixtures/ReferralSourceFixture.php

42 lines
1.1 KiB
PHP

<?php
namespace App\DataFixtures;
use App\Entity\ReferralSource;
use App\Enums\County;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Faker\Factory;
class ReferralSourceFixture extends Fixture
{
public function load(ObjectManager $manager): void
{
if(!$_ENV['CREATE_SOURCES']) {
return;
}
$gen = Factory::create();
for ($x = 0; $x < $_ENV['CREATE_REFERRALS']; $x++) {
$src = new ReferralSource();
$name = "{$gen->firstName()} {$gen->lastName()}";
$username = strtolower(str_replace(' ', '.', $name));
$src->setName($name)
->setEmail("{$username}@dcs.in.gov")
->setCounty((string) $gen->randomElement(County::class)->name)
->setAgency('DCS')
->setPhone(str_replace(['-', '+'], '', $gen->phoneNumber()))
;
print "Adding referral source {$src->getName()}".PHP_EOL;
$manager->persist($src);
}
// $product = new Product();
// $manager->persist($product);
$manager->flush();
}
}