Fix missing dependency.

This commit is contained in:
Pol Dellaiera 2021-05-21 16:35:26 +02:00
parent 1f4735caac
commit 5cc5e6a1f7

View File

@ -27,46 +27,41 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
/**
* Class ClosingMotiveRepository
* Entity repository for closing motives
*
* @package Chill\PersonBundle\Repository
*/
final class ClosingMotiveRepository
{
private EntityRepository $repository;
private EntityManagerInterface $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
$this->repository = $entityManager->getRepository(ClosingMotive::class);
}
/**
* @param bool $onlyLeaf
* @return mixed
*/
public function getActiveClosingMotive(bool $onlyLeaf = true)
{
$rsm = new ResultSetMappingBuilder($this->repository->getEntityManager());
$rsm = new ResultSetMappingBuilder($this->entityManager);
$rsm->addRootEntityFromClassMetadata($this->repository->getClassName(), 'cm');
$sql = "SELECT ".(string) $rsm."
$sql = "SELECT " . (string) $rsm . "
FROM chill_person_accompanying_period_closingmotive AS cm
WHERE
active IS TRUE ";
if ($onlyLeaf) {
$sql .= "AND cm.id NOT IN (
SELECT DISTINCT parent_id FROM chill_person_accompanying_period_closingmotive WHERE parent_id IS NOT NULL
)";
}
$sql .= " ORDER BY cm.ordering ASC";
return $this
->repository
->getEntityManager()
->entityManager
->createNativeQuery($sql, $rsm)
->getResult();
}