src/Repository/AddressRepository.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Address;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @method Address|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method Address|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method Address[]    findAll()
  10.  * @method Address[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class AddressRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryAddress::class);
  17.     }
  18.     public function getExistingCountries($type null)
  19.     {
  20.         $query $this->createQueryBuilder('a')
  21.             ->select('a.countryCode')
  22.             ->join('a.owner','o')
  23.             ->where('o.isPro = true')
  24.             ->groupBy('a.countryCode')
  25.             ->orderBy('count(a.countryCode)''DESC')
  26.         ;
  27.         if ($type != null) {
  28.             if ($type == 'coach') {
  29.                 $query->andWhere('o INSTANCE OF App\Entity\Coach');
  30.             }
  31.             else if ($type == 'club') {
  32.                 $query->andWhere('o INSTANCE OF App\Entity\Club');
  33.             } 
  34.             else 
  35.             {
  36.                 $query->andWhere('o INSTANCE OF App\Entity\Operator');
  37.             }
  38.         }
  39.             
  40.         return $query->getQuery()
  41.             ->getResult();
  42.     }
  43.     public function findCountryName($slug)
  44.     {
  45.         return $this->createQueryBuilder('a')
  46.             ->select('MIN(a.country)')
  47.             ->where('a.slug  = :slug')
  48.             ->setParameter('slug'$slug)
  49.             ->getQuery()
  50.             ->getOneOrNullResult()
  51.         ;
  52.     }
  53. }