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
|
|
|
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) |
|
|
|
|
126
|
|
|
{ |
127
|
|
|
$allQueryFields = array('route_id', 'route_destination_id'); |
128
|
|
|
$allBodyFields = array('is_visited', 'is_departed'); |
129
|
|
|
|
130
|
|
|
$result = Route4Me::makeRequst(array( |
131
|
|
|
'url' => Endpoint::ADDRESS_V4, |
132
|
|
|
'method' => 'PUT', |
133
|
|
|
'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
134
|
|
|
'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
135
|
|
|
)); |
136
|
|
|
|
137
|
|
|
return $result; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
View Code Duplication |
public function markAsDeparted($params) |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
$allQueryFields = array('route_id', 'address_id', 'is_departed', 'member_id'); |
143
|
|
|
|
144
|
|
|
$address = Route4Me::makeRequst(array( |
145
|
|
|
'url' => Endpoint::MARK_ADDRESS_DEPARTED, |
146
|
|
|
'method' => 'PUT', |
147
|
|
|
'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
148
|
|
|
)); |
149
|
|
|
|
150
|
|
|
return $address; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
View Code Duplication |
public function markAsVisited($params) |
|
|
|
|
154
|
|
|
{ |
155
|
|
|
$allQueryFields = array('route_id', 'address_id', 'is_visited', 'member_id'); |
156
|
|
|
|
157
|
|
|
$address = Route4Me::makeRequst(array( |
158
|
|
|
'url' => Endpoint::UPDATE_ADDRESS_VISITED, |
159
|
|
|
'method' => 'PUT', |
160
|
|
|
'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
161
|
|
|
)); |
162
|
|
|
|
163
|
|
|
return $address; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
View Code Duplication |
public function deleteAddress() |
|
|
|
|
167
|
|
|
{ |
168
|
|
|
$address = Route4Me::makeRequst(array( |
169
|
|
|
'url' => Endpoint::ADDRESS_V4, |
170
|
|
|
'method' => 'DELETE', |
171
|
|
|
'query' => array( |
172
|
|
|
'route_id' => $this->route_id, |
173
|
|
|
'route_destination_id' => $this->route_destination_id, |
174
|
|
|
) |
175
|
|
|
)); |
176
|
|
|
|
177
|
|
|
return (bool)$address['deleted']; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
View Code Duplication |
public function moveDestinationToRoute($params) |
|
|
|
|
181
|
|
|
{ |
182
|
|
|
$allBodyFields = array('to_route_id', 'route_destination_id', 'after_destination_id'); |
183
|
|
|
|
184
|
|
|
$result = Route4Me::makeRequst(array( |
185
|
|
|
'url' => Endpoint::MOVE_ROUTE_DESTINATION, |
186
|
|
|
'method' => 'POST', |
187
|
|
|
'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
188
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
189
|
|
|
)); |
190
|
|
|
|
191
|
|
|
return $result; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function AddAddressNote($params) |
195
|
|
|
{ |
196
|
|
|
$allQueryFields = array('route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type'); |
197
|
|
|
$allBodyFields = array('strNoteContents', 'strUpdateType'); |
198
|
|
|
|
199
|
|
|
$result = Route4Me::makeRequst(array( |
200
|
|
|
'url' => Endpoint::ROUTE_NOTES_ADD, |
201
|
|
|
'method' => 'POST', |
202
|
|
|
'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
203
|
|
|
'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
204
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
205
|
|
|
)); |
206
|
|
|
|
207
|
|
|
return $result; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function AddNoteFile($params) |
211
|
|
|
{ |
212
|
|
|
$allQueryFields = array('route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type', 'strUpdateType'); |
213
|
|
|
$allBodyFields = array('strFilename'); |
214
|
|
|
|
215
|
|
|
$result = Route4Me::fileUploadRequest(array( |
216
|
|
|
'url' => Endpoint::ROUTE_NOTES_ADD, |
217
|
|
|
'method' => 'POST', |
218
|
|
|
'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
219
|
|
|
'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
220
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
221
|
|
|
)); |
222
|
|
|
|
223
|
|
|
return $result; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function createCustomNoteType($params) |
227
|
|
|
{ |
228
|
|
|
$allBodyFields = array('type', 'values'); |
229
|
|
|
|
230
|
|
|
$result = Route4Me::makeRequst(array( |
231
|
|
|
'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
232
|
|
|
'method' => 'POST', |
233
|
|
|
'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
234
|
|
|
)); |
235
|
|
|
|
236
|
|
|
return $result; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
View Code Duplication |
public function removeCustomNoteType($params) |
|
|
|
|
240
|
|
|
{ |
241
|
|
|
$result = Route4Me::makeRequst(array( |
242
|
|
|
'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
243
|
|
|
'method' => 'DELETE', |
244
|
|
|
'body' => array( |
245
|
|
|
'id' => isset($params['id']) ? $params['id'] : null |
246
|
|
|
) |
247
|
|
|
)); |
248
|
|
|
|
249
|
|
|
return $result; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
public function getAllCustomNoteTypes() |
253
|
|
|
{ |
254
|
|
|
$result = Route4Me::makeRequst(array( |
255
|
|
|
'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
256
|
|
|
'method' => 'GET' |
257
|
|
|
)); |
258
|
|
|
|
259
|
|
|
return $result; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
public function addCustomNoteToRoute($params) |
263
|
|
|
{ |
264
|
|
|
$customArray = array(); |
265
|
|
|
|
266
|
|
|
foreach ($params as $key => $value) { |
267
|
|
|
if (strpos($key, "custom_note_type")!==false) { |
268
|
|
|
$customArray[$key] = $value; |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
$allQueryFields = array('route_id', 'address_id', 'format', 'dev_lat', 'dev_lng'); |
273
|
|
|
$allBodyFields = array('strUpdateType', 'strUpdateType', 'strNoteContents'); |
274
|
|
|
|
275
|
|
|
$result = Route4Me::makeRequst(array( |
276
|
|
|
'url' => Endpoint::ROUTE_NOTES_ADD, |
277
|
|
|
'method' => 'POST', |
278
|
|
|
'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
279
|
|
|
'body' => array_merge(Route4Me::generateRequestParameters($allBodyFields, $params), $customArray), |
280
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
281
|
|
|
)); |
282
|
|
|
|
283
|
|
|
return $result; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
function getAddressId() |
|
|
|
|
287
|
|
|
{ |
288
|
|
|
return $this->route_destination_id; |
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
|
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.