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

@@ -0,0 +1,40 @@
<?php
namespace Chill\PersonBundle\DataFixtures\Helper;
use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\EntityManagerInterface;
trait PersonRandomHelper
{
private array $randPersons = [];
private ?int $countPersons = null;
protected function getRandomPerson(EntityManagerInterface $em): Person
{
$fetchBy = 5;
if (null === $this->countPersons) {
$qb = $em->createQueryBuilder();
$this->countPersons = $qb->select('count(p)')
->from(Person::class, 'p')
->getQuery()
->getSingleScalarResult()
;
}
if ([] === $this->randPersons) {
$qb = $em->createQueryBuilder();
$this->randPersons = $qb
->select('p')
->from(Person::class, 'p')
->getQuery()
->setFirstResult(\random_int(0, $this->countPersons - $fetchBy))
->setMaxResults($fetchBy)
->getResult()
;
}
return \array_pop($this->randPersons);
}
}