mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-25 13:18:30 +00:00
51 lines
1.3 KiB
PHP
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();
|
|
}
|
|
}
|