// Reading out all Countries, States and Regions for SelectBox
$regionselect = array('' => __('please_choose'));
$country_array = array();
$countries = \Destinations\Model_Country::find('all');
foreach ($countries as $i => $obj)
{
$all_countries[$i] = $obj->to_array();
}
foreach ($all_countries as $value)
{
$states = \Destinations\Model_State::find('all', array('where' => array(array('country_id', $value['id']),),));
if(!empty($states)){
$country_array[$value['name']] = array();
}
$state_array = array();
foreach ($states as $i => $obj)
{
$all_states[$i] = $obj->to_array();
$all_states[$i]['name'] = ' '.$all_states[$i]['name'];
$regions = \Destinations\Model_Region::find('all', array('where' => array(array('state_id', $all_states[$i]['id']),),));
if(!empty($regions)){
$state_array[$all_states[$i]['name']] = array();
}
$region_array = array();
foreach ($regions as $i => $obj)
{
$all_regions[$i] = $obj->to_array();
$region_array[$all_regions[$i]['id']] = ' '.$all_regions[$i]['name'];
}
$state_array = $state_array + $region_array;
}
$country_array = $country_array + $state_array;
}
$data['regions'] = $regionselect + $country_array;
$options = array();You probably have to do a bit more if you want to be able to select the region if a region doesn't have any cities defined.
foreach ($countries as $country)
{
$options[$country->name] = array();
foreach ($country->states as $state)
{
$options[$country->name][$state->name] = array();
foreach ($state->regions as $region)
{
$options[$country->name][$state->name][$region->name] = array();
foreach ($region->cities as $city)
{
$options[$country->name][$state->name][$region->name][$city->id] = $city->name;
}
}
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!