mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
docgen normalization for relation
This commit is contained in:
@@ -24,6 +24,8 @@ class RelationshipRepository implements ObjectRepository
|
||||
|
||||
private EntityRepository $repository;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->repository = $em->getRepository(Relationship::class);
|
||||
@@ -64,6 +66,30 @@ class RelationshipRepository implements ObjectRepository
|
||||
->getResult();
|
||||
}
|
||||
|
||||
public function countByPerson(Person $person): int
|
||||
{
|
||||
return $this->buildQueryByPerson($person)
|
||||
->select('COUNT(p)')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
private function buildQueryByPerson(Person $person): QueryBuilder
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
$qb
|
||||
->from(Relationship::class, 'r')
|
||||
->where(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->eq('r.fromPerson', ':person'),
|
||||
$qb->expr()->eq('r.toPerson', ':person')
|
||||
)
|
||||
)
|
||||
->setParameter('person', $person);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria): ?Relationship
|
||||
{
|
||||
return $this->findOneBy($criteria);
|
||||
|
Reference in New Issue
Block a user