public static function getTop($contact)
 {
     $top = array();
     static $fields = null;
     if ($fields === null) {
         $fields = array(waContactFields::getAll('person', true), waContactFields::getAll('company', true));
     }
     $country_model = new waCountryModel();
     $iso3letters_map = $country_model->select('DISTINCT iso3letter')->fetchAll('iso3letter', true);
     foreach ($fields[intval($contact['is_company'])] as $f) {
         $info = $f->getInfo();
         if ($f->getParameter('top') && ($value = $contact->get($info['id'], 'top,html'))) {
             if ($info['type'] == 'Address') {
                 $data = $contact->get($info['id']);
                 $data_for_map = $contact->get($info['id'], 'forMap');
                 $value = (array) $value;
                 foreach ($value as $k => &$v) {
                     if (isset($data[$k]['data']['country']) && isset($iso3letters_map[$data[$k]['data']['country']])) {
                         $v = '<img src="' . wa_url() . 'wa-content/img/country/' . strtolower($data[$k]['data']['country']) . '.gif" /> ' . $v;
                     }
                     $map_url = '';
                     if (is_string($data_for_map[$k])) {
                         $map_url = $data_for_map[$k];
                     } else {
                         if (!empty($data_for_map[$k]['coords'])) {
                             $map_url = $data_for_map[$k]['coords'];
                         } else {
                             if (!empty($data_for_map[$k]['with_street'])) {
                                 $map_url = $data_for_map[$k]['with_street'];
                             }
                         }
                     }
                     $v .= ' <a target="_blank" href="//maps.google.com/maps?q=' . urlencode($map_url) . '&z=15" class="small underline map-link">' . _w('map') . '</a>';
                     $v = '<div data-subfield-index=' . $k . '>' . $v . '</div>';
                 }
                 unset($v);
             }
             $delimiter = $info['type'] == 'Composite' || $info['type'] == 'Address' ? "<br>" : ", ";
             $top[] = array('id' => $info['id'], 'name' => $f->getName(), 'value' => is_array($value) ? implode($delimiter, $value) : $value, 'icon' => $info['type'] == 'Email' || $info['type'] == 'Phone' ? strtolower($info['type']) : '', 'pic' => '');
         }
     }
     return $top;
 }
 public static function settingCountrySelect()
 {
     $country_model = new waCountryModel();
     return $country_model->select('iso3letter AS value, name AS title')->fetchAll('value');
 }
 /**
  * @param string $iso3
  * @throws waException
  * @return string
  */
 private function getISO2CountryCode($iso3)
 {
     $country_model = new waCountryModel();
     $iso2 = $country_model->select('iso2letter')->where('iso3letter = :iso3', array('iso3' => $iso3))->fetchField('iso2letter');
     if (!$iso2) {
         throw new waException($this->_w("Unknown country"));
     }
     return $iso2;
 }