Example #1
0
 /**
  * @param string $source
  * @param City $destination
  * @return mixed
  */
 public function map($source, $destination)
 {
     $destination->setName($source);
     $translations = array('fr' => $source);
     if (!$destination->getName()) {
         $translations = array('en' => $source);
     }
     $this->translateProperty($destination, 'name', $translations);
     if ($destination->getLatitude() == null || $destination->getLongitude() == null) {
         $tabCoord = $this->google->getGoogleXmlCoords($source, 'fr');
         if (isset($tabCoord[0]) && !empty($tabCoord[0]) && isset($tabCoord[1]) && !empty($tabCoord[1])) {
             $destination->setLatitude($tabCoord[0]);
             $destination->setLongitude($tabCoord[1]);
         }
     }
     return $destination;
 }
Example #2
0
 /**
  * @param City $city
  * @param null $lang
  * @param bool $absolute
  * @return bool
  */
 public function generateCityUrl(City $city, $lang = null, $absolute = false)
 {
     if ($lang === null) {
         $lang = $this->context->get('language');
     }
     $slug = $city->getSlug();
     if ($slug && $lang) {
         return $this->router->generate('destination_sheet_city', array('slugCity' => $slug, 'locale' => $lang), $absolute);
     }
     return false;
 }
Example #3
0
 /**
  * @param City $city
  * @param Department $department
  */
 protected function removeCity($city, $department)
 {
     $departmentId = $department->getId();
     if (!isset($this->removeCities[$departmentId])) {
         $this->removeCities[$departmentId] = array();
     }
     $this->removeCities[$departmentId][] = $city->getId();
 }
Example #4
0
 /**
  * Get linkedCity
  *
  * @return City
  */
 public function getLinkedCityLowestDistance()
 {
     /** @var array $toReturn */
     $toReturn = array();
     /** @var City $linkedCity */
     foreach ($this->linkedCities as $linkedCity) {
         if ($linkedCity->getId() != $this->city->getId()) {
             $distance = 0;
             if ($linkedCity->getLatitude() && $linkedCity->getLongitude() && $this->latitude && $this->longitude) {
                 $distance = GeolocManager::calculateDistance($linkedCity->getLatitude(), $linkedCity->getLongitude(), $this->latitude, $this->longitude);
             }
             if ($distance > 0) {
                 $linkedCity->setDistance($distance);
                 $toReturn[] = $linkedCity;
             }
         }
     }
     usort($toReturn, function ($a, $b) {
         if ($a->getDistance() > $b->getDistance()) {
             return 1;
         } elseif ($a->getDistance() < $b->getDistance()) {
             return -1;
         }
         return 0;
     });
     return array_shift($toReturn);
 }
Example #5
0
 /**
  * @param City $city
  *
  * @return $this
  */
 public function removeCity($city)
 {
     $this->cityType->deleteById($city->getId());
 }
Example #6
0
 /**
  * Removes a city.
  *
  * @param City $city
  * @return $this For fluid purposes.
  */
 public function removeCity(\Seh\Bundle\SehBundle\Entity\City $city)
 {
     $this->cities->removeElement($city);
     return $this;
 }
Example #7
0
 /**
  * @param City $city
  * @return array
  */
 public function findNbForCityAndBrand($city, $brandId = null)
 {
     $cityId = $city;
     if ($city instanceof City) {
         $cityId = $city->getId();
     }
     $qb = $this->getValidQueryBuilder()->andWhere('(ci.id = :city OR :city MEMBER OF h.linkedCities)')->setParameter(':city', $cityId)->select('COUNT(DISTINCT h.id) as nbHotels');
     if ($brandId != null) {
         $qb->andWhere('b.id = :idBrand')->setParameter(':idBrand', $brandId);
     }
     return $qb->getQuery()->getSingleScalarResult();
 }