Skip to content
Snippets Groups Projects
Commit 51f8ed2a authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Ajout de la recherche avec types pour les structures

parent 0433c9fb
No related branches found
No related tags found
No related merge requests found
......@@ -101,18 +101,46 @@ class StructureService {
/**
* @param string $term
* @param string $type
* @return Structure[]
*/
public function getStructuresByTerm($term)
public function getStructuresByTerm($term, $type = null)
{
$qb = $this->getEntityManager()->getRepository(Structure::class)->createQueryBuilder('type')
->andWhere('type.libelleCourt LIKE :search')
$qb = $this->getEntityManager()->getRepository(Structure::class)->createQueryBuilder('structure')
->andWhere('structure.libelleCourt LIKE :search')
->setParameter('search', '%'.$term.'%')
->orderBy('type.libelleCourt')
->orderBy('structure.libelleCourt')
;
if ($type) {
$qb = $qb->addSelect('type')->join('structure.type', 'type')
->andWhere('type.code = :type')
->setParameter('type', $type)
;
}
$result = $qb->getQuery()->getResult();
return $result;
}
/**
* @param string $type
* @param string $order
* @return Structure[]
*/
public function getStructuresByType($type, $order = null)
{
$qb = $this->getEntityManager()->getRepository(Structure::class)->createQueryBuilder('type')
->addSelect('type')->join('structure.type', 'type')
->andWhere('type.code = :type')
->setParameter('type', $type)
;
if ($order) $qb = $qb->orderBy('type.'.$order);
$qb = $qb->setMaxResults(501);
$result = $qb->getQuery()->getResult();
return $result;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment