00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class Mage_Adminhtml_Model_System_Config_Source_Allregion
00029 {
00030 protected $_countries;
00031 protected $_options;
00032
00033 public function toOptionArray($isMultiselect=false)
00034 {
00035 if (!$this->_options) {
00036 $countriesArray = Mage::getResourceModel('directory/country_collection')->load()
00037 ->toOptionArray(false);
00038 $this->_countries = array();
00039 foreach ($countriesArray as $a) {
00040 $this->_countries[$a['value']] = $a['label'];
00041 }
00042
00043 $countryRegions = array();
00044 $regionsCollection = Mage::getResourceModel('directory/region_collection')->load();
00045 foreach ($regionsCollection as $region) {
00046 $countryRegions[$region->getCountryId()][$region->getId()] = $region->getDefaultName();
00047 }
00048 uksort($countryRegions, array($this, 'sortRegionCountries'));
00049
00050 $this->_options = array();
00051 foreach ($countryRegions as $countryId=>$regions) {
00052 $regionOptions = array();
00053 foreach ($regions as $regionId=>$regionName) {
00054 $regionOptions[] = array('label'=>$regionName, 'value'=>$regionId);
00055 }
00056 $this->_options[] = array('label'=>$this->_countries[$countryId], 'value'=>$regionOptions);
00057 }
00058 }
00059 $options = $this->_options;
00060 if(!$isMultiselect){
00061 array_unshift($options, array('value'=>'', 'label'=>''));
00062 }
00063
00064 return $options;
00065 }
00066
00067 public function sortRegionCountries($a, $b)
00068 {
00069 return strcmp($this->_countries[$a], $this->_countries[$b]);
00070 }
00071 }