Merge remote-tracking branch 'origin/master' into doc/authorizaton-documentation-update

This commit is contained in:
2021-11-22 10:30:05 +01:00
300 changed files with 9998 additions and 5391 deletions

View File

@@ -22,9 +22,10 @@
namespace Chill\ActivityBundle\DataFixtures\ORM;
use Chill\PersonBundle\DataFixtures\Helper\RandomPersonHelperTrait;
use Chill\PersonBundle\Entity\Person;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use Faker\Factory as FakerFactory;
use Chill\ActivityBundle\Entity\Activity;
@@ -32,26 +33,21 @@ use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
use Chill\ActivityBundle\DataFixtures\ORM\LoadActivityReason;
use Chill\ActivityBundle\DataFixtures\ORM\LoadActivityType;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
/**
* Load reports into DB
*
* @author Champs-Libres Coop
*/
class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
class LoadActivity extends AbstractFixture implements OrderedFixtureInterface
{
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
use RandomPersonHelperTrait;
/**
* @var \Faker\Generator
*/
private $faker;
private EntityManagerInterface $em;
public function __construct()
public function __construct(EntityManagerInterface $em)
{
$this->faker = FakerFactory::create('fr_FR');
$this->em = $em;
}
public function getOrder()
@@ -86,15 +82,10 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C
*
* @return \Chill\ActivityBundle\Entity\ActivityReason
*/
private function getRandomActivityReason(array $excludingIds)
private function getRandomActivityReason()
{
$reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)];
if (in_array($this->getReference($reasonRef)->getId(), $excludingIds)) {
// we have a reason which should be excluded. Find another...
return $this->getRandomActivityReason($excludingIds);
}
return $this->getReference($reasonRef);
}
@@ -109,7 +100,7 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C
return $this->getReference($userRef);
}
public function newRandomActivity($person)
public function newRandomActivity($person): ?Activity
{
$activity = (new Activity())
->setUser($this->getRandomUser())
@@ -122,11 +113,13 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C
// ->setAttendee($this->faker->boolean())
$usedId = array();
for ($i = 0; $i < rand(0, 4); $i++) {
$reason = $this->getRandomActivityReason($usedId);
$usedId[] = $reason->getId();
$activity->addReason($reason);
$reason = $this->getRandomActivityReason();
if (null !== $reason) {
$activity->addReason($reason);
} else {
return null;
}
}
return $activity;
@@ -134,20 +127,19 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C
public function load(ObjectManager $manager)
{
$persons = $this->container->get('doctrine.orm.entity_manager')
->getRepository('ChillPersonBundle:Person')
$persons = $this->em
->getRepository(Person::class)
->findAll();
foreach($persons as $person) {
foreach ($persons as $person) {
$activityNbr = rand(0,3);
$ref = 'activity_'.$person->getFullnameCanonical();
for($i = 0; $i < $activityNbr; $i ++) {
for ($i = 0; $i < $activityNbr; $i ++) {
$activity = $this->newRandomActivity($person);
$manager->persist($activity);
if (null !== $activity) {
$manager->persist($activity);
}
}
$this->setReference($ref, $activity);
}
$manager->flush();
}