Example #1
0
 public function getHtml()
 {
     if ($this->value && !is_array($this->value)) {
         $this->value = array($this->value => (string) $this->value);
     } else {
         $this->value = array();
     }
     $this->zone_name = !$this->zone_name ? '' : urlencode($this->zone_name);
     $this->options = !$this->options ? array() : $this->options;
     $this->element_id = preg_replace('/[\\[+\\]+]/', '_', $this->element_id);
     $html = new AHtml($this->data['registry']);
     if ($this->submit_mode == 'id') {
         $url = $html->getSecureURL('common/zone');
     } else {
         $url = $html->getSecureURL('common/zone/names');
     }
     $this->data['registry']->get('load')->model('localisation/zone');
     $results = array();
     if ($this->submit_mode == 'id') {
         $id = $this->value ? key($this->value) : $this->data['registry']->get('config')->get('config_country_id');
         $results = $this->data['registry']->get('model_localisation_zone')->getZonesByCountryId($id);
     } else {
         if ($this->value) {
             $name = current($this->value);
         } else {
             $this->data['registry']->get('load')->model('localisation/country');
             $temp = $this->data['registry']->get('model_localisation_country')->getCountry($this->data['registry']->get('config')->get('config_country_id'));
             $name = $temp['name'];
         }
         $results = $this->data['registry']->get('model_localisation_zone')->getZonesByCountryName($name);
     }
     if (!is_array($this->zone_value)) {
         $this->zone_value = $this->zone_value ? array($this->zone_value => (string) $this->zone_value) : array();
     }
     $config_zone_id = $this->data['registry']->get('config')->get('config_zone_id');
     foreach ($results as $result) {
         // default zone_id is zone of shop
         if ($result['zone_id'] == $config_zone_id) {
             $this->default_zone_value = $this->submit_mode == 'id' ? array($config_zone_id) : array($result['name'] => $result['name']);
             $this->default_zone_name = $result['name'];
         }
         if ($this->submit_mode == 'id') {
             $this->zone_options[$result['zone_id']] = $result['name'];
         } else {
             $this->zone_options[$result['name']] = $result['name'];
         }
     }
     $this->view->batchAssign(array('name' => $this->name, 'id' => $this->element_id, 'value' => $this->value ? $this->value : $this->default_value, 'options' => $this->options, 'attr' => $this->attr, 'required' => $this->required, 'style' => $this->style, 'url' => $url, 'zone_name' => $this->zone_name ? $this->zone_name : $this->default_zone_name, 'zone_value' => $this->zone_value ? $this->zone_value : $this->default_zone_value, 'zone_options' => $this->zone_options, 'submit_mode' => $this->submit_mode, 'placeholder' => $this->placeholder));
     if (!empty($this->help_url)) {
         $this->view->assign('help_url', $this->help_url);
     }
     $return = $this->view->fetch('form/countries_zones.tpl');
     return $return;
 }