<?php
namespace Aviatur\FlightBundle\Entity;
use Doctrine\ORM\EntityRepository;
class ConfigFlightAgencyRepository extends EntityRepository
{
public function findProviderForFlights($productType, $domain, $domainField = 'domain')
{
$query = $this->getEntityManager()
->createQuery(
'SELECT cca FROM AviaturFlightBundle:ConfigFlightAgency cca '
.'JOIN cca.provider p JOIN cca.agency a '
.'WHERE p.productType = :productType '
.'AND a.'.$domainField.' = :domain '
.'AND cca.isactive = :isactive '
.'ORDER BY p.id ASC'
)->setParameters(
[
'productType' => $productType,
'domain' => str_replace('www.', '', $domain),
'isactive' => 1,
]
);
try {
return $query->getResult();
} catch (\Doctrine\ORM\NoResultException $e) {
return null;
}
}
public function findProviderForFlightsWithAgency($agency, $flightType = [])
{
if (0 == sizeof($flightType)) {
$flightTypeConditional = '';
} else {
$flightTypeConditional = 'AND cca.preference IN ('.implode($flightType, ',').') ';
}
$query = $this->getEntityManager()
->createQuery(
'SELECT cca FROM AviaturFlightBundle:ConfigFlightAgency cca '
.'WHERE cca.agency = :agency '
.'AND cca.isactive = :isactive '
.'AND (cca.errorcount < :errorcount OR cca.errordatetime <= :errordatetime)'
.$flightTypeConditional
.'ORDER BY cca.id ASC'
)->setParameters(
[
'agency' => $agency,
'isactive' => 1,
'errorcount' => 10,
'errordatetime' => new \DateTime(date('Y-m-d H:i:s', strtotime('-10 minute'))),
]
);
try {
return $query->getResult();
} catch (\Doctrine\ORM\NoResultException $e) {
return null;
}
}
}