src/Aviatur/FlightBundle/Entity/ConfigFlightAgencyRepository.php line 39

Open in your IDE?
  1. <?php
  2. namespace Aviatur\FlightBundle\Entity;
  3. use Doctrine\ORM\EntityRepository;
  4. class ConfigFlightAgencyRepository extends EntityRepository
  5. {
  6.     public function findProviderForFlights($productType$domain$domainField 'domain')
  7.     {
  8.         $query $this->getEntityManager()
  9.                         ->createQuery(
  10.                             'SELECT cca FROM AviaturFlightBundle:ConfigFlightAgency cca '
  11.                                 .'JOIN cca.provider p JOIN cca.agency a '
  12.                                 .'WHERE p.productType = :productType '
  13.                                 .'AND a.'.$domainField.' = :domain '
  14.                                 .'AND cca.isactive = :isactive '
  15.                                 .'ORDER BY p.id ASC'
  16.                         )->setParameters(
  17.                             [
  18.                     'productType' => $productType,
  19.                     'domain' => str_replace('www.'''$domain),
  20.                     'isactive' => 1,
  21.                 ]
  22.                         );
  23.         try {
  24.             return $query->getResult();
  25.         } catch (\Doctrine\ORM\NoResultException $e) {
  26.             return null;
  27.         }
  28.     }
  29.     public function findProviderForFlightsWithAgency($agency$flightType = [])
  30.     {
  31.         if (== sizeof($flightType)) {
  32.             $flightTypeConditional '';
  33.         } else {
  34.             $flightTypeConditional 'AND cca.preference IN ('.implode($flightType',').') ';
  35.         }
  36.         $query $this->getEntityManager()
  37.                         ->createQuery(
  38.                             'SELECT cca FROM AviaturFlightBundle:ConfigFlightAgency cca '
  39.                                 .'WHERE cca.agency = :agency '
  40.                                 .'AND cca.isactive = :isactive '
  41.                                 .'AND (cca.errorcount < :errorcount OR cca.errordatetime <= :errordatetime)'
  42.                                 .$flightTypeConditional
  43.                                 .'ORDER BY cca.id ASC'
  44.                         )->setParameters(
  45.                             [
  46.                     'agency' => $agency,
  47.                     'isactive' => 1,
  48.                     'errorcount' => 10,
  49.                     'errordatetime' => new \DateTime(date('Y-m-d H:i:s'strtotime('-10 minute'))),
  50.                 ]
  51.                         );
  52.         try {
  53.             return $query->getResult();
  54.         } catch (\Doctrine\ORM\NoResultException $e) {
  55.             return null;
  56.         }
  57.     }
  58. }