state.php
Go to the documentation of this file.
1 <?php
9 namespace depage\htmlform\elements;
10 
35 class 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  );
130 
131  // return a subset
132  if ($iso !== null) {
133  // search for iso state codes
134  foreach ($country_states as $country => &$states) {
135  if (isset($states[$iso])) {
136  return $states[$iso];
137  }
138  }
139 
140  return '';
141  }
142 
143  return $country_states;
144  }
145 
154  public function __construct($name, $parameters, $form)
155  {
156  parent::__construct($name, $parameters, $form);
157 
158  if (isset($parameters['defaultValue'])) {
159  $this->defaults['defaultValue'] = $parameters['defaultValue'];
160  }
161 
162  $this->list = isset($parameters['states'])
163  ? $parameters['states']
164  : self::getStates();
165 
166  // make sure all keys are lower case
167  $this->list = array_change_key_case($this->list, CASE_LOWER);
168 
169  // sort alphabetically
170  asort($this->list);
171 
172  $this->list = array('' => _("Please Select")) + $this->list;
173  }
174 
184  protected function setDefaults()
185  {
186  parent::setDefaults();
187 
188  $this->defaults['skin'] = 'select';
189  }
190 }
191 
192 /* vim:set ft=php sw=4 sts=4 fdm=marker et : */
__construct($name, $parameters, $form)
multiple class constructor
Definition: state.php:154
$list
Contains list of ISO countries.
Definition: state.php:40
static getStates($iso=null)
Gets the Default States list.
Definition: state.php:47
HTML-single-choice input type i.e. radio and select.
Definition: single.php:55
HTML-multiple-choice States input select .
Definition: state.php:35
setDefaults()
collects initial values across subclasses.
Definition: state.php:184