Ejemplo n.º 1
0
 public function getCountryName()
 {
     $c = $this->getCountry();
     return $c ? \GeoCountryModel::ISO2ToName($c) : 'Unknown';
 }
Ejemplo n.º 2
0
 public function getCountryName()
 {
     return $this->country ? \GeoCountryModel::ISO2ToName($this->country) : 'Unknown';
 }
Ejemplo n.º 3
0
 public function render()
 {
     // Make sure that some defaults are set first.
     if (!$this->get('name')) {
         $this->set('name', 'address');
     }
     if ($this->_model && ($this->_model->exists() || $this->_model->changed())) {
         // There is a valid model set, I can pull all the values from that!
         // This should also be used if the model was created but doesn't exist in the database, but was changed.
         // ie: a user entered information on a new model, but had an error that kicked it back.
         // that model may not exist, but it has been changed with the user's data, and so needs to be preserved.
         $v = $this->_model->getAsArray();
     } else {
         // There is no model currently set, fine... I'll just use some defaults.
         $v = ['id' => '', 'label' => '', 'address1' => '', 'address2' => '', 'city' => REMOTE_CITY, 'province' => REMOTE_PROVINCE, 'postal' => '', 'country' => REMOTE_COUNTRY];
     }
     $id = $v['id'];
     $label = $v['label'];
     $address1 = $v['address1'];
     $address2 = $v['address2'];
     $city = $v['city'];
     $province = $v['province'];
     $postal = $v['postal'];
     $country = $v['country'];
     // Get the provinces for the given selected country, (to save an ajax call)
     $provinces = GeoProvinceModel::Find(['country = ' . $country]);
     $countries = GeoCountryModel::Find(null, null, 'name');
     // Convert the provinces to JSON data so the javascript
     // can use it as if it had loaded from the server.
     $provincejs = [];
     foreach ($provinces as $p) {
         /** @var GeoProvinceModel $p */
         $provincejs[] = $p->getAsArray();
     }
     $file = $this->getTemplateName();
     $tpl = \Core\Templates\Template::Factory($file);
     $tpl->assign('id', $id);
     $tpl->assign('use_label', $this->_attributes['use_label']);
     $tpl->assign('label', $label);
     $tpl->assign('address1', $address1);
     $tpl->assign('address2', $address2);
     $tpl->assign('city', $city);
     $tpl->assign('province', $province);
     $tpl->assign('postal', $postal);
     $tpl->assign('country', $country);
     $tpl->assign('provinces', $provinces);
     $tpl->assign('province_json', json_encode($provincejs));
     $tpl->assign('countries', $countries);
     $tpl->assign('element', $this);
     $tpl->assign('req', $this->get('required'));
     return $tpl->fetch();
 }