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