function _get_city_by_name($city_name, $results = array()) { if (empty($city_name)) { return 0; } $city_id = 0; $city = org_routamc_positioning_city_dba::get_by_name($city_name); if ($city && $city->id) { $city_id = $city->id; } else { if (!empty($results)) { $city = new org_routamc_positioning_city_dba(); $city->city = $city_name; if (isset($results["{$this->_element_id}_input_place_country"]) && $results["{$this->_element_id}_input_place_country"]) { $city->country = $results["{$this->_element_id}_input_place_country"]; } if (isset($results["{$this->_element_id}_input_place_region"])) { $city->region = $results["{$this->_element_id}_input_place_region"]; } if (isset($results["{$this->_element_id}_input_coordinates_latitude"]) && $results["{$this->_element_id}_input_coordinates_latitude"] != '') { $city->latitude = $results["{$this->_element_id}_input_coordinates_latitude"]; } if (isset($results["{$this->_element_id}_input_coordinates_longitude"]) && $results["{$this->_element_id}_input_coordinates_longitude"] != '') { $city->longitude = $results["{$this->_element_id}_input_coordinates_longitude"]; } if (!$city->create()) { debug_add("Cannot save new city '{$city_name}'"); } $city_id = $city->id; } } return $city_id; }
$alternate_names = explode(',', $data[$fields_map['alternatenames']]); if (count($alternate_names) > 0) { foreach ($alternate_names as $name) { $new_city->alternatenames .= "|{$name}"; } if (!empty($data[$fields_map['asciiname']])) { $new_city->alternatenames .= '|' . $data[$fields_map['asciiname']]; } $new_city->alternatenames .= '|'; } if (array_key_exists("{$new_city->country}:{$data[3]}:{$new_city->city}", $imported_cities) || $row == 1) { // We have city by this name for the country already continue; } echo "{$row}: Adding {$new_city->city}, {$new_city->country}... "; if ($new_city->create()) { echo "<span style=\"color: #00cc00;\">Success,</span> "; $imported_cities["{$new_city->country}:{$data[3]}:{$new_city->city}"] = true; $cities_created++; } else { echo "<span style=\"color: #cc0000;\">FAILED</span>, "; } echo midcom_connection::get_error_string() . "<br />\n"; flush(); } echo "<p>{$cities_created} cities imported.</p>\n"; } else { ?> <h1>World Cities Database installation</h1> <p>