<?php
namespace App\Repository;
use App\Entity\Address;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Address|null find($id, $lockMode = null, $lockVersion = null)
* @method Address|null findOneBy(array $criteria, array $orderBy = null)
* @method Address[] findAll()
* @method Address[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class AddressRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Address::class);
}
public function getExistingCountries($type = null)
{
$query = $this->createQueryBuilder('a')
->select('a.countryCode')
->join('a.owner','o')
->where('o.isPro = true')
->groupBy('a.countryCode')
->orderBy('count(a.countryCode)', 'DESC')
;
if ($type != null) {
if ($type == 'coach') {
$query->andWhere('o INSTANCE OF App\Entity\Coach');
}
else if ($type == 'club') {
$query->andWhere('o INSTANCE OF App\Entity\Club');
}
else
{
$query->andWhere('o INSTANCE OF App\Entity\Operator');
}
}
return $query->getQuery()
->getResult();
}
public function findCountryName($slug)
{
return $this->createQueryBuilder('a')
->select('MIN(a.country)')
->where('a.slug = :slug')
->setParameter('slug', $slug)
->getQuery()
->getOneOrNullResult()
;
}
}