mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix LoadPeople for gender
This commit is contained in:
parent
086f391dc9
commit
d04f9ae9ff
@ -15,12 +15,14 @@ use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\Country;
|
||||
use Chill\MainBundle\Entity\Gender;
|
||||
use Chill\MainBundle\Entity\GenderEnum;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\CenterRepository;
|
||||
use Chill\MainBundle\Repository\CountryRepository;
|
||||
use Chill\MainBundle\Repository\GenderRepository;
|
||||
use Chill\MainBundle\Repository\ScopeRepository;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
@ -78,11 +80,13 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
|
||||
*/
|
||||
protected array $cacheUsers = [];
|
||||
|
||||
protected array $cacheGenders = [];
|
||||
|
||||
protected Generator $faker;
|
||||
|
||||
protected NativeLoader $loader;
|
||||
|
||||
private array $genders = [GenderEnum::MALE, GenderEnum::FEMALE, GenderEnum::NEUTRAL];
|
||||
// private array $genders = [GenderEnum::MALE, GenderEnum::FEMALE, GenderEnum::NEUTRAL];
|
||||
|
||||
private array $peoples = [
|
||||
[
|
||||
@ -229,6 +233,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
|
||||
protected MaritalStatusRepository $maritalStatusRepository,
|
||||
protected ScopeRepository $scopeRepository,
|
||||
protected UserRepository $userRepository,
|
||||
protected GenderRepository $genderRepository,
|
||||
) {
|
||||
$this->faker = Factory::create('fr_FR');
|
||||
$this->faker->addProvider($this);
|
||||
@ -273,9 +278,17 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
|
||||
/**
|
||||
* @internal This method is public and called by faker as a custom generator
|
||||
*/
|
||||
public function getRandomGender(): string
|
||||
public function getRandomGender(int $nullPercentage = 50): ?Gender
|
||||
{
|
||||
return $this->genders[array_rand($this->genders)]->value;
|
||||
if (0 === \count($this->cacheGenders)) {
|
||||
$this->cacheGenders = $this->genderRepository->findAll();
|
||||
}
|
||||
|
||||
if (\random_int(0, 100) > $nullPercentage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->cacheGenders[array_rand($this->cacheGenders)];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user