/** * callback that creates / re-creates the data map mapping all active country ids to all active countries * * @access private * @since 3.8.14 * * @param WPSC_Data_Map $data_map Data map object being intitilized */ public static function _create_active_countries_map($data_map) { global $wpdb; // there are also invisible countries $sql = 'SELECT ' . ' id, country, isocode, currency, symbol, symbol_html, code, has_regions, tax, continent, visible ' . ' FROM `' . WPSC_TABLE_CURRENCY_LIST . '` WHERE `visible`= "1" ' . ' ORDER BY id ASC'; $countries_array = $wpdb->get_results($sql, OBJECT_K); // build an array to map from iso code to country, while we do this get any region data for the country foreach ($countries_array as $country_id => $country) { // create a new empty country object, add the properties we know about, then we add our region info $wpsc_country = new WPSC_Country(null); $wpsc_country->_copy_properties_from_stdclass($country); if ($country->has_regions) { $sql = 'SELECT id, code, country_id, name, tax ' . ' FROM `' . WPSC_TABLE_REGION_TAX . '` ' . ' WHERE `country_id` = %d ' . ' ORDER BY code ASC '; // put the regions list into our country object $regions = $wpdb->get_results($wpdb->prepare($sql, $country_id), OBJECT_K); /* * any properties that came in as text that should be numbers or boolean * get adjusted here, we also build an array to map from region code to region id */ foreach ($regions as $region_id => $region) { $region->id = intval($region_id); $region->country_id = intval($region->country_id); $region->tax = floatval($region->tax); // create a new empty region object, then copy our region data into it. $wpsc_region = new WPSC_Region(null, null); $wpsc_region->_copy_properties_from_stdclass($region); $wpsc_country->_regions->map($region->id, $wpsc_region); $wpsc_country->_region_id_by_region_code->map($region->code, $region->id); $wpsc_country->_region_id_by_region_name->map(strtolower($region->name), $region->id); } } $data_map->map($country_id, $wpsc_country); } self::$_dirty = true; }