1
|
|
|
<?php |
2
|
|
|
namespace Route4Me; |
3
|
|
|
|
4
|
|
|
use Route4Me\Exception\BadParam; |
5
|
|
|
use Route4Me\Route4Me; |
6
|
|
|
use Route4Me\Common; |
7
|
|
|
use Route4Me\Enum\Endpoint; |
8
|
|
|
|
9
|
|
|
class Address extends Common |
10
|
|
|
{ |
11
|
|
|
public $route_destination_id; |
12
|
|
|
public $alias; |
13
|
|
|
public $member_id; |
14
|
|
|
public $address; |
15
|
|
|
public $addressUpdate; |
16
|
|
|
public $is_depot = false; |
17
|
|
|
public $lat; |
18
|
|
|
public $lng; |
19
|
|
|
public $route_id; |
20
|
|
|
public $original_route_id; |
21
|
|
|
public $optimization_problem_id; |
22
|
|
|
public $sequence_no; |
23
|
|
|
public $geocoded; |
24
|
|
|
public $preferred_geocoding; |
25
|
|
|
public $failed_geocoding; |
26
|
|
|
public $geocodings = array(); |
27
|
|
|
public $contact_id; |
28
|
|
|
public $is_visited; |
29
|
|
|
public $customer_po; |
30
|
|
|
public $invoice_no; |
31
|
|
|
public $reference_no; |
32
|
|
|
public $order_no; |
33
|
|
|
public $weight; |
34
|
|
|
public $cost; |
35
|
|
|
public $revenue; |
36
|
|
|
public $cube; |
37
|
|
|
public $pieces; |
38
|
|
|
public $email; |
39
|
|
|
public $phone; |
40
|
|
|
public $tracking_number; |
41
|
|
|
public $destination_note_count; |
42
|
|
|
public $drive_time_to_next_destination; |
43
|
|
|
public $distance_to_next_destination; |
44
|
|
|
public $generated_time_window_start; |
45
|
|
|
public $generated_time_window_end; |
46
|
|
|
public $time_window_start; |
47
|
|
|
public $time_window_end; |
48
|
|
|
public $time; |
49
|
|
|
public $notes; |
50
|
|
|
public $timestamp_last_visited; |
51
|
|
|
public $custom_fields = array(); |
52
|
|
|
public $manifest = array(); |
53
|
|
|
|
54
|
|
|
public $first_name; |
55
|
|
|
public $last_name; |
56
|
|
|
public $is_departed; |
57
|
|
|
public $timestamp_last_departed; |
58
|
|
|
public $order_id; |
59
|
|
|
public $priority; |
60
|
|
|
public $curbside_lat; |
61
|
|
|
public $curbside_lng; |
62
|
|
|
public $time_window_start_2; |
63
|
|
|
public $time_window_end_2; |
64
|
|
|
|
65
|
|
|
public static function fromArray(array $params) |
66
|
|
|
{ |
67
|
|
|
$address = new Address(); |
68
|
|
|
foreach ($params as $key => $value) { |
69
|
|
|
if (property_exists($address, $key)) { |
70
|
|
|
$address->{$key} = $value; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $address; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public static function getAddress($routeId, $addressId) |
78
|
|
|
{ |
79
|
|
|
$address = Route4Me::makeRequst(array( |
80
|
|
|
'url' => Endpoint::ADDRESS_V4, |
81
|
|
|
'method' => 'GET', |
82
|
|
|
'query' => array( |
83
|
|
|
'route_id' => $routeId, |
84
|
|
|
'route_destination_id' => $addressId, |
85
|
|
|
) |
86
|
|
|
)); |
87
|
|
|
|
88
|
|
|
return Address::fromArray($address); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/*Get notes from the specified route destination |
92
|
|
|
* Returns an address object with notes, if an address exists, otherwise - return null. |
93
|
|
|
*/ |
94
|
|
View Code Duplication |
public static function GetAddressesNotes($noteParams) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
$address = Route4Me::makeRequst(array( |
97
|
|
|
'url' => Endpoint::ADDRESS_V4, |
98
|
|
|
'method' => 'GET', |
99
|
|
|
'query' => array( |
100
|
|
|
'route_id' => isset($noteParams['route_id']) ? $noteParams['route_id'] : null, |
101
|
|
|
'route_destination_id' => isset($noteParams['route_destination_id']) |
102
|
|
|
? $noteParams['route_destination_id'] : null, |
103
|
|
|
'notes' => 1, |
104
|
|
|
) |
105
|
|
|
)); |
106
|
|
|
|
107
|
|
|
return $address; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
View Code Duplication |
public function update() |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
$addressUpdate = Route4Me::makeRequst(array( |
113
|
|
|
'url' => Endpoint::ADDRESS_V4, |
114
|
|
|
'method' => 'PUT', |
115
|
|
|
'body' => $this->toArray(), |
116
|
|
|
'query' => array( |
117
|
|
|
'route_id' => $this->route_id, |
118
|
|
|
'route_destination_id' => $this->route_destination_id, |
119
|
|
|
), |
120
|
|
|
)); |
121
|
|
|
|
122
|
|
|
return Address::fromArray($addressUpdate); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
View Code Duplication |
public function markAddress($params, $body) |
|
|
|
|
126
|
|
|
{ |
127
|
|
|
$result = Route4Me::makeRequst(array( |
128
|
|
|
'url' => Endpoint::ADDRESS_V4, |
129
|
|
|
'method' => 'PUT', |
130
|
|
|
'query' => array( |
131
|
|
|
'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
132
|
|
|
'route_destination_id' => isset($params['route_destination_id']) ? $params['route_destination_id'] : null, |
133
|
|
|
), |
134
|
|
|
'body' => $body |
135
|
|
|
)); |
136
|
|
|
|
137
|
|
|
return $result; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function markAsDeparted($params) |
141
|
|
|
{ |
142
|
|
|
$address = Route4Me::makeRequst(array( |
143
|
|
|
'url' => Endpoint::MARK_ADDRESS_DEPARTED, |
144
|
|
|
'method' => 'GET', |
145
|
|
|
'query' => array( |
146
|
|
|
'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
147
|
|
|
'address_id' => isset($params['address_id']) ? $params['address_id'] : null, |
148
|
|
|
'is_departed' => isset($params['is_departed']) ? $params['is_departed'] : null, |
149
|
|
|
'member_id' => isset($params['member_id']) ? $params['member_id'] : null, |
150
|
|
|
), |
151
|
|
|
)); |
152
|
|
|
|
153
|
|
|
return $address; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
View Code Duplication |
public function markAsVisited($params) |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
$address = Route4Me::makeRequst(array( |
159
|
|
|
'url' => Endpoint::UPDATE_ADDRESS_VISITED, |
160
|
|
|
'method' => 'GET', |
161
|
|
|
'query' => array( |
162
|
|
|
'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
163
|
|
|
'address_id' => isset($params['address_id']) ? $params['address_id'] : null, |
164
|
|
|
'member_id' => isset($params['member_id']) ? $params['member_id'] : null, |
165
|
|
|
), |
166
|
|
|
'body' => array( |
167
|
|
|
'is_visited' => isset($params['is_visited']) ? $params['is_visited'] : null |
168
|
|
|
) |
169
|
|
|
)); |
170
|
|
|
|
171
|
|
|
return $address; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
View Code Duplication |
public function delete() |
|
|
|
|
175
|
|
|
{ |
176
|
|
|
$address = Route4Me::makeRequst(array( |
177
|
|
|
'url' => Endpoint::ADDRESS_V4, |
178
|
|
|
'method' => 'DELETE', |
179
|
|
|
'query' => array( |
180
|
|
|
'route_id' => $this->route_id, |
181
|
|
|
'route_destination_id' => $this->route_destination_id, |
182
|
|
|
) |
183
|
|
|
)); |
184
|
|
|
|
185
|
|
|
return (bool)$address['deleted']; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function moveDestinationToRoute($params) |
189
|
|
|
{ |
190
|
|
|
$result = Route4Me::makeRequst(array( |
191
|
|
|
'url' => Endpoint::MOVE_ROUTE_DESTINATION, |
192
|
|
|
'method' => 'POST', |
193
|
|
|
'body' => array( |
194
|
|
|
'to_route_id' => isset($params['to_route_id']) ? $params['to_route_id'] : null, |
195
|
|
|
'route_destination_id' => isset($params['route_destination_id']) ? $params['route_destination_id'] : null, |
196
|
|
|
'after_destination_id' => isset($params['after_destination_id']) ? $params['after_destination_id'] : null |
197
|
|
|
), |
198
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
199
|
|
|
)); |
200
|
|
|
|
201
|
|
|
return $result; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
View Code Duplication |
public function AddAddressNote($params) |
|
|
|
|
205
|
|
|
{ |
206
|
|
|
$result = Route4Me::makeRequst(array( |
207
|
|
|
'url' => Endpoint::ROUTE_NOTES_ADD, |
208
|
|
|
'method' => 'POST', |
209
|
|
|
'query' => array( |
210
|
|
|
'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
211
|
|
|
'address_id' => isset($params['address_id']) ? $params['address_id'] : null, |
212
|
|
|
'dev_lat' => isset($params['dev_lat']) ? $params['dev_lat'] : null, |
213
|
|
|
'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null, |
214
|
|
|
'device_type' => isset($params['device_type']) ? $params['device_type'] : null |
215
|
|
|
), |
216
|
|
|
'body' => array( |
217
|
|
|
'strNoteContents' => isset($params['strNoteContents']) ? $params['strNoteContents'] : null, |
218
|
|
|
'strUpdateType' => isset($params['strUpdateType']) ? $params['strUpdateType'] : null |
219
|
|
|
), |
220
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
221
|
|
|
)); |
222
|
|
|
|
223
|
|
|
return $result; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
View Code Duplication |
public function AddNoteFile($params) |
|
|
|
|
227
|
|
|
{ |
228
|
|
|
$result = Route4Me::fileUploadRequest(array( |
229
|
|
|
'url' => Endpoint::ROUTE_NOTES_ADD, |
230
|
|
|
'method' => 'POST', |
231
|
|
|
'query' => array( |
232
|
|
|
'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
233
|
|
|
'address_id' => isset($params['address_id']) ? $params['address_id'] : null, |
234
|
|
|
'dev_lat' => isset($params['dev_lat']) ? $params['dev_lat'] : null, |
235
|
|
|
'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null, |
236
|
|
|
'device_type' => isset($params['device_type']) ? $params['device_type'] : null, |
237
|
|
|
'strUpdateType' => isset($params['strUpdateType']) ? $params['strUpdateType'] : null |
238
|
|
|
), |
239
|
|
|
'body' => array( |
240
|
|
|
'strFilename' => isset($params['strFilename']) ? $params['strFilename'] : null |
241
|
|
|
), |
242
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
243
|
|
|
)); |
244
|
|
|
|
245
|
|
|
return $result; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
View Code Duplication |
public function createCustomNoteType($params) |
|
|
|
|
249
|
|
|
{ |
250
|
|
|
$result = Route4Me::makeRequst(array( |
251
|
|
|
'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
252
|
|
|
'method' => 'POST', |
253
|
|
|
'body' => array( |
254
|
|
|
'type' => isset($params['type']) ? $params['type'] : null, |
255
|
|
|
'values' => isset($params['values']) ? $params['values'] : null |
256
|
|
|
) |
257
|
|
|
)); |
258
|
|
|
|
259
|
|
|
return $result; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
View Code Duplication |
public function removeCustomNoteType($params) |
|
|
|
|
263
|
|
|
{ |
264
|
|
|
$result = Route4Me::makeRequst(array( |
265
|
|
|
'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
266
|
|
|
'method' => 'DELETE', |
267
|
|
|
'body' => array( |
268
|
|
|
'id' => isset($params['id']) ? $params['id'] : null |
269
|
|
|
) |
270
|
|
|
)); |
271
|
|
|
|
272
|
|
|
return $result; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
public function getAllCustomNoteTypes() |
276
|
|
|
{ |
277
|
|
|
$result = Route4Me::makeRequst(array( |
278
|
|
|
'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
279
|
|
|
'method' => 'GET' |
280
|
|
|
)); |
281
|
|
|
|
282
|
|
|
return $result; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
public function addCustomNoteToRoute($params) |
286
|
|
|
{ |
287
|
|
|
$customArray = array(); |
288
|
|
|
|
289
|
|
|
foreach ($params as $key => $value) { |
290
|
|
|
$kpos = strpos($key, "custom_note_type"); |
291
|
|
|
|
292
|
|
|
if ($kpos!==false) { |
293
|
|
|
$customArray[$key] = $value; |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
$result = Route4Me::makeRequst(array( |
298
|
|
|
'url' => Endpoint::ROUTE_NOTES_ADD, |
299
|
|
|
'method' => 'POST', |
300
|
|
|
'query' => array( |
301
|
|
|
'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
302
|
|
|
'address_id' => isset($params['address_id']) ? $params['address_id'] : null, |
303
|
|
|
'format' => isset($params['format']) ? $params['format'] : null, |
304
|
|
|
'dev_lat' => isset($params['dev_lat']) ? $params['dev_lat'] : null, |
305
|
|
|
'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null |
306
|
|
|
), |
307
|
|
|
'body' => array_merge(array( |
308
|
|
|
'strUpdateType' => isset($params['strUpdateType']) ? $params['strUpdateType'] : null, |
309
|
|
|
'strUpdateType' => isset($params['strUpdateType']) ? $params['strUpdateType'] : null, |
310
|
|
|
'strNoteContents' => isset($params['strNoteContents']) ? $params['strNoteContents'] : null |
311
|
|
|
), $customArray), |
312
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
313
|
|
|
)); |
314
|
|
|
|
315
|
|
|
return $result; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
function getAddressId() |
|
|
|
|
319
|
|
|
{ |
320
|
|
|
return $this->route_destination_id; |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.