State.php
Go to the documentation of this file.
1<?php
10
35class State extends Single
36{
40 protected $list = array();
41
47 public static function getStates($iso = null)
48 {
49 $country_states = array(
50 // http://en.wikipedia.org/wiki/ISO_3166-2:DE
51 'de' => array(
52 'de-bw' => _("Baden-Württemberg"),
53 'de-by' => _("Bayern"),
54 'de-be' => _("Berlin"),
55 'de-bb' => _("Brandenburg"),
56 'de-hb' => _("Bremen"),
57 'de-hh' => _("Hamburg"),
58 'de-he' => _("Hessen"),
59 'de-mv' => _("Mecklenburg-Vorpommern"),
60 'de-ni' => _("Niedersachsen"),
61 'de-nw' => _("Nordrhein-Westfalen"),
62 'de-rp' => _("Rheinland-Pfalz"),
63 'de-sl' => _("Saarland"),
64 'de-sn' => _("Sachsen"),
65 'de-st' => _("Sachsen-Anhalt"),
66 'de-sh' => _("Schleswig-Holstein"),
67 'de-th' => _("Thüringen")
68 ),
69 // http://en.wikipedia.org/wiki/ISO_3166-2:US
70 'us' => array(
71 'us-al' => _("Alabama"),
72 'us-ak' => _("Alaska"),
73 'us-az' => _("Arizona"),
74 'us-ar' => _("Arkansas"),
75 'us-ca' => _("California"),
76 'us-co' => _("Colorado"),
77 'us-ct' => _("Connecticut"),
78 'us-de' => _("Delaware"),
79 'us-fl' => _("Florida"),
80 'us-ga' => _("Georgia"),
81 'us-hi' => _("Hawaii"),
82 'us-id' => _("Idaho"),
83 'us-il' => _("Illinois"),
84 'us-in' => _("Indiana"),
85 'us-ia' => _("Iowa"),
86 'us-ks' => _("Kansas"),
87 'us-ky' => _("Kentucky"),
88 'us-la' => _("Louisiana"),
89 'us-me' => _("Maine"),
90 'us-md' => _("Maryland"),
91 'us-ma' => _("Massachusetts"),
92 'us-mi' => _("Michigan"),
93 'us-mn' => _("Minnesota"),
94 'us-ms' => _("Mississippi"),
95 'us-mo' => _("Missouri"),
96 'us-mt' => _("Montana"),
97 'us-ne' => _("Nebraska"),
98 'us-nv' => _("Nevada"),
99 'us-nh' => _("New Hampshire"),
100 'us-nj' => _("New Jersey"),
101 'us-nm' => _("New Mexico"),
102 'us-ny' => _("New York"),
103 'us-nc' => _("North Carolina"),
104 'us-nd' => _("North Dakota"),
105 'us-oh' => _("Ohio"),
106 'us-ok' => _("Oklahoma"),
107 'us-or' => _("Oregon"),
108 'us-pa' => _("Pennsylvania"),
109 'us-ri' => _("Rhode Island"),
110 'us-sc' => _("South Carolina"),
111 'us-sd' => _("South Dakota"),
112 'us-tn' => _("Tennessee"),
113 'us-tx' => _("Texas"),
114 'us-ut' => _("Utah"),
115 'us-vt' => _("Vermont"),
116 'us-va' => _("Virginia"),
117 'us-wa' => _("Washington"),
118 'us-wv' => _("West Virginia"),
119 'us-wi' => _("Wisconsin"),
120 'us-wy' => _("Wyoming"),
121 'us-dc' => _("District of Columbia"),
122 'us-as' => _("American Samoa"),
123 'us-gu' => _("Guam"),
124 'us-mp' => _("Northern Mariana Islands"),
125 'us-pr' => _("Puerto Rico"),
126 'us-um' => _("United States Minor Outlying Islands"),
127 'us-vi' => _("Virgin Islands, U.S.)")
128 ),
129 'ca' => array(
130 'ca-ab' => _("Alberta"),
131 'ca-bc' => _("British Columbia"),
132 'ca-mb' => _("Manitoba"),
133 'ca-nb' => _("New Brunswick"),
134 'ca-nl' => _("Newfoundland and Labrador"),
135 'ca-nt' => _("Northwest Territories"),
136 'ca-ns' => _("Nova Scotia"),
137 'ca-nu' => _("Nunavut"),
138 'ca-on' => _("Ontario"),
139 'ca-pe' => _("Prince Edward Island"),
140 'ca-qc' => _("Quebec"),
141 'ca-sk' => _("Saskatchewan"),
142 'ca-yt' => _("Yukon"),
143 ),
144 'it' => array(
145 'it-ag' => _("Agrigento"),
146 'it-al' => _("Alessandria"),
147 'it-an' => _("Ancona"),
148 'it-ao' => _("Aosta"),
149 'it-ar' => _("Arezzo"),
150 'it-ap' => _("Ascoli Piceno"),
151 'it-at' => _("Asti"),
152 'it-av' => _("Avellino"),
153 'it-ba' => _("Bari"),
154 'it-bt' => _("Barletta-Andria-Trani"),
155 'it-bl' => _("Belluno"),
156 'it-bn' => _("Benevento"),
157 'it-bg' => _("Bergamo"),
158 'it-bi' => _("Biella"),
159 'it-bo' => _("Bologna"),
160 'it-bz' => _("Bolzano"),
161 'it-bs' => _("Brescia"),
162 'it-br' => _("Brindisi"),
163 'it-ca' => _("Cagliari"),
164 'it-cl' => _("Caltanissetta"),
165 'it-cb' => _("Campobasso"),
166 'it-ci' => _("Carbonia-Iglesias"),
167 'it-ce' => _("Caserta"),
168 'it-ct' => _("Catania"),
169 'it-cz' => _("Catanzaro"),
170 'it-ch' => _("Chieti"),
171 'it-co' => _("Como"),
172 'it-cs' => _("Cosenza"),
173 'it-cr' => _("Cremona"),
174 'it-kr' => _("Crotone"),
175 'it-cn' => _("Cuneo"),
176 'it-en' => _("Enna"),
177 'it-fm' => _("Fermo"),
178 'it-fe' => _("Ferrara"),
179 'it-fi' => _("Firenze"),
180 'it-fg' => _("Foggia"),
181 'it-fc' => _("Forlì-Cesena"),
182 'it-fr' => _("Frosinone"),
183 'it-ge' => _("Genova"),
184 'it-go' => _("Gorizia"),
185 'it-gr' => _("Grosseto"),
186 'it-im' => _("Imperia"),
187 'it-is' => _("Isernia"),
188 'it-aq' => _("L'Aquila"),
189 'it-sp' => _("La Spezia"),
190 'it-lt' => _("Latina"),
191 'it-le' => _("Lecce"),
192 'it-lc' => _("Lecco"),
193 'it-li' => _("Livorno"),
194 'it-lo' => _("Lodi"),
195 'it-lu' => _("Lucca"),
196 'it-mc' => _("Macerata"),
197 'it-mn' => _("Mantova"),
198 'it-ms' => _("Massa-Carrara"),
199 'it-mt' => _("Matera"),
200 'it-vs' => _("Medio Campidano"),
201 'it-me' => _("Messina"),
202 'it-mi' => _("Milano"),
203 'it-mo' => _("Modena"),
204 'it-mb' => _("Monza e della Brianza"),
205 'it-na' => _("Napoli"),
206 'it-no' => _("Novara"),
207 'it-nu' => _("Nuoro"),
208 'it-og' => _("Ogliastra"),
209 'it-ot' => _("Olbia-Tempio"),
210 'it-or' => _("Oristano"),
211 'it-pd' => _("Padova"),
212 'it-pa' => _("Palermo"),
213 'it-pr' => _("Parma"),
214 'it-pv' => _("Pavia"),
215 'it-pg' => _("Perugia"),
216 'it-pu' => _("Pesaro e Urbino"),
217 'it-pe' => _("Pescara"),
218 'it-pc' => _("Piacenza"),
219 'it-pi' => _("Pisa"),
220 'it-pt' => _("Pistoia"),
221 'it-pn' => _("Pordenone"),
222 'it-pz' => _("Potenza"),
223 'it-po' => _("Prato"),
224 'it-rg' => _("Ragusa"),
225 'it-ra' => _("Ravenna"),
226 'it-rc' => _("Reggio Calabria"),
227 'it-re' => _("Reggio Emilia"),
228 'it-ri' => _("Rieti"),
229 'it-rn' => _("Rimini"),
230 'it-rm' => _("Roma"),
231 'it-ro' => _("Rovigo"),
232 'it-sa' => _("Salerno"),
233 'it-ss' => _("Sassari"),
234 'it-sv' => _("Savona"),
235 'it-si' => _("Siena"),
236 'it-sr' => _("Siracusa"),
237 'it-so' => _("Sondrio"),
238 'it-ta' => _("Taranto"),
239 'it-te' => _("Teramo"),
240 'it-tr' => _("Terni"),
241 'it-to' => _("Torino"),
242 'it-tp' => _("Trapani"),
243 'it-tn' => _("Trento"),
244 'it-tv' => _("Treviso"),
245 'it-ts' => _("Trieste"),
246 'it-ud' => _("Udine"),
247 'it-va' => _("Varese"),
248 'it-ve' => _("Venezia"),
249 'it-vb' => _("Verbano-Cusio-Ossola"),
250 'it-vc' => _("Vercelli"),
251 'it-vr' => _("Verona"),
252 'it-vv' => _("Vibo Valentia"),
253 'it-vi' => _("Vicenza"),
254 'it-vt' => _("Viterbo"),
255 ),
256 );
257
258 // return a subset
259 if ($iso !== null) {
260 // search for iso state codes
261 if (is_string($iso) && isset($country_states[$iso])) {
262 return $country_states[$iso];
263 } else if (is_array($iso)) {
264 $toDelete = array_diff(array_keys($country_states), $iso);
265 foreach($toDelete as $country) {
266 unset($country_states[$country]);
267 }
268 return $country_states;
269 }
270
271 return '';
272 }
273
274 return $country_states;
275 }
276
285 public function __construct($name, $parameters, $form)
286 {
287 parent::__construct($name, $parameters, $form);
288
289 if (isset($parameters['defaultValue'])) {
290 $this->defaults['defaultValue'] = $parameters['defaultValue'];
291 }
292
293 $this->list = isset($parameters['states'])
294 ? $parameters['states']
295 : self::getStates();
296
297 // make sure all keys are lower case
298 $this->list = array_change_key_case($this->list, CASE_LOWER);
299
300 // sort alphabetically
301 asort($this->list);
302
303 $this->list = array('' => _("Please Select")) + $this->list;
304 }
305
315 protected function setDefaults()
316 {
317 parent::setDefaults();
318
319 $this->defaults['skin'] = 'select';
320 }
321}
322
323/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
HTML-single-choice input type i.e.
Definition Single.php:56
HTML-multiple-choice States input select .
Definition State.php:36
$list
Contains list of ISO countries.
Definition State.php:40
__construct($name, $parameters, $form)
multiple class constructor
Definition State.php:285
static getStates($iso=null)
Gets the Default States list.
Definition State.php:47
setDefaults()
collects initial values across subclasses.
Definition State.php:315
Classes for HTML input-elements.
Definition Address.php:9