/** * @return org_routamc_positioning_country_dba Country the city is in */ function get_parent_guid_uncached() { if ($this->country) { $qb = org_routamc_positioning_country_dba::new_query_builder(); $qb->add_constraint('code', '=', $this->country); $countries = $qb->execute(); if (count($countries) == 0) { debug_add("Could not load Country ID {$this->country} from the database, aborting.", MIDCOM_LOG_INFO); return null; } return $countries[0]->guid; } return null; }
static function get_by_name($name) { // Seek by strict city name first $qb = org_routamc_positioning_country_dba::new_query_builder(); $qb->add_constraint('name', 'LIKE', $name); $qb->set_limit(1); $matches = $qb->execute_unchecked(); if (count($matches) > 0) { return $matches[0]; } // Strict name didn't match, seek by alternate names $qb = org_routamc_positioning_country_dba::new_query_builder(); $qb->add_constraint('alternatenames', 'LIKE', "%{$name}%"); // Most likely we're interested in the biggest city that matches $qb->add_order('population', 'DESC'); $qb->set_limit(1); $matches = $qb->execute_unchecked(); if (count($matches) > 0) { return $matches[0]; } return false; }
public function __construct($args) { $this->_component = 'org.routamc.positioning'; parent::__construct(); $this->_data = array(); if (isset($args['start_message'])) { if (is_bool($args['start_message']) && $args['start_message']) { $this->_data[''] = $this->_l10n->get('select your country'); } else { if (is_string($args['start_message'])) { $this->_data[''] = $args['start_message']; } } } $qb = org_routamc_positioning_country_dba::new_query_builder(); $qb->add_constraint('code', '<>', ''); $qb->add_order('name', 'ASC'); $countries = $qb->execute_unchecked(); if (count($countries) == 0) { debug_add('No countries found. You have to use org.routamc.positioning to import countries to database.'); } $this->_populate_data($countries); }
function _get_country_list() { $this->_countrylist = array('' => midcom::get('i18n')->get_string('select your country', 'org.routamc.positioning')); $qb = org_routamc_positioning_country_dba::new_query_builder(); $qb->add_constraint('code', '<>', ''); $qb->add_order('name', 'ASC'); $countries = $qb->execute_unchecked(); if (count($countries) == 0) { debug_add('Cannot render country list: No countries found. You have to use org.routamc.positioning to import countries to database.'); } foreach ($countries as $country) { $this->_countrylist[$country->code] = $country->name; } }
/** * Modify country to conform to ISO standards */ function normalize_country($country) { if (strlen($country) == 2) { // Probably an ISO code return $country; } $qb = org_routamc_positioning_country_dba::new_query_builder(); $qb->add_constraint('name', '=', $country); $countries = $qb->execute(); if (count($countries) > 0) { return $countries[0]->code; } return ''; }