Country.php
Go to the documentation of this file.
1<?php
10
39class Country extends Single
40{
44 protected $list = array();
45
51 public static function getCountries($iso = null)
52 {
53 $countries = array(
54 'ad' => _("Andorra"),
55 'ae' => _("United Arab Emirates"),
56 'af' => _("Afghanistan"),
57 'ag' => _("Antigua &amp; Barbuda"),
58 'ai' => _("Anguilla"),
59 'al' => _("Albania"),
60 'am' => _("Armenia"),
61 'an' => _("Netherlands Antilles"),
62 'ao' => _("Angola"),
63 'aq' => _("Antarctica"),
64 'ar' => _("Argentina"),
65 'as' => _("American Samoa"),
66 'at' => _("Austria"),
67 'au' => _("Australia"),
68 'aw' => _("Aruba"),
69 'az' => _("Azerbaijan"),
70 'ba' => _("Bosnia and Herzegovina"),
71 'bb' => _("Barbados"),
72 'bd' => _("Bangladesh"),
73 'be' => _("Belgium"),
74 'bf' => _("Burkina Faso"),
75 'bg' => _("Bulgaria"),
76 'bh' => _("Bahrain"),
77 'bi' => _("Burundi"),
78 'bj' => _("Benin"),
79 'bm' => _("Bermuda"),
80 'bn' => _("Brunei Darussalam"),
81 'bo' => _("Bolivia"),
82 'br' => _("Brazil"),
83 'bs' => _("Bahama"),
84 'bt' => _("Bhutan"),
85 'bv' => _("Bouvet Island"),
86 'bw' => _("Botswana"),
87 'by' => _("Belarus"),
88 'bz' => _("Belize"),
89 'ca' => _("Canada"),
90 'cc' => _("Cocos (Keeling) Islands"),
91 'cf' => _("Central African Republic"),
92 'cg' => _("Congo"),
93 'ch' => _("Switzerland"),
94 'ci' => _("Côte D\'ivoire (Ivory Coast)"),
95 'ck' => _("Cook Iislands"),
96 'cl' => _("Chile"),
97 'cm' => _("Cameroon"),
98 'cn' => _("China"),
99 'co' => _("Colombia"),
100 'cr' => _("Costa Rica"),
101 'cu' => _("Cuba"),
102 'cv' => _("Cape Verde"),
103 'cx' => _("Christmas Island"),
104 'cy' => _("Cyprus"),
105 'cz' => _("Czech Republic"),
106 'de' => _("Germany"),
107 'dj' => _("Djibouti"),
108 'dk' => _("Denmark"),
109 'dm' => _("Dominica"),
110 'do' => _("Dominican Republic"),
111 'dz' => _("Algeria"),
112 'ec' => _("Ecuador"),
113 'ee' => _("Estonia"),
114 'eg' => _("Egypt"),
115 'eh' => _("Western Sahara"),
116 'er' => _("Eritrea"),
117 'es' => _("Spain"),
118 'et' => _("Ethiopia"),
119 'fi' => _("Finland"),
120 'fj' => _("Fiji"),
121 'fk' => _("Falkland Islands"),
122 'fm' => _("Micronesia"),
123 'fo' => _("Faroe Islands"),
124 'fr' => _("France"),
125 'fx' => _("France, Metropolitan"),
126 'ga' => _("Gabon"),
127 'gb' => _("United Kingdom"),
128 'gd' => _("Grenada"),
129 'ge' => _("Georgia"),
130 'gf' => _("French Guiana"),
131 'gh' => _("Ghana"),
132 'gi' => _("Gibraltar"),
133 'gl' => _("Greenland"),
134 'gm' => _("Gambia"),
135 'gn' => _("Guinea"),
136 'gp' => _("Guadeloupe"),
137 'gq' => _("Equatorial Guinea"),
138 'gr' => _("Greece"),
139 'gs' => _("South Georgia and the South Sandwich Islands"),
140 'gt' => _("Guatemala"),
141 'gu' => _("Guam"),
142 'gw' => _("Guinea-Bissau"),
143 'gy' => _("Guyana"),
144 'hk' => _("Hong Kong"),
145 'hm' => _("Heard &amp; McDonald Islands"),
146 'hn' => _("Honduras"),
147 'hr' => _("Croatia"),
148 'ht' => _("Haiti"),
149 'hu' => _("Hungary"),
150 'id' => _("Indonesia"),
151 'ie' => _("Ireland"),
152 'il' => _("Israel"),
153 'in' => _("India"),
154 'io' => _("British Indian Ocean Territory"),
155 'iq' => _("Iraq"),
156 'ir' => _("Islamic Republic of Iran"),
157 'is' => _("Iceland"),
158 'it' => _("Italy"),
159 'jm' => _("Jamaica"),
160 'jo' => _("Jordan"),
161 'jp' => _("Japan"),
162 'ke' => _("Kenya"),
163 'kg' => _("Kyrgyzstan"),
164 'kh' => _("Cambodia"),
165 'ki' => _("Kiribati"),
166 'km' => _("Comoros"),
167 'kn' => _("St. Kitts and Nevis"),
168 'kp' => _("Korea, Democratic People\'s Republic of"),
169 'kr' => _("Korea, Republic of"),
170 'kw' => _("Kuwait"),
171 'ky' => _("Cayman Islands"),
172 'kz' => _("Kazakhstan"),
173 'la' => _("Lao People\'s Democratic Republic"),
174 'lb' => _("Lebanon"),
175 'lc' => _("Saint Lucia"),
176 'li' => _("Liechtenstein"),
177 'lk' => _("Sri Lanka"),
178 'lr' => _("Liberia"),
179 'ls' => _("Lesotho"),
180 'lt' => _("Lithuania"),
181 'lu' => _("Luxembourg"),
182 'lv' => _("Latvia"),
183 'ly' => _("Libyan Arab Jamahiriya"),
184 'ma' => _("Morocco"),
185 'mc' => _("Monaco"),
186 'md' => _("Moldova, Republic of"),
187 'mg' => _("Madagascar"),
188 'mh' => _("Marshall Islands"),
189 'ml' => _("Mali"),
190 'mn' => _("Mongolia"),
191 'mm' => _("Myanmar"),
192 'mo' => _("Macau"),
193 'mp' => _("Northern Mariana Islands"),
194 'mq' => _("Martinique"),
195 'mr' => _("Mauritania"),
196 'ms' => _("Monserrat"),
197 'mt' => _("Malta"),
198 'mu' => _("Mauritius"),
199 'mv' => _("Maldives"),
200 'mw' => _("Malawi"),
201 'mx' => _("Mexico"),
202 'my' => _("Malaysia"),
203 'mz' => _("Mozambique"),
204 'na' => _("Namibia"),
205 'nc' => _("New Caledonia"),
206 'ne' => _("Niger"),
207 'nf' => _("Norfolk Island"),
208 'ng' => _("Nigeria"),
209 'ni' => _("Nicaragua"),
210 'nl' => _("Netherlands"),
211 'no' => _("Norway"),
212 'np' => _("Nepal"),
213 'nr' => _("Nauru"),
214 'nu' => _("Niue"),
215 'nz' => _("New Zealand"),
216 'om' => _("Oman"),
217 'pa' => _("Panama"),
218 'pe' => _("Peru"),
219 'pf' => _("French Polynesia"),
220 'pg' => _("Papua New Guinea"),
221 'ph' => _("Philippines"),
222 'pk' => _("Pakistan"),
223 'pl' => _("Poland"),
224 'pm' => _("St. Pierre &amp; Miquelon"),
225 'pn' => _("Pitcairn"),
226 'pr' => _("Puerto Rico"),
227 'pt' => _("Portugal"),
228 'pw' => _("Palau"),
229 'py' => _("Paraguay"),
230 'qa' => _("Qatar"),
231 're' => _("Réunion"),
232 'ro' => _("Romania"),
233 'ru' => _("Russian Federation"),
234 'rw' => _("Rwanda"),
235 'sa' => _("Saudi Arabia"),
236 'sb' => _("Solomon Islands"),
237 'sc' => _("Seychelles"),
238 'sd' => _("Sudan"),
239 'se' => _("Sweden"),
240 'sg' => _("Singapore"),
241 'sh' => _("St. Helena"),
242 'si' => _("Slovenia"),
243 'sj' => _("Svalbard &amp; Jan Mayen Islands"),
244 'sk' => _("Slovakia"),
245 'sl' => _("Sierra Leone"),
246 'sm' => _("San Marino"),
247 'sn' => _("Senegal"),
248 'so' => _("Somalia"),
249 'sr' => _("Suriname"),
250 'st' => _("Sao Tome &amp; Principe"),
251 'sv' => _("El Salvador"),
252 'sy' => _("Syrian Arab Republic"),
253 'sz' => _("Swaziland"),
254 'tc' => _("Turks &amp; Caicos Islands"),
255 'td' => _("Chad"),
256 'tf' => _("French Southern Territories"),
257 'tg' => _("Togo"),
258 'th' => _("Thailand"),
259 'tj' => _("Tajikistan"),
260 'tk' => _("Tokelau"),
261 'tm' => _("Turkmenistan"),
262 'tn' => _("Tunisia"),
263 'to' => _("Tonga"),
264 'tp' => _("East Timor"),
265 'tr' => _("Turkey"),
266 'tt' => _("Trinidad &amp; Tobago"),
267 'tv' => _("Tuvalu"),
268 'tw' => _("Taiwan, Province of China"),
269 'tz' => _("Tanzania, United Republic of"),
270 'ua' => _("Ukraine"),
271 'ug' => _("Uganda"),
272 'um' => _("United States Minor Outlying Islands"),
273 'us' => _("United States of America"),
274 'uy' => _("Uruguay"),
275 'uz' => _("Uzbekistan"),
276 'va' => _("Vatican City State (Holy See)"),
277 'vc' => _("St. Vincent &amp; the Grenadines"),
278 've' => _("Venezuela"),
279 'vg' => _("British Virgin Islands"),
280 'vi' => _("United States Virgin Islands"),
281 'vn' => _("Viet Nam"),
282 'vu' => _("Vanuatu"),
283 'wf' => _("Wallis &amp; Futuna Islands"),
284 'ws' => _("Samoa"),
285 'ye' => _("Yemen"),
286 'yt' => _("Mayotte"),
287 'yu' => _("Yugoslavia"),
288 'za' => _("South Africa"),
289 'zm' => _("Zambia"),
290 'zr' => _("Zaire"),
291 'zw' => _("Zimbabwe")
292 );
293
294 // return a subset
295 if ($iso !== null) {
296 if (is_array($iso)) {
297 return array_intersect_key($countries, $iso);
298 } else {
299 return isset($countries[$iso]) ? $countries[$iso] : '';
300 }
301 }
302
303 return $countries;
304 }
305
314 public function __construct($name, $parameters, $form)
315 {
316 parent::__construct($name, $parameters, $form);
317
318 if (isset($parameters['defaultValue'])) {
319 $this->defaults['defaultValue'] = $parameters['defaultValue'];
320 }
321
322 if (isset($parameters['priorityCountries'])) {
323 $this->defaults['priorityCountries'] = $parameters['priorityCountries'];
324 }
325
326 $this->list = isset($parameters['countries'])
327 ? $parameters['countries']
329
330 // make sure all keys are lower case
331 $this->list = array_change_key_case($this->list, CASE_LOWER);
332
333 // sort alphabetically
334 asort($this->list);
335
336 // move priority countries to the top based on options and language
337 if (defined("DEPAGE_LANG") && isset($parameters['priorityCountries'][DEPAGE_LANG])) {
338 $priorityCountries = array_reverse($parameters['priorityCountries'][DEPAGE_LANG], true);
339 // make sure all keys are lower case to match countries
340 $priorityCountries = array_change_key_case($priorityCountries, CASE_LOWER);
341
342 foreach ($priorityCountries as &$country_code) {
343 if (isset($this->list[$country_code])) {
344 $top = array($country_code => $this->list[$country_code]);
345 unset($this->list[$country_code]);
346 $this->list = $top + $this->list;
347 }
348 }
349 }
350
351 $this->list = array('' => _("Please Select")) + $this->list;
352 }
353
363 protected function setDefaults()
364 {
365 parent::setDefaults();
366
367 $this->defaults['skin'] = 'select';
368 }
369}
370
371/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
HTML-multiple-choice country input select .
Definition Country.php:40
$list
Contains list of ISO countries.
Definition Country.php:44
__construct($name, $parameters, $form)
multiple class constructor
Definition Country.php:314
static getCountries($iso=null)
Gets the Default Countries list.
Definition Country.php:51
setDefaults()
collects initial values across subclasses.
Definition Country.php:363
HTML-single-choice input type i.e.
Definition Single.php:56
Classes for HTML input-elements.
Definition Address.php:9