public function asLocation() { $location = null; if (!empty($this->location_id) && !empty($this->location_ns)) { $location = Location::fromId($this->location_id, $this->location_ns); } if (is_null($location)) { // no ID, or Location::fromId() failed $location = Location::fromLatLon($this->lat, $this->lon); } if (is_null($location)) { throw new ServerException('Location could not be looked up from existing data.'); } return $location; }
static function locationOptions($lat, $lon, $location_id, $location_ns, $profile = null) { $options = array(); if (!empty($location_id) && !empty($location_ns)) { $options['location_id'] = $location_id; $options['location_ns'] = $location_ns; $location = Location::fromId($location_id, $location_ns); if ($location instanceof Location) { $options['lat'] = $location->lat; $options['lon'] = $location->lon; } } else { if (!empty($lat) && !empty($lon)) { $options['lat'] = $lat; $options['lon'] = $lon; $location = Location::fromLatLon($lat, $lon); if ($location instanceof Location) { $options['location_id'] = $location->location_id; $options['location_ns'] = $location->location_ns; } } else { if (!empty($profile)) { if (isset($profile->lat) && isset($profile->lon)) { $options['lat'] = $profile->lat; $options['lon'] = $profile->lon; } if (isset($profile->location_id) && isset($profile->location_ns)) { $options['location_id'] = $profile->location_id; $options['location_ns'] = $profile->location_ns; } } } } return $options; }
/** * @dataProvider locationIds */ public function testLocationFromId($id, $ns, $language, $location) { $result = Location::fromId($id, $ns, $language); $this->assertEquals($result, $location); }
function getLocation() { $location = null; if (!empty($this->location_id) && !empty($this->location_ns)) { $location = Location::fromId($this->location_id, $this->location_ns); } if (is_null($location)) { // no ID, or Location::fromId() failed if (!empty($this->lat) && !empty($this->lon)) { $location = Location::fromLatLon($this->lat, $this->lon); } } if (is_null($location)) { // still haven't found it! if (!empty($this->location)) { $location = Location::fromName($this->location); } } return $location; }