mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Duplicate module
Signed-off-by: Mathieu Jaumotte <mathieu.jaumotte@champs-libres.coop>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Repository;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonNotDuplicate;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* Class PersonNotDuplicateRepository
|
||||
*
|
||||
* @package Chill\PersonBundle\Repository
|
||||
*/
|
||||
class PersonNotDuplicateRepository extends EntityRepository
|
||||
{
|
||||
/**
|
||||
* @param \Chill\PersonBundle\Entity\Person $person
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findNotDuplicatePerson(Person $person)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('pnd');
|
||||
$qb->select('pnd')
|
||||
->where('pnd.person1 = :person OR pnd.person2 = :person')
|
||||
;
|
||||
$qb->setParameter('person', $person);
|
||||
$result = $qb->getQuery()->getResult();
|
||||
|
||||
$persons = [];
|
||||
foreach ($result as $row) {
|
||||
if ($row->getPerson1() === $person) {
|
||||
$persons[] = $row->getPerson2();
|
||||
} elseif ($row->getPerson2() === $person) {
|
||||
$persons[] = $row->getPerson1();
|
||||
}
|
||||
}
|
||||
|
||||
return $persons;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user