コード例 #1
0
 public static function getOrCreate(GeocodeCached $locationInfo, Theatre $theatre, $computeDistance = false)
 {
     $where = $locationInfo->getQueryWhere()->where('theatre_id', $theatre->id);
     $manager = static::manager();
     $nearby = $manager->getEntityWhere($where);
     if ($nearby) {
         return $nearby;
     }
     $data = $locationInfo->toArray(0, 2, array('country_iso', 'postal_code', 'country', 'city'));
     $data['distance_m'] = $computeDistance ? LocationService::instance()->computeDistance($locationInfo->getGeocode(), $theatre->getGeocode()) : -1;
     $data['theatre_id'] = $theatre->id;
     $nearbyId = $manager->createEntity($data)->save();
     return $nearbyId ? $manager->getEntity($nearbyId) : null;
 }
コード例 #2
0
 /**
  *
  * @param string $latLong
  * @param bool $forceReload
  * @return \models\entities\GeocodeCached Description
  *
  */
 public function lookUp($latLong, $forceReload = false)
 {
     list($lat, $long) = explode(',', $latLong);
     $preciseLat = round(doubleval($lat), self::GEOCODE_PRECISION);
     $preciseLong = round(doubleval($long), self::GEOCODE_PRECISION);
     if (!$forceReload) {
         $lookUpWhere = (new \DbTableWhere())->where('longitude', $preciseLong)->where('latitude', $preciseLat)->setLimitAndOffset(1);
         $cachedList = \models\entities\GeocodeCached::manager()->getEntitiesWhere($lookUpWhere);
         if (count($cachedList)) {
             return $cachedList[0];
         }
     }
     foreach ($this->serviceProviderList as $serviceProvier) {
         $lookUpResult = $serviceProvier->lookUp($preciseLong, $preciseLat);
         \SystemLogger::debug("Making call with: ", $serviceProvier->getClassBasic());
         if ($lookUpResult && ($lookUpResult->getCity() || $lookUpResult->getPostalCode())) {
             //var_dump($lookUpResult);exit;
             return $this->cacheLookup($lookUpResult, $preciseLong, $preciseLat);
         } else {
             if ($lastError = $serviceProvier->getLastError(true)) {
                 \SystemLogger::warn("Error: {$lastError->getMessage()} TYPE: {$lastError->getType()}");
             }
             if ($lastError && !$lastError->isRateLimit()) {
                 break;
             }
         }
     }
     return null;
 }
コード例 #3
0
 public function dataLoaded(GeocodeCached $locationInfo, $date = null)
 {
     $queryWhere = $locationInfo->getQueryWhere();
     if ($date) {
         $queryWhere->where('load_date', $date);
     }
     return GeocodeLoaded::manager()->getEntityWhere($queryWhere) !== null;
 }
コード例 #4
0
 public function loadShowtimes(GeocodeCached $geocode, $currentDate = null, $dateOffset = 0)
 {
     $this->currentDate = \Utilities::dateFromOffset($currentDate, $dateOffset);
     $allCinemasFound = array();
     for ($i = 0; $i < self::MAX_PAGES; $i++) {
         $data = array('latlng' => $geocode->getGeocode(), 'date' => $dateOffset, 'start' => $i * self::PER_PAGE);
         $url = $this->formatUrl($this->showtimesUrl, $data, true);
         $pageData = $this->callUrl($url);
         //test if hasNextPage===
         $totalFound = count($allCinemasFound);
         $totalPages = 0;
         $allCinemasFound = array_merge($allCinemasFound, $this->extractTheatreMovieShowtimes($pageData, ShowtimeService::THEATRE_LIMIT - $totalFound, $totalPages));
         \SystemLogger::info("Total pages: ", $totalPages);
         if ($i >= $totalPages - 1) {
             break;
         }
     }
     return $allCinemasFound;
 }
コード例 #5
0
 /**
  * @param GeocodeCached $geocode
  * @param bool $forceUpdate
  * @return string timezone identifier
  */
 public function getTimeZone(GeocodeCached $geocode, $forceUpdate = false)
 {
     if (!$forceUpdate && $geocode->timezone) {
         return $geocode->timezone;
     }
     $timezone = $this->checkSingleCountryTimezone($geocode);
     if (!$timezone) {
         $timezone = $this->lookupTimeZoneByGeoCode($geocode->getGeocode());
     }
     //set time zone
     if ($timezone) {
         if ($geocode->city) {
             //update all cities wthin this country
             $where = \DbTableWhere::get()->where('country_iso', $geocode->country_iso)->where('city', $geocode->city);
             GeocodeCached::table()->update(['timezone' => $timezone], $where->getWhereString());
         } else {
             $geocode->update(['timezone' => $timezone]);
         }
     }
     return $timezone;
 }
コード例 #6
0
 /**
  *
  * @param TheatreNearby $tnb
  * @return GeocodeCached
  *
  */
 public static function getGeocodeCached(TheatreNearby $tnb)
 {
     $queryWhere = new \DbTableWhere();
     $queryWhere->where('country_iso', $tnb->country_iso);
     if ($tnb->postal_code) {
         $queryWhere->where(new \DbTableFunction("REPLACE(postal_code, ' ', '')"), str_replace(' ', '', $tnb->postal_code));
     } else {
         $queryWhere->where('city', $tnb->city);
     }
     $key = $queryWhere->getWhereString();
     if (array_key_exists($key, self::$cachedGeocodes)) {
         return self::$cachedGeocodes[$key];
     } else {
         return self::$cachedGeocodes[$key] = GeocodeCached::manager()->getEntityWhere($queryWhere);
     }
 }