1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace Route4Me; |
3
|
|
|
|
4
|
|
|
use Route4Me\Common; |
5
|
|
|
|
6
|
|
|
class AddressBookLocation extends Common |
7
|
|
|
{ |
8
|
|
|
static public $apiUrl = '/api.v4/address_book.php'; |
9
|
|
|
static public $apiUrl00 = '/api/address_book/modify_contact.php'; |
10
|
|
|
|
11
|
|
|
public $address_id; |
12
|
|
|
public $address_group; |
13
|
|
|
public $address_alias; |
14
|
|
|
public $address_1; |
15
|
|
|
public $address_2; |
16
|
|
|
public $first_name; |
17
|
|
|
public $last_name; |
18
|
|
|
public $address_email; |
19
|
|
|
public $address_phone_number; |
20
|
|
|
public $address_city; |
21
|
|
|
public $address_state_id; |
22
|
|
|
public $address_country_id; |
23
|
|
|
public $address_zip; |
24
|
|
|
public $cached_lat; |
25
|
|
|
public $cached_lng; |
26
|
|
|
public $curbside_lat; |
27
|
|
|
public $curbside_lng; |
28
|
|
|
public $color; |
29
|
|
|
public $address_custom_data; |
30
|
|
|
public $schedule; |
31
|
|
|
|
32
|
|
|
//public $offset; |
33
|
|
|
//public $limit; |
34
|
|
|
|
35
|
|
|
public function __construct () { } |
36
|
|
|
|
37
|
|
|
public static function fromArray(array $params) { |
38
|
|
|
$addressbooklocation = new AddressBookLocation(); |
39
|
|
|
foreach($params as $key => $value) { |
40
|
|
|
if (property_exists($addressbooklocation, $key)) { |
41
|
|
|
$addressbooklocation->{$key} = $value; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $addressbooklocation; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public static function getAddressBookLocation($addressId) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$ablocations = Route4Me::makeRequst(array( |
51
|
|
|
'url' => self::$apiUrl, |
52
|
|
|
'method' => 'GET', |
53
|
|
|
'query' => array( |
54
|
|
|
'query' => $addressId, |
55
|
|
|
'limit' => 30 |
56
|
|
|
) |
57
|
|
|
)); |
58
|
|
|
|
59
|
|
|
return $ablocations; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
View Code Duplication |
public static function searchRoutedLocation($params) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
$result= Route4Me::makeRequst(array( |
65
|
|
|
'url' => self::$apiUrl, |
66
|
|
|
'method' => 'GET', |
67
|
|
|
'query' => array( |
68
|
|
|
'display' => isset($params['display']) ? $params['display']: null, |
69
|
|
|
'query' => isset($params['query']) ? $params['query']: null, |
70
|
|
|
'fields' => isset($params['fields']) ? $params['fields']: null, |
71
|
|
|
'limit' => isset($params['limit']) ? $params['limit']: null, |
72
|
|
|
'offset' => isset($params['offset']) ? $params['offset'] : null, |
73
|
|
|
) |
74
|
|
|
)); |
75
|
|
|
|
76
|
|
|
return $result; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
View Code Duplication |
public static function getAddressBookLocations($params) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$ablocations = Route4Me::makeRequst(array( |
82
|
|
|
'url' => self::$apiUrl, |
83
|
|
|
'method' => 'GET', |
84
|
|
|
'query' => array( |
85
|
|
|
'limit' => isset($params->limit) ? $params->limit: null, |
86
|
|
|
'offset' => isset($params->offset) ? $params->offset : null, |
87
|
|
|
) |
88
|
|
|
)); |
89
|
|
|
|
90
|
|
|
return $ablocations; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
View Code Duplication |
public static function getAddressBookLocationsByIds($ids) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$ablocations = Route4Me::makeRequst(array( |
96
|
|
|
'url' => self::$apiUrl, |
97
|
|
|
'method' => 'GET', |
98
|
|
|
'query' => array( |
99
|
|
|
'address_id' => $ids |
100
|
|
|
) |
101
|
|
|
)); |
102
|
|
|
|
103
|
|
|
return $ablocations; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public static function addAdressBookLocation($params) |
107
|
|
|
{ |
108
|
|
|
$ablocations = Route4Me::makeRequst(array( |
109
|
|
|
'url' => self::$apiUrl, |
110
|
|
|
'method' => 'POST', |
111
|
|
|
'body' => array( |
112
|
|
|
'address_1' => isset($params->address_1) ? $params->address_1: null, |
113
|
|
|
'address_2' => isset($params->address_2) ? $params->address_2: null, |
114
|
|
|
'address_alias' => isset($params->address_alias) ? $params->address_alias: null, |
115
|
|
|
'first_name' => isset($params->first_name) ? $params->first_name : null, |
116
|
|
|
'cached_lat' => isset($params->cached_lat) ? $params->cached_lat : null, |
117
|
|
|
'cached_lng' => isset($params->cached_lng) ? $params->cached_lng : null, |
118
|
|
|
'curbside_lat' => isset($params->curbside_lat) ? $params->curbside_lat : null, |
119
|
|
|
'curbside_lng' => isset($params->curbside_lng) ? $params->curbside_lng : null, |
120
|
|
|
'address_phone_number' => isset($params->address_phone_number) ? $params->address_phone_number: null, |
121
|
|
|
'address_group' => isset($params->address_group) ? $params->address_group: null, |
122
|
|
|
'first_name' => isset($params->first_name) ? $params->first_name: null, |
123
|
|
|
'last_name' => isset($params->last_name) ? $params->last_name: null, |
124
|
|
|
'local_time_window_start' => isset($params->local_time_window_start) ? $params->local_time_window_start: null, |
125
|
|
|
'local_time_window_end' => isset($params->local_time_window_end) ? $params->local_time_window_end: null, |
126
|
|
|
'local_time_window_start_2' => isset($params->local_time_window_start_2) ? $params->local_time_window_start_2: null, |
127
|
|
|
'local_time_window_end_2' => isset($params->local_time_window_end_2) ? $params->local_time_window_end_2: null, |
128
|
|
|
'address_email' => isset($params->address_email) ? $params->address_email: null, |
129
|
|
|
'address_city' => isset($params->address_city) ? $params->address_city: null, |
130
|
|
|
'address_state_id' => isset($params->address_state_id) ? $params->address_state_id: null, |
131
|
|
|
'address_country_id' => isset($params->address_country_id) ? $params->address_country_id: null, |
132
|
|
|
'address_zip' => isset($params->address_zip) ? $params->address_zip: null, |
133
|
|
|
'address_custom_data' => isset($params->address_custom_data) ? $params->address_custom_data: null, |
134
|
|
|
'schedule' => isset($params->schedule) ? $params->schedule: null, |
135
|
|
|
'schedule_blacklist' => isset($params->schedule_blacklist) ? $params->schedule_blacklist: null, |
136
|
|
|
'service_time' => isset($params->service_time) ? $params->service_time: null, |
137
|
|
|
'local_timezone_string' => isset($params->local_timezone_string) ? $params->local_timezone_string: null, |
138
|
|
|
'color' => isset($params->color) ? $params->color: null, |
139
|
|
|
'address_icon' => isset($params->address_icon) ? $params->address_icon: null, |
140
|
|
|
'address_stop_type' => isset($params->address_stop_type) ? $params->address_stop_type: null, |
141
|
|
|
'address_cube' => isset($params->address_cube) ? $params->address_cube: null, |
142
|
|
|
'address_pieces' => isset($params->address_pieces) ? $params->address_pieces: null, |
143
|
|
|
'address_reference_no' => isset($params->address_reference_no) ? $params->address_reference_no: null, |
144
|
|
|
'address_revenue' => isset($params->address_revenue) ? $params->address_revenue: null, |
145
|
|
|
'address_weight' => isset($params->address_weight) ? $params->address_weight: null, |
146
|
|
|
'address_priority' => isset($params->address_priority) ? $params->address_priority: null, |
147
|
|
|
'address_customer_po' => isset($params->address_customer_po) ? $params->address_customer_po: null, |
148
|
|
|
) |
149
|
|
|
)); |
150
|
|
|
|
151
|
|
|
return $ablocations; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
View Code Duplication |
public function deleteAdressBookLocation($address_ids) |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
$address = Route4Me::makeRequst(array( |
157
|
|
|
'url' => self::$apiUrl, |
158
|
|
|
'method' => 'DELETEARRAY', |
159
|
|
|
'query' => array( |
160
|
|
|
'address_ids' => $address_ids |
161
|
|
|
) |
162
|
|
|
)); |
163
|
|
|
|
164
|
|
|
return $address; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function updateAdressBookLocation($params) |
168
|
|
|
{ |
169
|
|
|
//echo "address_id --> ".$params["address_id"]."<br"; |
|
|
|
|
170
|
|
|
$address = Route4Me::makeRequst(array( |
171
|
|
|
'url' => self::$apiUrl, |
172
|
|
|
'method' => 'PUT', |
173
|
|
|
'query' => $params, |
174
|
|
|
|
175
|
|
|
)); |
176
|
|
|
|
177
|
|
|
return $address; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
View Code Duplication |
public static function get($params) |
|
|
|
|
181
|
|
|
{ |
182
|
|
|
$ablocations = Route4Me::makeRequst(array( |
183
|
|
|
'url' => self::$apiUrl, |
184
|
|
|
'method' => 'ADD', |
185
|
|
|
'query' => array( |
186
|
|
|
'first_name' => isset($params->first_name) ? $params->first_name : null, |
187
|
|
|
'address_1' => isset($params->address_1) ? $params->address_1: null, |
188
|
|
|
'cached_lat' => isset($params->cached_lat) ? $params->cached_lat : null, |
189
|
|
|
'cached_lng' => isset($params->cached_lng) ? $params->cached_lng : null, |
190
|
|
|
) |
191
|
|
|
)); |
192
|
|
|
|
193
|
|
|
return $ablocations; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public static function validateScheduleMode($scheduleMode) |
197
|
|
|
{ |
198
|
|
|
$schedMmodes=array("daily","weekly","monthly","annually"); |
199
|
|
|
|
200
|
|
|
if (in_array($scheduleMode, $schedMmodes)) return TRUE; else return FALSE; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public static function validateScheduleEnable($scheduleEnabled) |
204
|
|
|
{ |
205
|
|
|
$schedEnambles=array(TRUE,FALSE); |
206
|
|
|
|
207
|
|
|
if (in_array($scheduleEnabled, $schedEnambles)) return TRUE; else return FALSE; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public static function validateScheduleEvery($scheduleEvery) |
211
|
|
|
{ |
212
|
|
|
if (is_numeric($scheduleEvery)) return TRUE; else return FALSE; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
View Code Duplication |
public static function validateScheduleWeekDays($scheduleWeekDays) |
|
|
|
|
216
|
|
|
{ |
217
|
|
|
$weekdays = explode(',', $scheduleWeekDays); |
218
|
|
|
|
219
|
|
|
if (sizeof($weekdays)<1) return FALSE; |
220
|
|
|
|
221
|
|
|
$isValid=TRUE; |
222
|
|
|
|
223
|
|
|
for ($i=0; $i < sizeof($weekdays); $i++) { |
|
|
|
|
224
|
|
|
if (is_numeric($weekdays[$i])) { |
225
|
|
|
$wday=intval($weekdays[$i]); |
226
|
|
|
if ($wday<1 || $wday>7) $isValid=FALSE; |
227
|
|
|
} |
228
|
|
|
else $isValid=FALSE; |
229
|
|
|
} |
230
|
|
|
//echo $scheduleWeekDays.' --- '. $isValid."<br>"; |
|
|
|
|
231
|
|
|
return $isValid; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public static function validateScheduleMonthlyMode($scheduleMonthlyMode) |
235
|
|
|
{ |
236
|
|
|
$schedMonthlyMmodes=array("dates","nth"); |
237
|
|
|
|
238
|
|
|
if (in_array($scheduleMonthlyMode, $schedMonthlyMmodes)) return TRUE; else return FALSE; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
View Code Duplication |
public static function validateScheduleMonthlyDates($scheduleMonthlyDates) |
|
|
|
|
242
|
|
|
{ |
243
|
|
|
$monthlyDates = explode(',', $scheduleMonthlyDates); |
244
|
|
|
|
245
|
|
|
if (sizeof($monthlyDates)<1) return FALSE; |
246
|
|
|
|
247
|
|
|
$isValid=TRUE; |
248
|
|
|
|
249
|
|
|
for ($i=0; $i < sizeof($monthlyDates); $i++) { |
|
|
|
|
250
|
|
|
if (is_numeric($monthlyDates[$i])) { |
251
|
|
|
$mday=intval($monthlyDates[$i]); |
252
|
|
|
if ($mday<1 || $mday>31) $isValid=FALSE; |
253
|
|
|
} |
254
|
|
|
else $isValid=FALSE; |
255
|
|
|
} |
256
|
|
|
//echo $scheduleMonthlyDates.' --- '. $isValid."<br>"; |
|
|
|
|
257
|
|
|
return $isValid; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
public static function validateScheduleNthN($scheduleNthN) |
261
|
|
|
{ |
262
|
|
|
if (!is_numeric($scheduleNthN)) return FALSE; |
263
|
|
|
|
264
|
|
|
$schedNthNs=array(1,2,3,4,5,-1); |
265
|
|
|
if (in_array($scheduleNthN, $schedNthNs)) return TRUE; else return FALSE; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
public static function validateScheduleNthWhat($scheduleNthWhat) |
269
|
|
|
{ |
270
|
|
|
if (!is_numeric($scheduleNthWhat)) return FALSE; |
271
|
|
|
|
272
|
|
|
$schedNthWhats=array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); |
273
|
|
|
if (in_array($scheduleNthWhat, $schedNthWhats)) return TRUE; else return FALSE; |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
?> |
|
|
|
|
278
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.