forked from AppStateESS/InternshipInventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathState.php
135 lines (118 loc) · 3.95 KB
/
State.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace Intern;
/**
* @author Matthew McNaney <mcnaney at gmail dot com>
* @license http://opensource.org/licenses/gpl-3.0.html
*/
class State {
public $abbr;
public $full_name;
public $active;
public function __construct($abbr)
{
$db = new \PHPWS_DB('intern_state');
$db->addWhere('abbr', $abbr);
$db->loadObject($this);
}
public function save()
{
$db = new \PHPWS_DB('intern_state');
$db->addWhere('abbr', $this->abbr);
return $db->saveObject($this);
}
public function setActive($active)
{
$this->active = (bool)$active;
}
public static function getAllowedStates()
{
$db = new \PHPWS_DB('intern_state');
$db->addWhere('active', 1);
$db->addColumn('abbr');
$db->addColumn('full_name');
$db->setIndexBy('abbr');
$db->addOrder('full_name ASC');
$states = $db->select('col');
if (empty($states)) {
\NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, 'The list of allowed US states for internship locations has not been configured. Please use the administrative options to <a href="index.php?module=intern&action=edit_states">add allowed states.</a>');
\NQ::close();
PHPWS_Core::goBack();
}
return $states;
}
public static function getStates()
{
$db = \phpws2\Database::newDB();
$pdo = $db->getPDO();
$sql = "SELECT *
FROM intern_state
ORDER BY full_name ASC";
$sth = $pdo->prepare($sql);
$sth->execute();
$result = $sth->fetchAll(\PDO::FETCH_CLASS, 'Intern\StateRestored');
if (empty($result)) {
\NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, 'The list of allowed US states for internship locations has not been configured. Please use the administrative options to <a href="index.php?module=intern&action=edit_states">add allowed states.</a>');
\NQ::close();
PHPWS_Core::goBack();
}
$resultState = array();
foreach($result as $state)
{
$resultState[$state->abbr] = $state;
}
return $resultState;
}
/* http://www.bytemycode.com/snippets/snippet/454/ */
public static $UNITED_STATES = array(-1 => 'Select State',
'AL' => "Alabama",
'AK' => "Alaska",
'AZ' => "Arizona",
'AR' => "Arkansas",
'CA' => "California",
'CO' => "Colorado",
'CT' => "Connecticut",
'DE' => "Delaware",
'DC' => "District Of Columbia",
'FL' => "Florida",
'GA' => "Georgia",
'HI' => "Hawaii",
'ID' => "Idaho",
'IL' => "Illinois",
'IN' => "Indiana",
'IA' => "Iowa",
'KS' => "Kansas",
'KY' => "Kentucky",
'LA' => "Louisiana",
'ME' => "Maine",
'MD' => "Maryland",
'MA' => "Massachusetts",
'MI' => "Michigan",
'MN' => "Minnesota",
'MS' => "Mississippi",
'MO' => "Missouri",
'MT' => "Montana",
'NE' => "Nebraska",
'NV' => "Nevada",
'NH' => "New Hampshire",
'NJ' => "New Jersey",
'NM' => "New Mexico",
'NY' => "New York",
'NC' => "North Carolina",
'ND' => "North Dakota",
'OH' => "Ohio",
'OK' => "Oklahoma",
'OR' => "Oregon",
'PA' => "Pennsylvania",
'RI' => "Rhode Island",
'SC' => "South Carolina",
'SD' => "South Dakota",
'TN' => "Tennessee",
'TX' => "Texas",
'UT' => "Utah",
'VT' => "Vermont",
'VA' => "Virginia",
'WA' => "Washington",
'WV' => "West Virginia",
'WI' => "Wisconsin",
'WY' => "Wyoming");
}