add base authorization to person search + improve search ordering

This commit is contained in:
2021-11-15 11:17:03 +00:00
parent 4ba93bb709
commit 8296d60cb6
22 changed files with 317 additions and 151 deletions

View File

@@ -3,17 +3,24 @@ declare(strict_types=1);
namespace Chill\PersonBundle\DataFixtures\ORM;
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use Chill\PersonBundle\DataFixtures\ORM\LoadPeople;
use Chill\PersonBundle\DataFixtures\ORM\LoadRelations;
use Chill\PersonBundle\Entity\Relationships\Relationship;
class LoadRelationships extends Fixture implements DependentFixtureInterface
{
use PersonRandomHelper;
private EntityManagerInterface $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function getDependencies()
{
@@ -21,16 +28,33 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
LoadPeople::class,
LoadRelations::class
];
}
public function load(ObjectManager $manager)
{
$relationship = new Relationship;
$relationship->setFromPerson($this->getReference(LoadPeople::PERSON));
$relationship->setToPerson($this->getReference(LoadPeople::PERSON));
$relationship->setRelation($this->getReference(LoadRelations::RELATIONS));
$relationship->setReverse((bool)random_int(0, 1));
for ($i = 0; $i < 15; $i++) {
$user = $this->getRandomUser();
$date = new \DateTimeImmutable();
$relationship = (new Relationship())
->setFromPerson($this->getRandomPerson($this->em))
->setToPerson($this->getRandomPerson($this->em))
->setRelation($this->getReference(LoadRelations::RELATION_KEY.
\random_int(0, count(LoadRelations::RELATIONS) - 1)))
->setReverse((bool) random_int(0, 1))
->setCreatedBy($user)
->setUpdatedBy($user)
->setCreatedAt($date)
->setUpdatedAt($date)
;
$manager->persist($relationship);
}
$manager->flush();
}
}
private function getRandomUser(): User
{
$userRef = array_rand(LoadUsers::$refs);
return $this->getReference($userRef);
}
}