Files
chill-bundles/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/ClosingMotiveRepository.php
2021-04-26 17:18:38 +02:00

51 lines
1.3 KiB
PHP

<?php
/**
* Chill is a software for social workers.
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://www.champs-libres.coop/
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Repository\AccompanyingPeriod;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
/**
* Class ClosingMotiveRepository
* Entity repository for closing motives.
*/
class ClosingMotiveRepository extends EntityRepository
{
/**
* @return mixed
*/
public function getActiveClosingMotive(bool $onlyLeaf = true)
{
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata($this->getClassName(), 'cm');
$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->_em
->createNativeQuery($sql, $rsm)
->getResult();
}
}