Пример #1
0
 /**
  * @param SearchModel $search
  *
  * @return \Doctrine\ORM\Query
  */
 public function getQueryFromSearch(SearchModel $search)
 {
     $nodes = $this->locationManager->getChildren($search->getLocation(), true, 'name', 'ASC', true);
     $results = [];
     foreach ($nodes as $location) {
         $results[] = $location->getId();
     }
     return $this->repository->getQueryFromSearch($search, $results);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function getQueryFromSearch(SearchModel $search, array $locations)
 {
     $queryBuilder = $this->createQueryBuilder('f')->select('f', 'p')->innerJoin('f.provider', 'p')->where('f.enabled = true')->andWhere('f.location IN(:locations)')->setParameter('locations', $locations)->orderBy('f.createdAt', 'DESC')->addOrderBy('f.title', 'ASC');
     // attach providers if needed
     if ($nbProviders = count($search->getProviders())) {
         $providers = [];
         foreach ($search->getProviders() as $provider) {
             $providers[] = $provider->getId();
         }
         if ($nbProviders == 1) {
             $queryBuilder->andWhere('p.id = :provider_id')->setParameter('provider_id', $providers[0]);
         } elseif ($nbProviders > 1) {
             $queryBuilder->andWhere('p.id IN (:provider_ids)')->setParameter('provider_ids', $providers);
         }
     }
     if ($search->getMinSize()) {
         $queryBuilder->andWhere('f.size >= :minSize')->setParameter('minSize', $search->getMinSize());
     }
     if ($search->getMaxSize()) {
         $queryBuilder->andWhere('f.size <= :maxSize')->setParameter('maxSize', $search->getMaxSize());
     }
     if ($search->getMinRooms()) {
         $queryBuilder->andWhere('f.nbRooms >= :minRooms')->setParameter('minRooms', $search->getMinRooms());
     }
     if ($search->getMaxRooms()) {
         $queryBuilder->andWhere('f.nbRooms <= :maxRooms')->setParameter('maxRooms', $search->getMaxRooms());
     }
     if ($search->getMinPrice()) {
         $queryBuilder->andWhere('f.price >= :minPrice')->setParameter('minPrice', $search->getMinPrice());
     }
     if ($search->getMaxPrice()) {
         $queryBuilder->andWhere('f.price <= :maxPrice')->setParameter('maxPrice', $search->getMaxPrice());
     }
     if (false === $search->isBToC()) {
         $queryBuilder->andWhere('f.bToC = false');
     } elseif (true === $search->isBToC()) {
         $queryBuilder->andWhere('f.bToC = true');
     }
     if (count($search->getExcludedFlats())) {
         $excludedFlats = [];
         /** @var $flat Flat */
         foreach ($search->getExcludedFlats() as $flat) {
             $excludedFlats[] = $flat->getId();
         }
         $queryBuilder->andWhere('f.id NOT IN (:excludedIds)')->setParameter('excludedIds', $excludedFlats);
     }
     return $queryBuilder->getQuery();
 }
Пример #3
0
 /**
  * @param SearchModel $search
  * @param FlatModel   $flat
  *
  * @return bool
  */
 public function isFlatDisabledForSearch(SearchModel $search, FlatModel $flat)
 {
     foreach ($search->getExcludedFlats() as $excludedFlat) {
         if ($excludedFlat == $flat) {
             return true;
         }
     }
     return false;
 }