1: <?php
2: namespace TIC\TownBundle\Repository;
3:
4: use TIC\TownBundle\Entity\Region as RepoEntity;
5: use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
6: use Doctrine\Persistence\ManagerRegistry;
7:
8: /**
9: * RegionRepository.
10: *
11: * @method Region|null find($id, $lockMode = null, $lockVersion = null)
12: * @method Region|null findOneBy(array $criteria, array $orderBy = null)
13: * @method Region[] findAll()
14: * @method Region[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
15: */
16: class RegionRepository extends ServiceEntityRepository
17: {
18:
19: public function __construct(ManagerRegistry $registry)
20: {
21: parent::__construct($registry, RepoEntity::class);
22: }
23:
24:
25: public $sortBy = array('nom_maj' => 'ASC');
26:
27:
28: /**
29: * Recherche basique.
30: */
31: public function searchBasic(string $term, ?int $limit=20)
32: {
33: return $this->createQueryBuilder('d')
34: ->select('d.insee AS id, d.nom AS text')
35: ->where('d.nom LIKE :term')->setParameter('term', '%'.$term.'%')
36: ->setMaxResults($limit)
37: ->getQuery()->getArrayResult()
38: ;
39: }
40:
41: }
42: