public function testSearchDistance() { $country = CM_Model_Location::createCountry('Country', 'CR'); $source = CM_Model_Location::createCity($country, 'Source', 0, 0); $locationMiddle = CM_Model_Location::createCity($country, 'City', 0, 10); $locationFar = CM_Model_Location::createCity($country, 'City', 0, 100); $locationClose = CM_Model_Location::createCity($country, 'City', 0, 0); $this->_recreateLocationIndex(); $paging = new CM_Paging_Location_SearchText('City', CM_Model_Location::LEVEL_CITY, CM_Model_Location::LEVEL_CITY, $source); $expected = array($locationClose, $locationMiddle, $locationFar); $this->assertEquals($expected, $paging->getItems()); }
protected function _upgradeCityList() { $this->_streamOutput->writeln('Updating cities database…'); $count = $this->_count(array($this->_cityListByRegionRenamed, $this->_cityListByRegionUpdatedCode, $this->_cityListByRegionAdded), 4) + $this->_count($this->_cityListUpdatedRegion, 2); $item = 0; foreach ($this->_cityListByRegionRenamed as $cityListByRegionRenamed) { foreach ($cityListByRegionRenamed as $cityListRenamed) { foreach ($cityListRenamed as $cityCode => $cityNames) { $cityName = $cityNames['name']; CM_Db_Db::update('cm_model_location_city', array('name' => $cityName), array('_maxmind' => $cityCode)); $this->_printProgressCounter(++$item, $count); } } } unset($this->_cityListByRegionRenamed); foreach ($this->_cityListByRegionUpdatedCode as $cityListByRegionUpdatedCode) { foreach ($cityListByRegionUpdatedCode as $cityListUpdatedCode) { foreach ($cityListUpdatedCode as $cityCode) { $cityId = $this->_cityIdList[$cityCode]; CM_Db_Db::update('cm_model_location_city', array('_maxmind' => $cityCode), array('id' => $cityId)); $this->_printProgressCounter(++$item, $count); } } } unset($this->_cityListByRegionUpdatedCode); foreach ($this->_cityListUpdatedRegion as $countryCode => $cityListUpdatedRegion) { foreach ($cityListUpdatedRegion as $cityCode => $regionCodes) { $cityId = $this->_cityIdList[$cityCode]; $regionCode = $regionCodes['regionCode']; $regionName = $this->_getRegionName($countryCode, $regionCode); $cityName = $this->_cityListByRegion[$countryCode][$regionCode][$cityCode]; if ($regionName === 'Unknown region') { CM_Db_Db::update('cm_model_location_city', array('stateId' => null, 'name' => $cityName), array('id' => $cityId)); } else { $regionId = $this->_regionIdListByCountry[$countryCode][$regionCode]; CM_Db_Db::update('cm_model_location_city', array('stateId' => $regionId, 'name' => $cityName), array('id' => $cityId)); } $this->_printProgressCounter(++$item, $count); } } unset($this->_regionListByCountry); unset($this->_cityListByRegion); unset($this->_cityListUpdatedRegion); foreach ($this->_cityListByRegionAdded as $countryCode => $cityListByRegionAdded) { foreach ($cityListByRegionAdded as $regionCode => $cityListAdded) { if (isset($this->_regionIdListByCountry[$countryCode][$regionCode])) { $regionId = $this->_regionIdListByCountry[$countryCode][$regionCode]; $parentLocation = new CM_Model_Location(CM_Model_Location::LEVEL_STATE, $regionId); } else { $countryId = $this->_countryIdList[$countryCode]; $parentLocation = new CM_Model_Location(CM_Model_Location::LEVEL_COUNTRY, $countryId); } foreach ($cityListAdded as $cityCode => $cityName) { $cityData = $this->_locationTree[$countryCode]['regions'][$regionCode]['cities'][$cityName]['location']; $city = CM_Model_Location::createCity($parentLocation, $cityName, $cityData['latitude'], $cityData['longitude'], $cityData['maxMind']); $cityId = $city->getId(); $this->_cityIdList[$cityCode] = $cityId; $this->_printProgressCounter(++$item, $count); } } } unset($this->_regionIdListByCountry); unset($this->_cityListByRegionAdded); unset($this->_locationTree); }
public function testCreateZip() { $country = CM_Model_Location::createCountry('Example Country', 'EC'); $state = CM_Model_Location::createState($country, 'Example State', 'ES'); $city = CM_Model_Location::createCity($state, 'Example City', 50, 100); $zip = CM_Model_Location::createZip($city, '12333', 50, 100); $this->assertSame($country->getId(), $zip->getId(CM_Model_Location::LEVEL_COUNTRY)); $this->assertSame($state->getId(), $zip->getId(CM_Model_Location::LEVEL_STATE)); $this->assertSame($city->getId(), $zip->getId(CM_Model_Location::LEVEL_CITY)); $this->assertSame('12333', $zip->getName()); $this->assertSame(array('lat' => (double) 50, 'lon' => (double) 100), $zip->getCoordinates()); }