@@ -7,291 +7,291 @@ |
||
7 | 7 | |
8 | 8 | class Route4Me |
9 | 9 | { |
10 | - static public $apiKey; |
|
11 | - static public $baseUrl = Endpoint::BASE_URL; |
|
10 | + static public $apiKey; |
|
11 | + static public $baseUrl = Endpoint::BASE_URL; |
|
12 | 12 | |
13 | - public static function setApiKey($apiKey) |
|
14 | - { |
|
15 | - self::$apiKey = $apiKey; |
|
16 | - } |
|
13 | + public static function setApiKey($apiKey) |
|
14 | + { |
|
15 | + self::$apiKey = $apiKey; |
|
16 | + } |
|
17 | 17 | |
18 | - public static function getApiKey() |
|
19 | - { |
|
20 | - return self::$apiKey; |
|
21 | - } |
|
18 | + public static function getApiKey() |
|
19 | + { |
|
20 | + return self::$apiKey; |
|
21 | + } |
|
22 | 22 | |
23 | - public static function setBaseUrl($baseUrl) |
|
24 | - { |
|
25 | - self::$baseUrl = $baseUrl; |
|
26 | - } |
|
23 | + public static function setBaseUrl($baseUrl) |
|
24 | + { |
|
25 | + self::$baseUrl = $baseUrl; |
|
26 | + } |
|
27 | 27 | |
28 | - public static function getBaseUrl() |
|
29 | - { |
|
30 | - return self::$baseUrl; |
|
31 | - } |
|
28 | + public static function getBaseUrl() |
|
29 | + { |
|
30 | + return self::$baseUrl; |
|
31 | + } |
|
32 | 32 | |
33 | - public static function makeRequst($options) { |
|
34 | - $errorHandler = new myErrorHandler(); |
|
33 | + public static function makeRequst($options) { |
|
34 | + $errorHandler = new myErrorHandler(); |
|
35 | 35 | |
36 | - $old_error_handler = set_error_handler(array($errorHandler, "proc_error")); |
|
36 | + $old_error_handler = set_error_handler(array($errorHandler, "proc_error")); |
|
37 | 37 | |
38 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
39 | - $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
38 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
39 | + $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
40 | 40 | |
41 | - $body = isset($options['body']) ? $options['body'] : null; |
|
42 | - $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
43 | - $headers = array( |
|
44 | - "User-Agent: Route4Me php-sdk" |
|
45 | - ); |
|
41 | + $body = isset($options['body']) ? $options['body'] : null; |
|
42 | + $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
43 | + $headers = array( |
|
44 | + "User-Agent: Route4Me php-sdk" |
|
45 | + ); |
|
46 | 46 | |
47 | - if (isset($options['HTTPHEADER'])) { |
|
48 | - $headers[] = $options['HTTPHEADER']; |
|
49 | - } |
|
47 | + if (isset($options['HTTPHEADER'])) { |
|
48 | + $headers[] = $options['HTTPHEADER']; |
|
49 | + } |
|
50 | 50 | |
51 | - if (isset($options['HTTPHEADERS'])) { |
|
52 | - foreach ($options['HTTPHEADERS'] As $header) { |
|
53 | - $headers[] = $header; |
|
54 | - } |
|
55 | - } |
|
51 | + if (isset($options['HTTPHEADERS'])) { |
|
52 | + foreach ($options['HTTPHEADERS'] As $header) { |
|
53 | + $headers[] = $header; |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - $ch = curl_init(); |
|
57 | + $ch = curl_init(); |
|
58 | 58 | |
59 | - $url = isset($options['url']) ? $options['url'].'?'.http_build_query(array_merge( |
|
60 | - $query, array('api_key' => self::getApiKey()) |
|
61 | - )) : ""; |
|
59 | + $url = isset($options['url']) ? $options['url'].'?'.http_build_query(array_merge( |
|
60 | + $query, array('api_key' => self::getApiKey()) |
|
61 | + )) : ""; |
|
62 | 62 | |
63 | - $baseUrl = self::getBaseUrl(); |
|
63 | + $baseUrl = self::getBaseUrl(); |
|
64 | 64 | |
65 | - $curlOpts = array( |
|
66 | - CURLOPT_URL => $baseUrl.$url, |
|
67 | - CURLOPT_RETURNTRANSFER => true, |
|
68 | - CURLOPT_TIMEOUT => 80, |
|
69 | - CURLOPT_FOLLOWLOCATION => true, |
|
70 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
71 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
72 | - CURLOPT_HTTPHEADER => $headers |
|
73 | - ); |
|
65 | + $curlOpts = array( |
|
66 | + CURLOPT_URL => $baseUrl.$url, |
|
67 | + CURLOPT_RETURNTRANSFER => true, |
|
68 | + CURLOPT_TIMEOUT => 80, |
|
69 | + CURLOPT_FOLLOWLOCATION => true, |
|
70 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
71 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
72 | + CURLOPT_HTTPHEADER => $headers |
|
73 | + ); |
|
74 | 74 | |
75 | - curl_setopt_array($ch, $curlOpts); |
|
75 | + curl_setopt_array($ch, $curlOpts); |
|
76 | 76 | |
77 | - if ($file!=null) { |
|
78 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
79 | - $fp=fopen($file, 'r'); |
|
80 | - curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
81 | - curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
82 | - } |
|
77 | + if ($file!=null) { |
|
78 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
79 | + $fp=fopen($file, 'r'); |
|
80 | + curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
81 | + curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
82 | + } |
|
83 | 83 | |
84 | - switch ($method) { |
|
85 | - case 'DELETE': |
|
86 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
87 | - break; |
|
88 | - case 'DELETEARRAY': |
|
89 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
90 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
91 | - break; |
|
92 | - case 'PUT': |
|
93 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
94 | - break; |
|
95 | - case 'POST': |
|
96 | - if (isset($body)) { |
|
97 | - $bodyData = json_encode($body); |
|
98 | - if (isset($options['HTTPHEADER'])) { |
|
99 | - if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) { |
|
100 | - $bodyData = $body; |
|
101 | - } |
|
102 | - } |
|
84 | + switch ($method) { |
|
85 | + case 'DELETE': |
|
86 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
87 | + break; |
|
88 | + case 'DELETEARRAY': |
|
89 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
90 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
91 | + break; |
|
92 | + case 'PUT': |
|
93 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
94 | + break; |
|
95 | + case 'POST': |
|
96 | + if (isset($body)) { |
|
97 | + $bodyData = json_encode($body); |
|
98 | + if (isset($options['HTTPHEADER'])) { |
|
99 | + if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) { |
|
100 | + $bodyData = $body; |
|
101 | + } |
|
102 | + } |
|
103 | 103 | |
104 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
105 | - } |
|
106 | - break; |
|
107 | - case 'ADD': |
|
108 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
109 | - } |
|
104 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
105 | + } |
|
106 | + break; |
|
107 | + case 'ADD': |
|
108 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
109 | + } |
|
110 | 110 | |
111 | - if (is_numeric(array_search($method, array('DELETE', 'PUT')))) { |
|
112 | - if (isset($body)) { |
|
113 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
114 | - } |
|
115 | - } |
|
111 | + if (is_numeric(array_search($method, array('DELETE', 'PUT')))) { |
|
112 | + if (isset($body)) { |
|
113 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | - $result = curl_exec($ch); |
|
117 | + $result = curl_exec($ch); |
|
118 | 118 | |
119 | - $isxml = FALSE; |
|
120 | - $jxml = ""; |
|
121 | - if (strpos($result, '<?xml')>-1) { |
|
122 | - $xml = simplexml_load_string($result); |
|
123 | - //$jxml = json_encode($xml); |
|
124 | - $jxml = self::object2array($xml); |
|
125 | - $isxml = TRUE; |
|
126 | - } |
|
119 | + $isxml = FALSE; |
|
120 | + $jxml = ""; |
|
121 | + if (strpos($result, '<?xml')>-1) { |
|
122 | + $xml = simplexml_load_string($result); |
|
123 | + //$jxml = json_encode($xml); |
|
124 | + $jxml = self::object2array($xml); |
|
125 | + $isxml = TRUE; |
|
126 | + } |
|
127 | 127 | |
128 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
129 | - curl_close($ch); |
|
128 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
129 | + curl_close($ch); |
|
130 | 130 | |
131 | - if (200==$code) { |
|
132 | - if ($isxml) { |
|
133 | - $json = $jxml; |
|
134 | - } else { |
|
135 | - $json = json_decode($result, true); |
|
136 | - } |
|
131 | + if (200==$code) { |
|
132 | + if ($isxml) { |
|
133 | + $json = $jxml; |
|
134 | + } else { |
|
135 | + $json = json_decode($result, true); |
|
136 | + } |
|
137 | 137 | |
138 | - if (isset($json['errors'])) { |
|
139 | - throw new ApiError(implode(', ', $json['errors'])); |
|
140 | - } else { |
|
141 | - return $json; |
|
142 | - } |
|
143 | - } elseif (409==$code) { |
|
144 | - throw new ApiError('Wrong API key'); |
|
145 | - } else { |
|
146 | - throw new ApiError('Something wrong'); |
|
147 | - } |
|
148 | - } |
|
138 | + if (isset($json['errors'])) { |
|
139 | + throw new ApiError(implode(', ', $json['errors'])); |
|
140 | + } else { |
|
141 | + return $json; |
|
142 | + } |
|
143 | + } elseif (409==$code) { |
|
144 | + throw new ApiError('Wrong API key'); |
|
145 | + } else { |
|
146 | + throw new ApiError('Something wrong'); |
|
147 | + } |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * @param $object: JSON object |
|
152 | - */ |
|
153 | - public static function object2array($object) |
|
154 | - { |
|
155 | - return @json_decode(@json_encode($object), 1); |
|
156 | - } |
|
150 | + /** |
|
151 | + * @param $object: JSON object |
|
152 | + */ |
|
153 | + public static function object2array($object) |
|
154 | + { |
|
155 | + return @json_decode(@json_encode($object), 1); |
|
156 | + } |
|
157 | 157 | |
158 | 158 | |
159 | - /** |
|
160 | - * Prints on the screen main keys and values of the array |
|
161 | - * @param $results: object to be printed on the screen. |
|
162 | - * @param $deepPrinting: if true, object will be printed recursively. |
|
163 | - */ |
|
164 | - public static function simplePrint($results, $deepPrinting = null) |
|
165 | - { |
|
166 | - if (isset($results)) { |
|
167 | - if (is_array($results)) { |
|
168 | - foreach ($results as $key=>$result) { |
|
169 | - if (is_array($result)) { |
|
170 | - foreach ($result as $key1=>$result1) { |
|
171 | - if (is_array($result1)) { |
|
172 | - if ($deepPrinting) { |
|
173 | - echo "<br>$key1 ------><br>"; |
|
174 | - Route4Me::simplePrint($result1, true); |
|
175 | - echo "------<br>"; |
|
176 | - } else { |
|
177 | - echo $key1." --> "."Array() <br>"; |
|
178 | - } |
|
179 | - } else { |
|
180 | - if (is_object($result1)) { |
|
181 | - if ($deepPrinting) { |
|
182 | - echo "<br>$key1 ------><br>"; |
|
183 | - $oarray = (array)$result1; |
|
184 | - Route4Me::simplePrint($oarray, true); |
|
185 | - echo "------<br>"; |
|
186 | - } else { |
|
187 | - echo $key1." --> "."Object <br>"; |
|
188 | - } |
|
189 | - } else { |
|
190 | - if (!is_null($result1)) { |
|
191 | - echo $key1." --> ".$result1."<br>"; |
|
192 | - } |
|
193 | - } |
|
194 | - } |
|
195 | - } |
|
196 | - } else { |
|
197 | - if (is_object($result)) { |
|
198 | - if ($deepPrinting) { |
|
199 | - echo "<br>$key ------><br>"; |
|
200 | - $oarray = (array)$result; |
|
201 | - Route4Me::simplePrint($oarray, true); |
|
202 | - echo "------<br>"; |
|
203 | - } else { |
|
204 | - echo $key." --> "."Object <br>"; |
|
205 | - } |
|
206 | - } else { |
|
207 | - if (!is_null($result)) { |
|
208 | - echo $key." --> ".$result."<br>"; |
|
209 | - } |
|
210 | - } |
|
159 | + /** |
|
160 | + * Prints on the screen main keys and values of the array |
|
161 | + * @param $results: object to be printed on the screen. |
|
162 | + * @param $deepPrinting: if true, object will be printed recursively. |
|
163 | + */ |
|
164 | + public static function simplePrint($results, $deepPrinting = null) |
|
165 | + { |
|
166 | + if (isset($results)) { |
|
167 | + if (is_array($results)) { |
|
168 | + foreach ($results as $key=>$result) { |
|
169 | + if (is_array($result)) { |
|
170 | + foreach ($result as $key1=>$result1) { |
|
171 | + if (is_array($result1)) { |
|
172 | + if ($deepPrinting) { |
|
173 | + echo "<br>$key1 ------><br>"; |
|
174 | + Route4Me::simplePrint($result1, true); |
|
175 | + echo "------<br>"; |
|
176 | + } else { |
|
177 | + echo $key1." --> "."Array() <br>"; |
|
178 | + } |
|
179 | + } else { |
|
180 | + if (is_object($result1)) { |
|
181 | + if ($deepPrinting) { |
|
182 | + echo "<br>$key1 ------><br>"; |
|
183 | + $oarray = (array)$result1; |
|
184 | + Route4Me::simplePrint($oarray, true); |
|
185 | + echo "------<br>"; |
|
186 | + } else { |
|
187 | + echo $key1." --> "."Object <br>"; |
|
188 | + } |
|
189 | + } else { |
|
190 | + if (!is_null($result1)) { |
|
191 | + echo $key1." --> ".$result1."<br>"; |
|
192 | + } |
|
193 | + } |
|
194 | + } |
|
195 | + } |
|
196 | + } else { |
|
197 | + if (is_object($result)) { |
|
198 | + if ($deepPrinting) { |
|
199 | + echo "<br>$key ------><br>"; |
|
200 | + $oarray = (array)$result; |
|
201 | + Route4Me::simplePrint($oarray, true); |
|
202 | + echo "------<br>"; |
|
203 | + } else { |
|
204 | + echo $key." --> "."Object <br>"; |
|
205 | + } |
|
206 | + } else { |
|
207 | + if (!is_null($result)) { |
|
208 | + echo $key." --> ".$result."<br>"; |
|
209 | + } |
|
210 | + } |
|
211 | 211 | |
212 | - } |
|
213 | - //echo "<br>"; |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - } |
|
212 | + } |
|
213 | + //echo "<br>"; |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Generates query or body parameters. |
|
221 | - * @param $allFields: all known fields could be used for parameters generation. |
|
222 | - * @param $params: input parameters (array or object) |
|
223 | - */ |
|
224 | - public static function generateRequestParameters($allFields, $params) |
|
225 | - { |
|
226 | - $generatedParams = array(); |
|
219 | + /** |
|
220 | + * Generates query or body parameters. |
|
221 | + * @param $allFields: all known fields could be used for parameters generation. |
|
222 | + * @param $params: input parameters (array or object) |
|
223 | + */ |
|
224 | + public static function generateRequestParameters($allFields, $params) |
|
225 | + { |
|
226 | + $generatedParams = array(); |
|
227 | 227 | |
228 | - if (is_array($params)) { |
|
229 | - foreach ($allFields as $field) { |
|
230 | - if (isset($params[$field])) { |
|
231 | - $generatedParams[$field] = $params[$field]; |
|
232 | - } |
|
233 | - } |
|
234 | - } elseif (is_object($params)) { |
|
235 | - foreach ($allFields as $field) { |
|
236 | - if (isset($params->{$field})) { |
|
237 | - $generatedParams[$field] = $params->{$field}; |
|
238 | - } |
|
239 | - } |
|
240 | - } |
|
228 | + if (is_array($params)) { |
|
229 | + foreach ($allFields as $field) { |
|
230 | + if (isset($params[$field])) { |
|
231 | + $generatedParams[$field] = $params[$field]; |
|
232 | + } |
|
233 | + } |
|
234 | + } elseif (is_object($params)) { |
|
235 | + foreach ($allFields as $field) { |
|
236 | + if (isset($params->{$field})) { |
|
237 | + $generatedParams[$field] = $params->{$field}; |
|
238 | + } |
|
239 | + } |
|
240 | + } |
|
241 | 241 | |
242 | - return $generatedParams; |
|
243 | - } |
|
242 | + return $generatedParams; |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * Returns an array of the object properties |
|
247 | - * @param $object: An object. |
|
248 | - * @param $exclude: array of the object parameters to be excluded from the returned array. |
|
249 | - */ |
|
250 | - public static function getObjectProperties($object, $exclude) |
|
251 | - { |
|
252 | - $objectParameters = array(); |
|
245 | + /** |
|
246 | + * Returns an array of the object properties |
|
247 | + * @param $object: An object. |
|
248 | + * @param $exclude: array of the object parameters to be excluded from the returned array. |
|
249 | + */ |
|
250 | + public static function getObjectProperties($object, $exclude) |
|
251 | + { |
|
252 | + $objectParameters = array(); |
|
253 | 253 | |
254 | - foreach (get_object_vars($object) as $key => $value) { |
|
255 | - if (property_exists($object, $key)) { |
|
256 | - if (!is_numeric(array_search($key, $exclude))) { |
|
257 | - array_push($objectParameters, $key); |
|
258 | - } |
|
259 | - } |
|
260 | - } |
|
254 | + foreach (get_object_vars($object) as $key => $value) { |
|
255 | + if (property_exists($object, $key)) { |
|
256 | + if (!is_numeric(array_search($key, $exclude))) { |
|
257 | + array_push($objectParameters, $key); |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | - return $objectParameters; |
|
263 | - } |
|
262 | + return $objectParameters; |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * Returns url path generated from the array of the fields and parameters. |
|
267 | - * @param $allFields; array of the paossible fields (parameter names). |
|
268 | - * @param $params: input parameters (array or object). |
|
269 | - */ |
|
270 | - public static function generateUrlPath($allFields, $params) |
|
271 | - { |
|
272 | - $generatedPath = ""; |
|
265 | + /** |
|
266 | + * Returns url path generated from the array of the fields and parameters. |
|
267 | + * @param $allFields; array of the paossible fields (parameter names). |
|
268 | + * @param $params: input parameters (array or object). |
|
269 | + */ |
|
270 | + public static function generateUrlPath($allFields, $params) |
|
271 | + { |
|
272 | + $generatedPath = ""; |
|
273 | 273 | |
274 | - if (is_array($params)) { |
|
275 | - foreach ($allFields as $field) { |
|
276 | - if (isset($params[$field])) { |
|
277 | - $generatedPath .= $params[$field].'/'; |
|
278 | - } |
|
279 | - } |
|
280 | - } elseif (is_object($params)) { |
|
281 | - foreach ($allFields as $field) { |
|
282 | - if (isset($params->{$field})) { |
|
283 | - $generatedPath .= $params->{$field}.'/'; |
|
284 | - } |
|
285 | - } |
|
286 | - } |
|
274 | + if (is_array($params)) { |
|
275 | + foreach ($allFields as $field) { |
|
276 | + if (isset($params[$field])) { |
|
277 | + $generatedPath .= $params[$field].'/'; |
|
278 | + } |
|
279 | + } |
|
280 | + } elseif (is_object($params)) { |
|
281 | + foreach ($allFields as $field) { |
|
282 | + if (isset($params->{$field})) { |
|
283 | + $generatedPath .= $params->{$field}.'/'; |
|
284 | + } |
|
285 | + } |
|
286 | + } |
|
287 | 287 | |
288 | - return $generatedPath; |
|
289 | - } |
|
288 | + return $generatedPath; |
|
289 | + } |
|
290 | 290 | |
291 | - public static function getFileRealPath($fileName) |
|
292 | - { |
|
293 | - $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
291 | + public static function getFileRealPath($fileName) |
|
292 | + { |
|
293 | + $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
294 | 294 | |
295 | - return $rpath; |
|
296 | - } |
|
295 | + return $rpath; |
|
296 | + } |
|
297 | 297 | } |
@@ -27,23 +27,23 @@ discard block |
||
27 | 27 | $addresses = array(); |
28 | 28 | |
29 | 29 | foreach ($json as $address) { |
30 | - $addresses[] = Address::fromArray($address); |
|
30 | + $addresses[] = Address::fromArray($address); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | $parameters = RouteParameters::fromArray(array( |
34 | - "algorithm_type" => Algorithmtype::CVRP_TW_SD, |
|
35 | - "route_name" => "Multiple Depot, Multiple Driver, Time Window", |
|
36 | - "route_date" => time() + 24 * 60 * 60, |
|
37 | - "route_time" => 60 * 60 * 7, |
|
38 | - "rt" => TRUE, |
|
39 | - "distance_unit" => DistanceUnit::MILES, |
|
40 | - "device_type" => DeviceType::WEB, |
|
41 | - "optimize" => OptimizationType::TIME, |
|
42 | - "metric" => Metric::GEODESIC, |
|
43 | - "route_max_duration" => 86400 * 3, |
|
44 | - "travel_mode" => TravelMode::DRIVING, |
|
45 | - "vehicle_capacity" => 99, |
|
46 | - "vehicle_max_distance_mi" => 99999 |
|
34 | + "algorithm_type" => Algorithmtype::CVRP_TW_SD, |
|
35 | + "route_name" => "Multiple Depot, Multiple Driver, Time Window", |
|
36 | + "route_date" => time() + 24 * 60 * 60, |
|
37 | + "route_time" => 60 * 60 * 7, |
|
38 | + "rt" => TRUE, |
|
39 | + "distance_unit" => DistanceUnit::MILES, |
|
40 | + "device_type" => DeviceType::WEB, |
|
41 | + "optimize" => OptimizationType::TIME, |
|
42 | + "metric" => Metric::GEODESIC, |
|
43 | + "route_max_duration" => 86400 * 3, |
|
44 | + "travel_mode" => TravelMode::DRIVING, |
|
45 | + "vehicle_capacity" => 99, |
|
46 | + "vehicle_max_distance_mi" => 99999 |
|
47 | 47 | )); |
48 | 48 | |
49 | 49 | $optimizationParams = new OptimizationProblemParams; |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | $problem = OptimizationProblem::optimize($optimizationParams); |
54 | 54 | |
55 | 55 | foreach ((array)$problem as $key => $value) { |
56 | - if (is_string($value)) { |
|
57 | - echo $key." --> ".$value."<br>"; |
|
58 | - } else { |
|
59 | - echo "************ $key ************* <br>"; |
|
60 | - Route4Me::simplePrint((array)$value, true); |
|
61 | - echo "******************************* <br>"; |
|
62 | - } |
|
56 | + if (is_string($value)) { |
|
57 | + echo $key." --> ".$value."<br>"; |
|
58 | + } else { |
|
59 | + echo "************ $key ************* <br>"; |
|
60 | + Route4Me::simplePrint((array)$value, true); |
|
61 | + echo "******************************* <br>"; |
|
62 | + } |
|
63 | 63 | } |
@@ -6,78 +6,78 @@ |
||
6 | 6 | |
7 | 7 | class ActivityParameters extends Common |
8 | 8 | { |
9 | - public $route_id; |
|
10 | - public $device_id; |
|
11 | - public $member_id; |
|
12 | - public $team; |
|
13 | - public $limit; |
|
14 | - public $offset; |
|
15 | - public $start; |
|
16 | - public $end; |
|
17 | - public $activity_type; |
|
18 | - public $activity_message; |
|
9 | + public $route_id; |
|
10 | + public $device_id; |
|
11 | + public $member_id; |
|
12 | + public $team; |
|
13 | + public $limit; |
|
14 | + public $offset; |
|
15 | + public $start; |
|
16 | + public $end; |
|
17 | + public $activity_type; |
|
18 | + public $activity_message; |
|
19 | 19 | |
20 | - public $activity_id; |
|
21 | - public $activity_timestamp; |
|
22 | - public $route_destination_id; |
|
23 | - public $note_id; |
|
24 | - public $member; |
|
25 | - public $note_type; |
|
26 | - public $note_contents; |
|
27 | - public $route_name; |
|
28 | - public $note_file; |
|
29 | - public $destination_name; |
|
30 | - public $destination_alias; |
|
20 | + public $activity_id; |
|
21 | + public $activity_timestamp; |
|
22 | + public $route_destination_id; |
|
23 | + public $note_id; |
|
24 | + public $member; |
|
25 | + public $note_type; |
|
26 | + public $note_contents; |
|
27 | + public $route_name; |
|
28 | + public $note_file; |
|
29 | + public $destination_name; |
|
30 | + public $destination_alias; |
|
31 | 31 | |
32 | - public static function fromArray(array $params) |
|
33 | - { |
|
34 | - $activityparameters = new ActivityParameters(); |
|
32 | + public static function fromArray(array $params) |
|
33 | + { |
|
34 | + $activityparameters = new ActivityParameters(); |
|
35 | 35 | |
36 | - foreach ($params as $key => $value) { |
|
37 | - if (property_exists($activityparameters, $key)) { |
|
38 | - $activityparameters->{$key} = $value; |
|
39 | - } |
|
40 | - } |
|
36 | + foreach ($params as $key => $value) { |
|
37 | + if (property_exists($activityparameters, $key)) { |
|
38 | + $activityparameters->{$key} = $value; |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - return $activityparameters; |
|
43 | - } |
|
42 | + return $activityparameters; |
|
43 | + } |
|
44 | 44 | |
45 | - public static function getActivities($params) |
|
46 | - { |
|
47 | - $allQueryFields = array('route_id', 'team', 'limit', 'offset', 'start'); |
|
45 | + public static function getActivities($params) |
|
46 | + { |
|
47 | + $allQueryFields = array('route_id', 'team', 'limit', 'offset', 'start'); |
|
48 | 48 | |
49 | - $activity = Route4Me::makeRequst(array( |
|
50 | - 'url' => Endpoint::GET_ACTIVITIES, |
|
51 | - 'method' => 'GET', |
|
52 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
53 | - )); |
|
49 | + $activity = Route4Me::makeRequst(array( |
|
50 | + 'url' => Endpoint::GET_ACTIVITIES, |
|
51 | + 'method' => 'GET', |
|
52 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
53 | + )); |
|
54 | 54 | |
55 | - return $activity; |
|
56 | - } |
|
55 | + return $activity; |
|
56 | + } |
|
57 | 57 | |
58 | - public static function searcActivities($params) |
|
59 | - { |
|
60 | - $allQueryFields = array('route_id', 'limit', 'offset', 'activity_type'); |
|
58 | + public static function searcActivities($params) |
|
59 | + { |
|
60 | + $allQueryFields = array('route_id', 'limit', 'offset', 'activity_type'); |
|
61 | 61 | |
62 | - $activity = Route4Me::makeRequst(array( |
|
63 | - 'url' => Endpoint::GET_ACTIVITIES, |
|
64 | - 'method' => 'GET', |
|
65 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
66 | - )); |
|
62 | + $activity = Route4Me::makeRequst(array( |
|
63 | + 'url' => Endpoint::GET_ACTIVITIES, |
|
64 | + 'method' => 'GET', |
|
65 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
|
66 | + )); |
|
67 | 67 | |
68 | - return $activity; |
|
69 | - } |
|
68 | + return $activity; |
|
69 | + } |
|
70 | 70 | |
71 | - public static function sendUserMessage($params) |
|
72 | - { |
|
73 | - $allBodyFields = array('activity_type', 'activity_message', 'route_id'); |
|
71 | + public static function sendUserMessage($params) |
|
72 | + { |
|
73 | + $allBodyFields = array('activity_type', 'activity_message', 'route_id'); |
|
74 | 74 | |
75 | - $result = Route4Me::makeRequst(array( |
|
76 | - 'url' => Endpoint::ACTIVITY_FEED, |
|
77 | - 'method' => 'POST', |
|
78 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
79 | - )); |
|
75 | + $result = Route4Me::makeRequst(array( |
|
76 | + 'url' => Endpoint::ACTIVITY_FEED, |
|
77 | + 'method' => 'POST', |
|
78 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
79 | + )); |
|
80 | 80 | |
81 | - return $result; |
|
82 | - } |
|
81 | + return $result; |
|
82 | + } |
|
83 | 83 | } |
@@ -7,93 +7,93 @@ |
||
7 | 7 | |
8 | 8 | class OptimizationProblemParams extends Common |
9 | 9 | { |
10 | - public $optimization_problem_id; |
|
11 | - public $reoptimize; |
|
12 | - public $addresses = array(); |
|
13 | - public $parameters; |
|
14 | - public $directions; |
|
15 | - public $format; |
|
16 | - public $route_path_output; |
|
17 | - public $optimized_callback_url; |
|
18 | - public $redirect = true; |
|
10 | + public $optimization_problem_id; |
|
11 | + public $reoptimize; |
|
12 | + public $addresses = array(); |
|
13 | + public $parameters; |
|
14 | + public $directions; |
|
15 | + public $format; |
|
16 | + public $route_path_output; |
|
17 | + public $optimized_callback_url; |
|
18 | + public $redirect = true; |
|
19 | 19 | |
20 | - public static function fromArray($params) |
|
21 | - { |
|
22 | - $param = new OptimizationProblemParams; |
|
23 | - if (!isset($params['addresses'])) { |
|
24 | - throw new BadParam('addresses must be provided.'); |
|
25 | - } |
|
20 | + public static function fromArray($params) |
|
21 | + { |
|
22 | + $param = new OptimizationProblemParams; |
|
23 | + if (!isset($params['addresses'])) { |
|
24 | + throw new BadParam('addresses must be provided.'); |
|
25 | + } |
|
26 | 26 | |
27 | - if (!isset($params['parameters'])) { |
|
28 | - throw new BadParam('parameters must be provided.'); |
|
29 | - } |
|
27 | + if (!isset($params['parameters'])) { |
|
28 | + throw new BadParam('parameters must be provided.'); |
|
29 | + } |
|
30 | 30 | |
31 | - if ($params['parameters'] instanceof RouteParameters) { |
|
32 | - $param->setParameters($params['parameters']); |
|
33 | - } else { |
|
34 | - $param->setParameters(RouteParameters::fromArray($params['parameters'])); |
|
35 | - } |
|
31 | + if ($params['parameters'] instanceof RouteParameters) { |
|
32 | + $param->setParameters($params['parameters']); |
|
33 | + } else { |
|
34 | + $param->setParameters(RouteParameters::fromArray($params['parameters'])); |
|
35 | + } |
|
36 | 36 | |
37 | - foreach ($params['addresses'] as $address) { |
|
38 | - if (!($address instanceof Address)) { |
|
39 | - $address = Address::fromArray($address); |
|
40 | - } |
|
37 | + foreach ($params['addresses'] as $address) { |
|
38 | + if (!($address instanceof Address)) { |
|
39 | + $address = Address::fromArray($address); |
|
40 | + } |
|
41 | 41 | |
42 | - $param->addAddress($address); |
|
43 | - } |
|
42 | + $param->addAddress($address); |
|
43 | + } |
|
44 | 44 | |
45 | - $param->directions = self::getValue($params, 'directions'); |
|
46 | - $param->format = self::getValue($params, 'format'); |
|
47 | - $param->route_path_output = self::getValue($params, 'route_path_output'); |
|
48 | - $param->optimized_callback_url = self::getValue($params, 'optimized_callback_url'); |
|
49 | - $param->optimization_problem_id = self::getValue($params, 'optimization_problem_id'); |
|
50 | - $param->reoptimize = self::getValue($params, 'reoptimize'); |
|
51 | - $param->redirect = filter_var(self::getValue($params, 'redirect', true), FILTER_VALIDATE_BOOLEAN); |
|
45 | + $param->directions = self::getValue($params, 'directions'); |
|
46 | + $param->format = self::getValue($params, 'format'); |
|
47 | + $param->route_path_output = self::getValue($params, 'route_path_output'); |
|
48 | + $param->optimized_callback_url = self::getValue($params, 'optimized_callback_url'); |
|
49 | + $param->optimization_problem_id = self::getValue($params, 'optimization_problem_id'); |
|
50 | + $param->reoptimize = self::getValue($params, 'reoptimize'); |
|
51 | + $param->redirect = filter_var(self::getValue($params, 'redirect', true), FILTER_VALIDATE_BOOLEAN); |
|
52 | 52 | |
53 | - return $param; |
|
54 | - } |
|
53 | + return $param; |
|
54 | + } |
|
55 | 55 | |
56 | - public function __construct() |
|
57 | - { |
|
58 | - $this->parameters = new RouteParameters; |
|
59 | - } |
|
56 | + public function __construct() |
|
57 | + { |
|
58 | + $this->parameters = new RouteParameters; |
|
59 | + } |
|
60 | 60 | |
61 | - public function setParameters(RouteParameters $params) |
|
62 | - { |
|
63 | - $this->parameters = $params; |
|
61 | + public function setParameters(RouteParameters $params) |
|
62 | + { |
|
63 | + $this->parameters = $params; |
|
64 | 64 | |
65 | - return $this; |
|
66 | - } |
|
65 | + return $this; |
|
66 | + } |
|
67 | 67 | |
68 | - public function addAddress(Address $address) |
|
69 | - { |
|
70 | - $this->addresses[] = $address; |
|
68 | + public function addAddress(Address $address) |
|
69 | + { |
|
70 | + $this->addresses[] = $address; |
|
71 | 71 | |
72 | - return $this; |
|
73 | - } |
|
72 | + return $this; |
|
73 | + } |
|
74 | 74 | |
75 | - public function getAddressesArray() |
|
76 | - { |
|
77 | - $addresses = array(); |
|
75 | + public function getAddressesArray() |
|
76 | + { |
|
77 | + $addresses = array(); |
|
78 | 78 | |
79 | - foreach ($this->addresses as $address) { |
|
80 | - $addresses[] = $address->toArray(); |
|
81 | - } |
|
79 | + foreach ($this->addresses as $address) { |
|
80 | + $addresses[] = $address->toArray(); |
|
81 | + } |
|
82 | 82 | |
83 | - return $addresses; |
|
84 | - } |
|
83 | + return $addresses; |
|
84 | + } |
|
85 | 85 | |
86 | - public function getParametersArray() |
|
87 | - { |
|
88 | - return $this->parameters->toArray(); |
|
89 | - } |
|
86 | + public function getParametersArray() |
|
87 | + { |
|
88 | + return $this->parameters->toArray(); |
|
89 | + } |
|
90 | 90 | |
91 | - public function setAddresses(array $addresses) |
|
92 | - { |
|
93 | - foreach ($addresses as $address) { |
|
94 | - $this->addAddress($address); |
|
95 | - } |
|
91 | + public function setAddresses(array $addresses) |
|
92 | + { |
|
93 | + foreach ($addresses as $address) { |
|
94 | + $this->addAddress($address); |
|
95 | + } |
|
96 | 96 | |
97 | - return $this; |
|
98 | - } |
|
97 | + return $this; |
|
98 | + } |
|
99 | 99 | } |