コード例 #1
0
 /**
  * @param Theatre $theatre
  * @return bool|mixed|\mysqli_result
  */
 public static function setTheatreLatLng(Theatre $theatre)
 {
     //51.4752267,-0.2396438
     \SystemLogger::info("Finding LongLat for: ", $theatre->name, $theatre->address);
     $geocode = LocationService::instance()->addressLookup($theatre->address, [], true);
     $saved = false;
     if ($geocode) {
         $geoLocation = $geocode->getGeocode();
         \SystemLogger::info("Found Geocode: ", strval($geoLocation));
         $saved = $theatre->update(['longitude' => $geoLocation->getLongitude(), 'latitude' => $geoLocation->getLatitude()], 'id');
     }
     return $saved;
 }
コード例 #2
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;
 }
コード例 #3
0
 public static function getOrCreate($theatreData, $locationInfo = null, $lookUpAddress = false, $computeDistance = false)
 {
     $manager = self::manager();
     $findWhere = (new \DbTableWhere())->where('name', $theatreData['name'])->where('address', $theatreData['address']);
     if ($foundTheatre = $manager->getEntityWhere($findWhere)) {
         TheatreNearby::getOrCreate($locationInfo, $foundTheatre, $computeDistance);
         return $foundTheatre;
     }
     if ($lookUpAddress && (!$theatreData['longitude'] || !$theatreData['latitude'])) {
         $geoCode = LocationService::instance()->addressLookup($theatreData['address']);
         if ($geoCode) {
             $theatreData['longitude'] = $geoCode->found_longitude;
             $theatreData['latitude'] = $geoCode->found_latitude;
         }
     }
     $theatreId = $manager->createEntity($theatreData)->save();
     if ($theatreId) {
         $theatre = $manager->getEntity($theatreId);
         TheatreNearby::getOrCreate($locationInfo, $theatre, $computeDistance);
         return $theatre;
     }
     return null;
 }
コード例 #4
0
 protected function _initGeocode()
 {
     $locationService = LocationService::instance();
     if ($this->_request->hasQueryParam('latlng')) {
         $latLng = $this->_request->getQueryParam('latlng');
         $this->geocode = $locationService->lookUp($latLng);
     }
     if (!$this->geocode && ($this->_request->hasQueryParam('city') || $this->_request->hasQueryParam('country') || $this->_request->hasQueryParam('postalCode'))) {
         $countryIso = $this->_request->getQueryParam('country');
         $city = $this->_request->getQueryParam('city');
         $postalCode = $this->_request->getQueryParam('postalCode');
         $this->geocode = $locationService->postalCodeLookup($postalCode, $countryIso, $city);
     }
 }