@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | class TravelMode |
6 | 6 | { |
7 | - const DRIVING = 'Driving'; |
|
8 | - const WALKING = 'Walking'; |
|
9 | - const TRUCKING = 'Trucking'; |
|
7 | + const DRIVING = 'Driving'; |
|
8 | + const WALKING = 'Walking'; |
|
9 | + const TRUCKING = 'Trucking'; |
|
10 | 10 | } |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | class DirectionMethod |
6 | 6 | { |
7 | - const VIRTUALEARTH = 1; |
|
8 | - const GOOGLE = 2; |
|
9 | - const HERE = 3; |
|
7 | + const VIRTUALEARTH = 1; |
|
8 | + const GOOGLE = 2; |
|
9 | + const HERE = 3; |
|
10 | 10 | } |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | class AlgorithmType |
6 | 6 | { |
7 | - const TSP = 1; |
|
8 | - const VRP = 2; |
|
9 | - const CVRP_TW_SD = 3; |
|
10 | - const CVRP_TW_MD = 4; |
|
11 | - const TSP_TW = 5; |
|
12 | - const TSP_TW_CR = 6; |
|
13 | - const BBCVRP = 7; |
|
7 | + const TSP = 1; |
|
8 | + const VRP = 2; |
|
9 | + const CVRP_TW_SD = 3; |
|
10 | + const CVRP_TW_MD = 4; |
|
11 | + const TSP_TW = 5; |
|
12 | + const TSP_TW_CR = 6; |
|
13 | + const BBCVRP = 7; |
|
14 | 14 | } |
@@ -6,74 +6,74 @@ discard block |
||
6 | 6 | |
7 | 7 | class Route4Me |
8 | 8 | { |
9 | - static public $apiKey; |
|
10 | - static public $baseUrl = 'https://route4me.com'; |
|
9 | + static public $apiKey; |
|
10 | + static public $baseUrl = 'https://route4me.com'; |
|
11 | 11 | |
12 | - public static function setApiKey($apiKey) |
|
13 | - { |
|
14 | - self::$apiKey = $apiKey; |
|
15 | - } |
|
12 | + public static function setApiKey($apiKey) |
|
13 | + { |
|
14 | + self::$apiKey = $apiKey; |
|
15 | + } |
|
16 | 16 | |
17 | - public static function getApiKey() |
|
18 | - { |
|
19 | - return self::$apiKey; |
|
20 | - } |
|
17 | + public static function getApiKey() |
|
18 | + { |
|
19 | + return self::$apiKey; |
|
20 | + } |
|
21 | 21 | |
22 | - public static function setBaseUrl($baseUrl) |
|
23 | - { |
|
24 | - self::$baseUrl = $baseUrl; |
|
25 | - } |
|
22 | + public static function setBaseUrl($baseUrl) |
|
23 | + { |
|
24 | + self::$baseUrl = $baseUrl; |
|
25 | + } |
|
26 | 26 | |
27 | - public static function getBaseUrl() |
|
28 | - { |
|
29 | - return self::$baseUrl; |
|
30 | - } |
|
27 | + public static function getBaseUrl() |
|
28 | + { |
|
29 | + return self::$baseUrl; |
|
30 | + } |
|
31 | 31 | |
32 | - public static function makeRequst($options) { |
|
33 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
34 | - $query = isset($options['query']) ? |
|
35 | - array_filter($options['query']) : array(); |
|
36 | - $body = isset($options['body']) ? |
|
37 | - array_filter($options['body']) : null; |
|
32 | + public static function makeRequst($options) { |
|
33 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
34 | + $query = isset($options['query']) ? |
|
35 | + array_filter($options['query']) : array(); |
|
36 | + $body = isset($options['body']) ? |
|
37 | + array_filter($options['body']) : null; |
|
38 | 38 | $httpHeader = isset($options['HTTPHEADER']) ? $options['HTTPHEADER'] : null; |
39 | 39 | |
40 | - $ch = curl_init(); |
|
41 | - $url = $options['url'] . '?' . http_build_query(array_merge( |
|
42 | - $query, array( 'api_key' => self::getApiKey()) |
|
43 | - )); |
|
40 | + $ch = curl_init(); |
|
41 | + $url = $options['url'] . '?' . http_build_query(array_merge( |
|
42 | + $query, array( 'api_key' => self::getApiKey()) |
|
43 | + )); |
|
44 | 44 | |
45 | 45 | //$jfile=json_encode($body); echo $jfile; die(""); |
46 | 46 | $baseUrl=self::getBaseUrl(); |
47 | 47 | |
48 | 48 | if (strpos($url,'move_route_destination')>0) $baseUrl='https://www.route4me.com'; |
49 | - $curlOpts = arraY( |
|
50 | - CURLOPT_URL => $baseUrl. $url, |
|
51 | - CURLOPT_RETURNTRANSFER => true, |
|
52 | - CURLOPT_TIMEOUT => 60, |
|
53 | - CURLOPT_FOLLOWLOCATION => true, |
|
54 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
55 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
56 | - CURLOPT_HTTPHEADER => array( |
|
57 | - 'User-Agent' => 'Route4Me php-sdk' |
|
58 | - ) |
|
59 | - ); |
|
49 | + $curlOpts = arraY( |
|
50 | + CURLOPT_URL => $baseUrl. $url, |
|
51 | + CURLOPT_RETURNTRANSFER => true, |
|
52 | + CURLOPT_TIMEOUT => 60, |
|
53 | + CURLOPT_FOLLOWLOCATION => true, |
|
54 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
55 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
56 | + CURLOPT_HTTPHEADER => array( |
|
57 | + 'User-Agent' => 'Route4Me php-sdk' |
|
58 | + ) |
|
59 | + ); |
|
60 | 60 | //echo "url=".$baseUrl.$url."<br>";die(""); |
61 | - curl_setopt_array($ch, $curlOpts); |
|
62 | - switch($method) { |
|
63 | - case 'DELETE': |
|
64 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
61 | + curl_setopt_array($ch, $curlOpts); |
|
62 | + switch($method) { |
|
63 | + case 'DELETE': |
|
64 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
65 | 65 | |
66 | 66 | if (isset($body)) { |
67 | 67 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
68 | 68 | } |
69 | - break; |
|
69 | + break; |
|
70 | 70 | case 'DELETEARRAY': |
71 | 71 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
72 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
73 | - break; |
|
74 | - case 'PUT': |
|
72 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
73 | + break; |
|
74 | + case 'PUT': |
|
75 | 75 | //$jfile=json_encode($body); echo $jfile; die(""); |
76 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
76 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
77 | 77 | if (isset($query)) { |
78 | 78 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
79 | 79 | } |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
83 | 83 | } |
84 | 84 | break; |
85 | - case 'POST': |
|
85 | + case 'POST': |
|
86 | 86 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
87 | 87 | if (isset($query)) { |
88 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
88 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | if (isset($body)) { |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | } |
94 | 94 | break; |
95 | 95 | case 'ADD': |
96 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
97 | - } |
|
96 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | if ($httpHeader!=null) curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader); |
100 | 100 | |
101 | - $result = curl_exec($ch); |
|
101 | + $result = curl_exec($ch); |
|
102 | 102 | //var_dump($result); die(""); |
103 | 103 | $isxml=FALSE; |
104 | 104 | $jxml=""; |
@@ -109,58 +109,58 @@ discard block |
||
109 | 109 | $isxml = TRUE; |
110 | 110 | } |
111 | 111 | |
112 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
113 | - curl_close($ch); |
|
112 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
113 | + curl_close($ch); |
|
114 | 114 | |
115 | 115 | if ($isxml) { |
116 | 116 | $json = $jxml; |
117 | 117 | } else $json = json_decode($result, true); |
118 | 118 | //var_dump($json); die(""); |
119 | - if (200 == $code) { |
|
120 | - return $json; |
|
121 | - } elseif (isset($json['errors'])) { |
|
122 | - throw new ApiError(implode(', ', $json['errors'])); |
|
123 | - } else { |
|
124 | - throw new ApiError('Something wrong'); |
|
125 | - } |
|
126 | - } |
|
119 | + if (200 == $code) { |
|
120 | + return $json; |
|
121 | + } elseif (isset($json['errors'])) { |
|
122 | + throw new ApiError(implode(', ', $json['errors'])); |
|
123 | + } else { |
|
124 | + throw new ApiError('Something wrong'); |
|
125 | + } |
|
126 | + } |
|
127 | 127 | |
128 | 128 | public static function makeUrlRequst($url, $options) { |
129 | 129 | $method = isset($options['method']) ? $options['method'] : 'GET'; |
130 | - $query = isset($options['query']) ? |
|
131 | - array_filter($options['query']) : array(); |
|
132 | - $body = isset($options['body']) ? |
|
133 | - array_filter($options['body']) : null; |
|
134 | - $ch = curl_init(); |
|
130 | + $query = isset($options['query']) ? |
|
131 | + array_filter($options['query']) : array(); |
|
132 | + $body = isset($options['body']) ? |
|
133 | + array_filter($options['body']) : null; |
|
134 | + $ch = curl_init(); |
|
135 | 135 | |
136 | 136 | $curlOpts = arraY( |
137 | - CURLOPT_URL => $url, |
|
138 | - CURLOPT_RETURNTRANSFER => true, |
|
139 | - CURLOPT_TIMEOUT => 60, |
|
140 | - CURLOPT_FOLLOWLOCATION => true, |
|
141 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
142 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
143 | - CURLOPT_HTTPHEADER => array( |
|
144 | - 'User-Agent' => 'Route4Me php-sdk' |
|
145 | - ) |
|
146 | - ); |
|
137 | + CURLOPT_URL => $url, |
|
138 | + CURLOPT_RETURNTRANSFER => true, |
|
139 | + CURLOPT_TIMEOUT => 60, |
|
140 | + CURLOPT_FOLLOWLOCATION => true, |
|
141 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
142 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
143 | + CURLOPT_HTTPHEADER => array( |
|
144 | + 'User-Agent' => 'Route4Me php-sdk' |
|
145 | + ) |
|
146 | + ); |
|
147 | 147 | |
148 | 148 | curl_setopt_array($ch, $curlOpts); |
149 | 149 | |
150 | - switch($method) { |
|
151 | - case 'DELETE': |
|
152 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
150 | + switch($method) { |
|
151 | + case 'DELETE': |
|
152 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
153 | 153 | |
154 | 154 | if (isset($body)) { |
155 | 155 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
156 | 156 | } |
157 | - break; |
|
157 | + break; |
|
158 | 158 | case 'DELETEARRAY': |
159 | 159 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
160 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
161 | - break; |
|
162 | - case 'PUT': |
|
163 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
160 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
161 | + break; |
|
162 | + case 'PUT': |
|
163 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
164 | 164 | if (isset($query)) { |
165 | 165 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
166 | 166 | } |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
170 | 170 | } |
171 | 171 | break; |
172 | - case 'POST': |
|
172 | + case 'POST': |
|
173 | 173 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
174 | 174 | if (isset($query)) { |
175 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
175 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | if (isset($body)) { |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | } |
181 | 181 | break; |
182 | 182 | case 'ADD': |
183 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
184 | - } |
|
183 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
184 | + } |
|
185 | 185 | |
186 | 186 | $result = curl_exec($ch); |
187 | 187 | $isxml=FALSE; |
@@ -193,20 +193,20 @@ discard block |
||
193 | 193 | $isxml = TRUE; |
194 | 194 | } |
195 | 195 | |
196 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
197 | - curl_close($ch); |
|
196 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
197 | + curl_close($ch); |
|
198 | 198 | |
199 | 199 | if ($isxml) { |
200 | 200 | $json = $jxml; |
201 | 201 | } else $json = json_decode($result, true); |
202 | 202 | |
203 | - if (200 == $code) { |
|
204 | - return $json; |
|
205 | - } elseif (isset($json['errors'])) { |
|
206 | - throw new ApiError(implode(', ', $json['errors'])); |
|
207 | - } else { |
|
208 | - throw new ApiError('Something wrong'); |
|
209 | - } |
|
203 | + if (200 == $code) { |
|
204 | + return $json; |
|
205 | + } elseif (isset($json['errors'])) { |
|
206 | + throw new ApiError(implode(', ', $json['errors'])); |
|
207 | + } else { |
|
208 | + throw new ApiError('Something wrong'); |
|
209 | + } |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -8,85 +8,85 @@ |
||
8 | 8 | |
9 | 9 | class OptimizationProblemParams extends Common |
10 | 10 | { |
11 | - public $optimization_problem_id; |
|
12 | - public $reoptimize; |
|
13 | - public $addresses = array(); |
|
14 | - public $parameters; |
|
15 | - public $directions; |
|
16 | - public $format; |
|
17 | - public $route_path_output; |
|
18 | - public $optimized_callback_url; |
|
11 | + public $optimization_problem_id; |
|
12 | + public $reoptimize; |
|
13 | + public $addresses = array(); |
|
14 | + public $parameters; |
|
15 | + public $directions; |
|
16 | + public $format; |
|
17 | + public $route_path_output; |
|
18 | + public $optimized_callback_url; |
|
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 | - } |
|
41 | - $param->addAddress($address); |
|
42 | - } |
|
37 | + foreach($params['addresses'] as $address) { |
|
38 | + if (!($address instanceof Address)) { |
|
39 | + $address = Address::fromArray($address); |
|
40 | + } |
|
41 | + $param->addAddress($address); |
|
42 | + } |
|
43 | 43 | |
44 | - $param->directions = self::getValue($params, 'directions'); |
|
45 | - $param->format = self::getValue($params, 'format'); |
|
46 | - $param->route_path_output = self::getValue($params, 'route_path_output'); |
|
47 | - $param->optimized_callback_url = self::getValue($params, 'optimized_callback_url'); |
|
48 | - $param->optimization_problem_id = self::getValue($params, 'optimization_problem_id'); |
|
49 | - $param->reoptimize = self::getValue($params, 'reoptimize'); |
|
44 | + $param->directions = self::getValue($params, 'directions'); |
|
45 | + $param->format = self::getValue($params, 'format'); |
|
46 | + $param->route_path_output = self::getValue($params, 'route_path_output'); |
|
47 | + $param->optimized_callback_url = self::getValue($params, 'optimized_callback_url'); |
|
48 | + $param->optimization_problem_id = self::getValue($params, 'optimization_problem_id'); |
|
49 | + $param->reoptimize = self::getValue($params, 'reoptimize'); |
|
50 | 50 | |
51 | - return $param; |
|
52 | - } |
|
51 | + return $param; |
|
52 | + } |
|
53 | 53 | |
54 | - public function __construct() |
|
55 | - { |
|
56 | - $this->parameters = new RouteParameters; |
|
57 | - } |
|
54 | + public function __construct() |
|
55 | + { |
|
56 | + $this->parameters = new RouteParameters; |
|
57 | + } |
|
58 | 58 | |
59 | - public function setParameters(RouteParameters $params) |
|
60 | - { |
|
61 | - $this->parameters = $params; |
|
62 | - return $this; |
|
63 | - } |
|
59 | + public function setParameters(RouteParameters $params) |
|
60 | + { |
|
61 | + $this->parameters = $params; |
|
62 | + return $this; |
|
63 | + } |
|
64 | 64 | |
65 | - public function addAddress(Address $address) |
|
66 | - { |
|
67 | - $this->addresses[] = $address; |
|
68 | - return $this; |
|
69 | - } |
|
65 | + public function addAddress(Address $address) |
|
66 | + { |
|
67 | + $this->addresses[] = $address; |
|
68 | + return $this; |
|
69 | + } |
|
70 | 70 | |
71 | - public function getAddressesArray() |
|
72 | - { |
|
73 | - $addresses = array(); |
|
74 | - foreach($this->addresses as $address) { |
|
75 | - $addresses[] = $address->toArray(); |
|
76 | - } |
|
77 | - return $addresses; |
|
78 | - } |
|
71 | + public function getAddressesArray() |
|
72 | + { |
|
73 | + $addresses = array(); |
|
74 | + foreach($this->addresses as $address) { |
|
75 | + $addresses[] = $address->toArray(); |
|
76 | + } |
|
77 | + return $addresses; |
|
78 | + } |
|
79 | 79 | |
80 | - public function getParametersArray() |
|
81 | - { |
|
82 | - return $this->parameters->toArray(); |
|
83 | - } |
|
80 | + public function getParametersArray() |
|
81 | + { |
|
82 | + return $this->parameters->toArray(); |
|
83 | + } |
|
84 | 84 | |
85 | - public function setAddresses(array $addresses) |
|
86 | - { |
|
87 | - foreach ($addresses as $address) { |
|
88 | - $this->addAddress($address); |
|
89 | - } |
|
90 | - return $this; |
|
91 | - } |
|
85 | + public function setAddresses(array $addresses) |
|
86 | + { |
|
87 | + foreach ($addresses as $address) { |
|
88 | + $this->addAddress($address); |
|
89 | + } |
|
90 | + return $this; |
|
91 | + } |
|
92 | 92 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | class Route extends Common |
13 | 13 | { |
14 | - static public $apiUrl = '/api.v4/route.php'; |
|
14 | + static public $apiUrl = '/api.v4/route.php'; |
|
15 | 15 | static public $apiUrlAddress = '/api.v4/address.php'; |
16 | 16 | static public $apiUrlDuplicate='/actions/duplicate_route.php'; |
17 | 17 | static public $apiUrlDelete='/actions/delete_routes.php'; |
@@ -22,121 +22,121 @@ discard block |
||
22 | 22 | static public $apiUrlAsset='/api.v4/status.php'; |
23 | 23 | static public $apiUrlDeviceLocation='/api/track/get_device_location.php'; |
24 | 24 | //static public $apiUrlMove='/actions/route/move_route_destination.php'; |
25 | - public $route_id; |
|
25 | + public $route_id; |
|
26 | 26 | public $route_destination_id; |
27 | - public $optimization_problem_id; |
|
28 | - public $vehicle_alias; |
|
29 | - public $driver_alias; |
|
30 | - public $trip_distance; |
|
31 | - public $mpg; |
|
32 | - public $gas_price; |
|
33 | - public $route_duration_sec; |
|
34 | - public $parameters; |
|
35 | - public $addresses = array(); |
|
36 | - public $links = array(); |
|
37 | - public $directions = array(); |
|
38 | - public $path = array(); |
|
39 | - public $tracking_history = array(); |
|
27 | + public $optimization_problem_id; |
|
28 | + public $vehicle_alias; |
|
29 | + public $driver_alias; |
|
30 | + public $trip_distance; |
|
31 | + public $mpg; |
|
32 | + public $gas_price; |
|
33 | + public $route_duration_sec; |
|
34 | + public $parameters; |
|
35 | + public $addresses = array(); |
|
36 | + public $links = array(); |
|
37 | + public $directions = array(); |
|
38 | + public $path = array(); |
|
39 | + public $tracking_history = array(); |
|
40 | 40 | public $recipient_email; |
41 | 41 | public $httpheaders; |
42 | 42 | |
43 | 43 | public $dev_lat; |
44 | 44 | public $dev_lng; |
45 | 45 | |
46 | - public static function fromArray(array $params) |
|
47 | - { |
|
48 | - $route = new Route(); |
|
49 | - $route->route_id = Common::getValue($params, 'route_id'); |
|
50 | - $route->optimization_problem_id = Common::getValue($params, 'optimization_problem_id'); |
|
51 | - $route->vehicle_alias = Common::getValue($params, 'vehicle_alias'); |
|
52 | - $route->driver_alias = Common::getValue($params, 'driver_alias'); |
|
53 | - $route->trip_distance = Common::getValue($params, 'trip_distance'); |
|
54 | - $route->mpg = Common::getValue($params, 'mpg'); |
|
55 | - $route->gas_price = Common::getValue($params, 'gas_price'); |
|
56 | - $route->route_duration_sec = Common::getvalue($params, 'route_duration_sec'); |
|
57 | - |
|
58 | - // Make RouteParameters |
|
59 | - if (isset($params['parameters'])) { |
|
60 | - $route->parameters = RouteParameters::fromArray($params['parameters']); |
|
61 | - } |
|
62 | - |
|
63 | - if (isset($params['addresses'])) { |
|
64 | - $addresses = array(); |
|
65 | - foreach ($params['addresses'] as $address) { |
|
66 | - $addresses[] = Address::fromArray($address); |
|
67 | - } |
|
68 | - |
|
69 | - $route->addresses = $addresses; |
|
70 | - } |
|
71 | - |
|
72 | - $route->links = Common::getValue($params, 'links', array()); |
|
73 | - $route->directions = Common::getValue($params, 'directions', array()); |
|
74 | - $route->path = Common::getValue($params, 'path', array()); |
|
75 | - $route->tracking_history = Common::getValue($params, 'tracking_history', array()); |
|
76 | - |
|
77 | - return $route; |
|
78 | - } |
|
79 | - |
|
80 | - public static function getRoutes($routeId=null, $params=null) |
|
81 | - { |
|
82 | - $query = array( |
|
83 | - 'api_key' => Route4Me::getApiKey() |
|
84 | - ); |
|
85 | - |
|
86 | - if ($routeId) { |
|
87 | - $query['route_id'] = implode(',', (array) $routeId); |
|
88 | - } |
|
89 | - |
|
90 | - if ($params) { |
|
91 | - if (isset($params['directions'])) { |
|
92 | - $query['directions'] = $params['directions']; |
|
93 | - } |
|
94 | - |
|
95 | - if (isset($params['route_path_output'])) { |
|
96 | - $query['route_path_output'] = $params['route_path_output']; |
|
97 | - } |
|
98 | - |
|
99 | - if (isset($params['device_tracking_history'])) { |
|
100 | - $query['device_tracking_history'] = $params['device_tracking_history']; |
|
101 | - } |
|
46 | + public static function fromArray(array $params) |
|
47 | + { |
|
48 | + $route = new Route(); |
|
49 | + $route->route_id = Common::getValue($params, 'route_id'); |
|
50 | + $route->optimization_problem_id = Common::getValue($params, 'optimization_problem_id'); |
|
51 | + $route->vehicle_alias = Common::getValue($params, 'vehicle_alias'); |
|
52 | + $route->driver_alias = Common::getValue($params, 'driver_alias'); |
|
53 | + $route->trip_distance = Common::getValue($params, 'trip_distance'); |
|
54 | + $route->mpg = Common::getValue($params, 'mpg'); |
|
55 | + $route->gas_price = Common::getValue($params, 'gas_price'); |
|
56 | + $route->route_duration_sec = Common::getvalue($params, 'route_duration_sec'); |
|
57 | + |
|
58 | + // Make RouteParameters |
|
59 | + if (isset($params['parameters'])) { |
|
60 | + $route->parameters = RouteParameters::fromArray($params['parameters']); |
|
61 | + } |
|
62 | + |
|
63 | + if (isset($params['addresses'])) { |
|
64 | + $addresses = array(); |
|
65 | + foreach ($params['addresses'] as $address) { |
|
66 | + $addresses[] = Address::fromArray($address); |
|
67 | + } |
|
68 | + |
|
69 | + $route->addresses = $addresses; |
|
70 | + } |
|
71 | + |
|
72 | + $route->links = Common::getValue($params, 'links', array()); |
|
73 | + $route->directions = Common::getValue($params, 'directions', array()); |
|
74 | + $route->path = Common::getValue($params, 'path', array()); |
|
75 | + $route->tracking_history = Common::getValue($params, 'tracking_history', array()); |
|
76 | + |
|
77 | + return $route; |
|
78 | + } |
|
79 | + |
|
80 | + public static function getRoutes($routeId=null, $params=null) |
|
81 | + { |
|
82 | + $query = array( |
|
83 | + 'api_key' => Route4Me::getApiKey() |
|
84 | + ); |
|
85 | + |
|
86 | + if ($routeId) { |
|
87 | + $query['route_id'] = implode(',', (array) $routeId); |
|
88 | + } |
|
89 | + |
|
90 | + if ($params) { |
|
91 | + if (isset($params['directions'])) { |
|
92 | + $query['directions'] = $params['directions']; |
|
93 | + } |
|
94 | + |
|
95 | + if (isset($params['route_path_output'])) { |
|
96 | + $query['route_path_output'] = $params['route_path_output']; |
|
97 | + } |
|
98 | + |
|
99 | + if (isset($params['device_tracking_history'])) { |
|
100 | + $query['device_tracking_history'] = $params['device_tracking_history']; |
|
101 | + } |
|
102 | 102 | |
103 | 103 | if (isset($params['query'])) { |
104 | - $query['query'] = $params['query']; |
|
105 | - } |
|
106 | - |
|
107 | - $query['limit'] = isset($params['limit']) ? $params['limit'] : 30; |
|
108 | - $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
109 | - } |
|
104 | + $query['query'] = $params['query']; |
|
105 | + } |
|
110 | 106 | |
111 | - $json = Route4Me::makeRequst(array( |
|
112 | - 'url' => self::$apiUrl, |
|
113 | - 'method' => 'GET', |
|
114 | - 'query' => $query |
|
115 | - )); |
|
107 | + $query['limit'] = isset($params['limit']) ? $params['limit'] : 30; |
|
108 | + $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
109 | + } |
|
116 | 110 | |
117 | - if ($routeId) { |
|
118 | - return Route::fromArray($json); die(""); |
|
119 | - } else { |
|
120 | - $routes = array(); |
|
121 | - foreach($json as $route) { |
|
122 | - $routes[] = Route::fromArray($route); |
|
123 | - } |
|
124 | - return $routes; |
|
125 | - } |
|
126 | - } |
|
111 | + $json = Route4Me::makeRequst(array( |
|
112 | + 'url' => self::$apiUrl, |
|
113 | + 'method' => 'GET', |
|
114 | + 'query' => $query |
|
115 | + )); |
|
116 | + |
|
117 | + if ($routeId) { |
|
118 | + return Route::fromArray($json); die(""); |
|
119 | + } else { |
|
120 | + $routes = array(); |
|
121 | + foreach($json as $route) { |
|
122 | + $routes[] = Route::fromArray($route); |
|
123 | + } |
|
124 | + return $routes; |
|
125 | + } |
|
126 | + } |
|
127 | 127 | |
128 | 128 | public function getRoutePoints($routeId, $params) |
129 | 129 | { |
130 | 130 | $result = Route4Me::makeRequst(array( |
131 | - 'url' => self::$apiUrl, |
|
132 | - 'method' => 'GET', |
|
133 | - 'query' => array( |
|
134 | - 'api_key' => Route4Me::getApiKey(), |
|
135 | - 'route_id' => $routeId, |
|
136 | - 'route_path_output' => isset($params['route_path_output']) ? $params['route_path_output'] : null, |
|
137 | - 'directions' => isset($params['directions']) ? $params['directions'] : null, |
|
138 | - ) |
|
139 | - )); |
|
131 | + 'url' => self::$apiUrl, |
|
132 | + 'method' => 'GET', |
|
133 | + 'query' => array( |
|
134 | + 'api_key' => Route4Me::getApiKey(), |
|
135 | + 'route_id' => $routeId, |
|
136 | + 'route_path_output' => isset($params['route_path_output']) ? $params['route_path_output'] : null, |
|
137 | + 'directions' => isset($params['directions']) ? $params['directions'] : null, |
|
138 | + ) |
|
139 | + )); |
|
140 | 140 | |
141 | 141 | return $result; |
142 | 142 | } |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | public function duplicateRoute($route_id) |
145 | 145 | { |
146 | 146 | $result = Route4Me::makeRequst(array( |
147 | - 'url' => self::$apiUrlDuplicate, |
|
148 | - 'method' => 'GET', |
|
149 | - 'query' => array( |
|
150 | - 'api_key' => Route4Me::getApiKey(), |
|
151 | - 'route_id' => $route_id, |
|
152 | - 'to' => 'none', |
|
153 | - ) |
|
154 | - )); |
|
147 | + 'url' => self::$apiUrlDuplicate, |
|
148 | + 'method' => 'GET', |
|
149 | + 'query' => array( |
|
150 | + 'api_key' => Route4Me::getApiKey(), |
|
151 | + 'route_id' => $route_id, |
|
152 | + 'to' => 'none', |
|
153 | + ) |
|
154 | + )); |
|
155 | 155 | |
156 | 156 | return $result; |
157 | 157 | } |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | public function resequenceRoute($params) |
160 | 160 | { |
161 | 161 | $result = Route4Me::makeRequst(array( |
162 | - 'url' => self::$apiUrl, |
|
163 | - 'method' => 'PUT', |
|
164 | - 'query' => array( |
|
165 | - 'api_key' => Route4Me::getApiKey(), |
|
166 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
167 | - 'route_destination_id' => isset($params['route_destination_id']) ? $params['route_destination_id'] : null, |
|
168 | - ), |
|
169 | - 'body' => array( |
|
162 | + 'url' => self::$apiUrl, |
|
163 | + 'method' => 'PUT', |
|
164 | + 'query' => array( |
|
165 | + 'api_key' => Route4Me::getApiKey(), |
|
166 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
167 | + 'route_destination_id' => isset($params['route_destination_id']) ? $params['route_destination_id'] : null, |
|
168 | + ), |
|
169 | + 'body' => array( |
|
170 | 170 | 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
171 | 171 | ) |
172 | - )); |
|
172 | + )); |
|
173 | 173 | |
174 | 174 | return $result; |
175 | 175 | } |
@@ -177,15 +177,15 @@ discard block |
||
177 | 177 | public function resequenceAllAddresses($params) |
178 | 178 | { |
179 | 179 | $result = Route4Me::makeRequst(array( |
180 | - 'url' => self::$apiUrlReseq, |
|
181 | - 'method' => 'GET', |
|
182 | - 'query' => array( |
|
183 | - 'api_key' => Route4Me::getApiKey(), |
|
184 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
185 | - 'disable_optimization' => isset($params['disable_optimization']) ? $params['disable_optimization'] : null, |
|
186 | - 'optimize' => isset($params['optimize']) ? $params['optimize'] : null, |
|
187 | - ) |
|
188 | - )); |
|
180 | + 'url' => self::$apiUrlReseq, |
|
181 | + 'method' => 'GET', |
|
182 | + 'query' => array( |
|
183 | + 'api_key' => Route4Me::getApiKey(), |
|
184 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
185 | + 'disable_optimization' => isset($params['disable_optimization']) ? $params['disable_optimization'] : null, |
|
186 | + 'optimize' => isset($params['optimize']) ? $params['optimize'] : null, |
|
187 | + ) |
|
188 | + )); |
|
189 | 189 | |
190 | 190 | return $result; |
191 | 191 | |
@@ -194,16 +194,16 @@ discard block |
||
194 | 194 | public function mergeRoutes($params) |
195 | 195 | { |
196 | 196 | $result = Route4Me::makeRequst(array( |
197 | - 'url' => self::$apiUrlMerge, |
|
198 | - 'method' => 'POST', |
|
199 | - 'query' => array( |
|
200 | - 'api_key' => Route4Me::getApiKey(), |
|
201 | - ), |
|
202 | - 'body' => array( |
|
197 | + 'url' => self::$apiUrlMerge, |
|
198 | + 'method' => 'POST', |
|
199 | + 'query' => array( |
|
200 | + 'api_key' => Route4Me::getApiKey(), |
|
201 | + ), |
|
202 | + 'body' => array( |
|
203 | 203 | 'route_ids' => isset($params['route_ids']) ? $params['route_ids'] : null, |
204 | 204 | ), |
205 | 205 | 'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null, |
206 | - )); |
|
206 | + )); |
|
207 | 207 | |
208 | 208 | return $result; |
209 | 209 | } |
@@ -211,17 +211,17 @@ discard block |
||
211 | 211 | public function shareRoute($params) |
212 | 212 | { |
213 | 213 | $result = Route4Me::makeRequst(array( |
214 | - 'url' => self::$apiUrlShare, |
|
215 | - 'method' => 'POST', |
|
216 | - 'query' => array( |
|
217 | - 'api_key' => Route4Me::getApiKey(), |
|
218 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
219 | - ), |
|
220 | - 'body' => array( |
|
214 | + 'url' => self::$apiUrlShare, |
|
215 | + 'method' => 'POST', |
|
216 | + 'query' => array( |
|
217 | + 'api_key' => Route4Me::getApiKey(), |
|
218 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
219 | + ), |
|
220 | + 'body' => array( |
|
221 | 221 | 'recipient_email' => isset($params['recipient_email']) ? $params['recipient_email'] : null, |
222 | 222 | ), |
223 | 223 | 'Content-Type' => 'multipart/form-data' |
224 | - )); |
|
224 | + )); |
|
225 | 225 | |
226 | 226 | return $result; |
227 | 227 | } |
@@ -230,18 +230,18 @@ discard block |
||
230 | 230 | public function getRandomRouteId($offset,$limit) |
231 | 231 | { |
232 | 232 | $query['limit'] = isset($params['limit']) ? $params['limit'] : 30; |
233 | - $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
233 | + $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
234 | 234 | |
235 | 235 | $json = Route4Me::makeRequst(array( |
236 | - 'url' => self::$apiUrl, |
|
237 | - 'method' => 'GET', |
|
238 | - 'query' => $query |
|
239 | - )); |
|
236 | + 'url' => self::$apiUrl, |
|
237 | + 'method' => 'GET', |
|
238 | + 'query' => $query |
|
239 | + )); |
|
240 | 240 | |
241 | 241 | $routes = array(); |
242 | - foreach($json as $route) { |
|
243 | - $routes[] = Route::fromArray($route); |
|
244 | - } |
|
242 | + foreach($json as $route) { |
|
243 | + $routes[] = Route::fromArray($route); |
|
244 | + } |
|
245 | 245 | |
246 | 246 | $num=rand(0,sizeof($routes)-1); |
247 | 247 | $rRoute=(array)$routes[$num]; |
@@ -253,71 +253,71 @@ discard block |
||
253 | 253 | else return null; |
254 | 254 | } |
255 | 255 | |
256 | - public function update() |
|
257 | - { |
|
258 | - $route = Route4Me::makeRequst(array( |
|
259 | - 'url' => self::$apiUrl, |
|
260 | - 'method' => 'PUT', |
|
261 | - 'query' => array( |
|
262 | - 'route_id' => isset($this->route_id) ? $this->route_id : null, |
|
263 | - 'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null, |
|
264 | - ), |
|
265 | - 'body' => array ( |
|
266 | - 'parameters' => $this->parameters, |
|
267 | - ), |
|
268 | - 'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null, |
|
269 | - )); |
|
256 | + public function update() |
|
257 | + { |
|
258 | + $route = Route4Me::makeRequst(array( |
|
259 | + 'url' => self::$apiUrl, |
|
260 | + 'method' => 'PUT', |
|
261 | + 'query' => array( |
|
262 | + 'route_id' => isset($this->route_id) ? $this->route_id : null, |
|
263 | + 'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null, |
|
264 | + ), |
|
265 | + 'body' => array ( |
|
266 | + 'parameters' => $this->parameters, |
|
267 | + ), |
|
268 | + 'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null, |
|
269 | + )); |
|
270 | 270 | |
271 | - return Route::fromArray($route); |
|
272 | - } |
|
271 | + return Route::fromArray($route); |
|
272 | + } |
|
273 | 273 | |
274 | 274 | public function updateAddress() |
275 | - { |
|
276 | - $result = Route4Me::makeRequst(array( |
|
277 | - 'url' => self::$apiUrlAddress, |
|
278 | - 'method' => 'PUT', |
|
279 | - 'query' => array( |
|
280 | - 'route_id' => isset($this->route_id) ? $this->route_id : null, |
|
281 | - 'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null, |
|
282 | - ), |
|
283 | - 'body' => get_object_vars($this->parameters), |
|
284 | - 'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null, |
|
285 | - )); |
|
275 | + { |
|
276 | + $result = Route4Me::makeRequst(array( |
|
277 | + 'url' => self::$apiUrlAddress, |
|
278 | + 'method' => 'PUT', |
|
279 | + 'query' => array( |
|
280 | + 'route_id' => isset($this->route_id) ? $this->route_id : null, |
|
281 | + 'route_destination_id' => isset($this->route_destination_id) ? $this->route_destination_id : null, |
|
282 | + ), |
|
283 | + 'body' => get_object_vars($this->parameters), |
|
284 | + 'HTTPHEADER' => isset($this->httpheaders) ? $this->httpheaders : null, |
|
285 | + )); |
|
286 | 286 | |
287 | - return $result; |
|
288 | - } |
|
287 | + return $result; |
|
288 | + } |
|
289 | 289 | |
290 | - public function addAddresses(array $params) |
|
291 | - { |
|
292 | - $route = Route4Me::makeRequst(array( |
|
293 | - 'url' => self::$apiUrl, |
|
294 | - 'method' => 'PUT', |
|
295 | - 'query' => array( |
|
296 | - 'api_key' => Route4Me::getApiKey(), |
|
297 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
298 | - 'addresses' => isset($params['addresses']) ? $params['addresses'] : null |
|
299 | - ) |
|
300 | - )); |
|
290 | + public function addAddresses(array $params) |
|
291 | + { |
|
292 | + $route = Route4Me::makeRequst(array( |
|
293 | + 'url' => self::$apiUrl, |
|
294 | + 'method' => 'PUT', |
|
295 | + 'query' => array( |
|
296 | + 'api_key' => Route4Me::getApiKey(), |
|
297 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
298 | + 'addresses' => isset($params['addresses']) ? $params['addresses'] : null |
|
299 | + ) |
|
300 | + )); |
|
301 | 301 | |
302 | - return Route::fromArray($route); |
|
303 | - } |
|
302 | + return Route::fromArray($route); |
|
303 | + } |
|
304 | 304 | |
305 | 305 | public function insertAddressOptimalPosition(array $params) |
306 | 306 | { |
307 | 307 | $route = Route4Me::makeRequst(array( |
308 | - 'url' => self::$apiUrl, |
|
309 | - 'method' => 'PUT', |
|
310 | - 'query' => array( |
|
311 | - 'api_key' => Route4Me::getApiKey(), |
|
312 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
313 | - ), |
|
314 | - 'body' => array( |
|
308 | + 'url' => self::$apiUrl, |
|
309 | + 'method' => 'PUT', |
|
310 | + 'query' => array( |
|
311 | + 'api_key' => Route4Me::getApiKey(), |
|
312 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
313 | + ), |
|
314 | + 'body' => array( |
|
315 | 315 | 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
316 | 316 | 'optimal_position' => isset($params['optimal_position']) ? $params['optimal_position'] : null, |
317 | 317 | ) |
318 | - )); |
|
318 | + )); |
|
319 | 319 | |
320 | - return Route::fromArray($route); |
|
320 | + return Route::fromArray($route); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | public function addNoteFile($params) |
@@ -326,18 +326,18 @@ discard block |
||
326 | 326 | $rpath = realpath($fname); |
327 | 327 | //echo $rpath;die(""); |
328 | 328 | $result= Route4Me::makeRequst(array( |
329 | - 'url' => self::$apiUrlNoteFile, |
|
330 | - 'method' => 'POST', |
|
331 | - 'query' => array( |
|
332 | - 'api_key' => Route4Me::getApiKey(), |
|
333 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
334 | - 'address_id' => isset($params['address_id']) ? $params['address_id'] : null, |
|
335 | - 'dev_lat' => isset($params['dev_lat']) ? $params['dev_lat'] : null, |
|
336 | - 'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null, |
|
337 | - 'device_type' => isset($params['device_type']) ? $params['device_type'] : null, |
|
338 | - 'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null, |
|
339 | - ), |
|
340 | - 'body' => array( |
|
329 | + 'url' => self::$apiUrlNoteFile, |
|
330 | + 'method' => 'POST', |
|
331 | + 'query' => array( |
|
332 | + 'api_key' => Route4Me::getApiKey(), |
|
333 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
334 | + 'address_id' => isset($params['address_id']) ? $params['address_id'] : null, |
|
335 | + 'dev_lat' => isset($params['dev_lat']) ? $params['dev_lat'] : null, |
|
336 | + 'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null, |
|
337 | + 'device_type' => isset($params['device_type']) ? $params['device_type'] : null, |
|
338 | + 'dev_lng' => isset($params['dev_lng']) ? $params['dev_lng'] : null, |
|
339 | + ), |
|
340 | + 'body' => array( |
|
341 | 341 | 'strUpdateType' => isset($params['strUpdateType']) ? $params['strUpdateType'] : null, |
342 | 342 | 'strFilename' => isset($params['strFilename']) ? $params['strFilename'] : null, |
343 | 343 | 'strNoteContents' => isset($params['strNoteContents']) ? $params['strNoteContents'] : null, |
@@ -347,18 +347,18 @@ discard block |
||
347 | 347 | 'HTTPHEADER' => array( |
348 | 348 | 'Content-Type: application/x-www-form-urlencoded' |
349 | 349 | ) |
350 | - )); |
|
350 | + )); |
|
351 | 351 | |
352 | - return $result; |
|
352 | + return $result; |
|
353 | 353 | } |
354 | 354 | |
355 | - public function delete($route_id) |
|
356 | - { |
|
357 | - $result = Route4Me::makeRequst(array( |
|
358 | - 'url' => self::$apiUrl, |
|
359 | - 'method' => 'DELETE', |
|
360 | - 'query' => array( 'route_id' => $route_id ) |
|
361 | - )); |
|
355 | + public function delete($route_id) |
|
356 | + { |
|
357 | + $result = Route4Me::makeRequst(array( |
|
358 | + 'url' => self::$apiUrl, |
|
359 | + 'method' => 'DELETE', |
|
360 | + 'query' => array( 'route_id' => $route_id ) |
|
361 | + )); |
|
362 | 362 | |
363 | 363 | // The code below doesn't work, altough this method is described as workable in REST API |
364 | 364 | /* |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | ) |
372 | 372 | )); |
373 | 373 | */ |
374 | - return $result; |
|
375 | - } |
|
374 | + return $result; |
|
375 | + } |
|
376 | 376 | |
377 | 377 | public function GetAddressesFromRoute($route_id) |
378 | 378 | { |
@@ -396,63 +396,63 @@ discard block |
||
396 | 396 | } else { return null;} |
397 | 397 | } |
398 | 398 | |
399 | - public function getRouteId() |
|
400 | - { |
|
401 | - return $this->route_id; |
|
402 | - } |
|
399 | + public function getRouteId() |
|
400 | + { |
|
401 | + return $this->route_id; |
|
402 | + } |
|
403 | 403 | |
404 | - public function getOptimizationId() |
|
405 | - { |
|
406 | - return $this->optimization_problem_id; |
|
407 | - } |
|
404 | + public function getOptimizationId() |
|
405 | + { |
|
406 | + return $this->optimization_problem_id; |
|
407 | + } |
|
408 | 408 | |
409 | 409 | public function GetLastLocation(array $params) |
410 | 410 | { |
411 | 411 | $route = Route4Me::makeRequst(array( |
412 | - 'url' => self::$apiUrl, |
|
413 | - 'method' => 'GET', |
|
414 | - 'query' => array( |
|
415 | - 'api_key' => Route4Me::getApiKey(), |
|
416 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
417 | - 'device_tracking_history' => isset($params['device_tracking_history']) ? $params['device_tracking_history'] : null |
|
418 | - ) |
|
419 | - )); |
|
412 | + 'url' => self::$apiUrl, |
|
413 | + 'method' => 'GET', |
|
414 | + 'query' => array( |
|
415 | + 'api_key' => Route4Me::getApiKey(), |
|
416 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
417 | + 'device_tracking_history' => isset($params['device_tracking_history']) ? $params['device_tracking_history'] : null |
|
418 | + ) |
|
419 | + )); |
|
420 | 420 | |
421 | - return Route::fromArray($route); |
|
421 | + return Route::fromArray($route); |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
425 | 425 | public function GetTrackingHistoryFromTimeRange(array $params) |
426 | 426 | { |
427 | 427 | $route = Route4Me::makeRequst(array( |
428 | - 'url' => self::$apiUrlDeviceLocation, |
|
429 | - 'method' => 'GET', |
|
430 | - 'query' => array( |
|
431 | - 'api_key' => Route4Me::getApiKey(), |
|
432 | - 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
433 | - 'format' => isset($params['format']) ? $params['format'] : null, |
|
434 | - 'time_period' => isset($params['time_period']) ? $params['time_period'] : null, |
|
435 | - 'start_date' => isset($params['start_date']) ? $params['start_date'] : null, |
|
436 | - 'end_date' => isset($params['end_date']) ? $params['end_date'] : null |
|
437 | - ) |
|
438 | - )); |
|
439 | - |
|
440 | - return $route; |
|
428 | + 'url' => self::$apiUrlDeviceLocation, |
|
429 | + 'method' => 'GET', |
|
430 | + 'query' => array( |
|
431 | + 'api_key' => Route4Me::getApiKey(), |
|
432 | + 'route_id' => isset($params['route_id']) ? $params['route_id'] : null, |
|
433 | + 'format' => isset($params['format']) ? $params['format'] : null, |
|
434 | + 'time_period' => isset($params['time_period']) ? $params['time_period'] : null, |
|
435 | + 'start_date' => isset($params['start_date']) ? $params['start_date'] : null, |
|
436 | + 'end_date' => isset($params['end_date']) ? $params['end_date'] : null |
|
437 | + ) |
|
438 | + )); |
|
439 | + |
|
440 | + return $route; |
|
441 | 441 | |
442 | 442 | } |
443 | 443 | |
444 | 444 | public function GetAssetTracking(array $params) |
445 | 445 | { |
446 | 446 | $route = Route4Me::makeRequst(array( |
447 | - 'url' => self::$apiUrlAsset, |
|
448 | - 'method' => 'GET', |
|
449 | - 'query' => array( |
|
450 | - 'api_key' => Route4Me::getApiKey(), |
|
451 | - 'tracking' => isset($params['tracking']) ? $params['tracking'] : null |
|
452 | - ) |
|
453 | - )); |
|
454 | - |
|
455 | - return $route; |
|
447 | + 'url' => self::$apiUrlAsset, |
|
448 | + 'method' => 'GET', |
|
449 | + 'query' => array( |
|
450 | + 'api_key' => Route4Me::getApiKey(), |
|
451 | + 'tracking' => isset($params['tracking']) ? $params['tracking'] : null |
|
452 | + ) |
|
453 | + )); |
|
454 | + |
|
455 | + return $route; |
|
456 | 456 | |
457 | 457 | } |
458 | 458 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | //and finally send curl request |
111 | 111 | $result = curl_exec_redir($this->ch); |
112 | 112 | if(curl_errno($this->ch)) |
113 | - { |
|
113 | + { |
|
114 | 114 | if($this->debug) |
115 | 115 | { |
116 | 116 | echo "Error Occured in Curl\n"; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | else |
123 | - { |
|
123 | + { |
|
124 | 124 | return $result; |
125 | 125 | } |
126 | 126 | } |
@@ -372,53 +372,53 @@ discard block |
||
372 | 372 | */ |
373 | 373 | function curl_exec_redir($ch) |
374 | 374 | { |
375 | - static $curl_loops = 0; |
|
376 | - static $curl_max_loops = 20; |
|
377 | - if ($curl_loops++ >= $curl_max_loops) |
|
378 | - { |
|
379 | - $curl_loops = 0; |
|
380 | - return FALSE; |
|
381 | - } |
|
382 | - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); |
|
383 | - curl_setopt($ch, CURLOPT_HEADER, true); |
|
384 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
385 | - curl_setopt($ch, CURLOPT_VERBOSE, false); |
|
386 | - $data = curl_exec($ch); |
|
387 | - $data = str_replace("\r", "\n", str_replace("\r\n", "\n", $data)); |
|
388 | - list($header, $data) = explode("\n\n", $data, 2); |
|
389 | - $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
375 | + static $curl_loops = 0; |
|
376 | + static $curl_max_loops = 20; |
|
377 | + if ($curl_loops++ >= $curl_max_loops) |
|
378 | + { |
|
379 | + $curl_loops = 0; |
|
380 | + return FALSE; |
|
381 | + } |
|
382 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); |
|
383 | + curl_setopt($ch, CURLOPT_HEADER, true); |
|
384 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
385 | + curl_setopt($ch, CURLOPT_VERBOSE, false); |
|
386 | + $data = curl_exec($ch); |
|
387 | + $data = str_replace("\r", "\n", str_replace("\r\n", "\n", $data)); |
|
388 | + list($header, $data) = explode("\n\n", $data, 2); |
|
389 | + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
390 | 390 | |
391 | - //echo "*** Got HTTP code: $http_code ***\n"; |
|
392 | - //echo "** Got headers: \n$header\n\n"; |
|
391 | + //echo "*** Got HTTP code: $http_code ***\n"; |
|
392 | + //echo "** Got headers: \n$header\n\n"; |
|
393 | 393 | |
394 | - if ( $http_code == 301 || $http_code == 302 ) |
|
395 | - { |
|
396 | - // If we're redirected, we should revert to GET |
|
394 | + if ( $http_code == 301 || $http_code == 302 ) |
|
395 | + { |
|
396 | + // If we're redirected, we should revert to GET |
|
397 | 397 | curl_setopt($ch, CURLOPT_HTTPGET,true); |
398 | 398 | |
399 | - $matches = array(); |
|
400 | - preg_match('/Location:\s*(.*?)(\n|$)/i', $header, $matches); |
|
401 | - $url = @parse_url(trim($matches[1])); |
|
402 | - if (!$url) |
|
403 | - { |
|
404 | - //couldn't process the url to redirect to |
|
405 | - $curl_loops = 0; |
|
406 | - return $data; |
|
407 | - } |
|
408 | - $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); |
|
409 | - if (empty($url['scheme'])) |
|
410 | - $url['scheme'] = $last_url['scheme']; |
|
411 | - if (empty($url['host'])) |
|
412 | - $url['host'] = $last_url['host']; |
|
413 | - if (empty($url['path'])) |
|
414 | - $url['path'] = $last_url['path']; |
|
415 | - $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . (!empty($url['query'])?'?'.$url['query']:''); |
|
416 | - //echo "Being redirected to $new_url\n"; |
|
417 | - curl_setopt($ch, CURLOPT_URL, $new_url); |
|
418 | - return curl_exec_redir($ch); |
|
419 | - } else { |
|
420 | - $curl_loops=0; |
|
421 | - return $data; |
|
422 | - } |
|
399 | + $matches = array(); |
|
400 | + preg_match('/Location:\s*(.*?)(\n|$)/i', $header, $matches); |
|
401 | + $url = @parse_url(trim($matches[1])); |
|
402 | + if (!$url) |
|
403 | + { |
|
404 | + //couldn't process the url to redirect to |
|
405 | + $curl_loops = 0; |
|
406 | + return $data; |
|
407 | + } |
|
408 | + $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); |
|
409 | + if (empty($url['scheme'])) |
|
410 | + $url['scheme'] = $last_url['scheme']; |
|
411 | + if (empty($url['host'])) |
|
412 | + $url['host'] = $last_url['host']; |
|
413 | + if (empty($url['path'])) |
|
414 | + $url['path'] = $last_url['path']; |
|
415 | + $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . (!empty($url['query'])?'?'.$url['query']:''); |
|
416 | + //echo "Being redirected to $new_url\n"; |
|
417 | + curl_setopt($ch, CURLOPT_URL, $new_url); |
|
418 | + return curl_exec_redir($ch); |
|
419 | + } else { |
|
420 | + $curl_loops=0; |
|
421 | + return $data; |
|
422 | + } |
|
423 | 423 | } |
424 | 424 | ?> |
@@ -37,45 +37,45 @@ discard block |
||
37 | 37 | |
38 | 38 | public static function fromArray(array $params) { |
39 | 39 | $order= new Order(); |
40 | - foreach($params as $key => $value) { |
|
41 | - if (property_exists($order, $key)) { |
|
42 | - $order->{$key} = $value; |
|
43 | - } |
|
40 | + foreach($params as $key => $value) { |
|
41 | + if (property_exists($order, $key)) { |
|
42 | + $order->{$key} = $value; |
|
43 | + } |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | return $order; |
47 | 47 | } |
48 | 48 | |
49 | 49 | public static function addOrder($params) |
50 | - { |
|
51 | - $response = Route4Me::makeRequst(array( |
|
52 | - 'url' => self::$apiUrl, |
|
53 | - 'method' => 'POST', |
|
54 | - 'body' => array( |
|
50 | + { |
|
51 | + $response = Route4Me::makeRequst(array( |
|
52 | + 'url' => self::$apiUrl, |
|
53 | + 'method' => 'POST', |
|
54 | + 'body' => array( |
|
55 | 55 | 'address_1' => isset($params->address_1) ? $params->address_1: null, |
56 | - 'cached_lat' => isset($params->cached_lat) ? $params->cached_lat : null, |
|
57 | - 'cached_lng' => isset($params->cached_lng) ? $params->cached_lng : null, |
|
58 | - 'address_alias' => isset($params->address_alias) ? $params->address_alias : null, |
|
59 | - 'address_city' => isset($params->address_1) ? $params->address_city: null, |
|
60 | - 'EXT_FIELD_first_name' => isset($params->EXT_FIELD_first_name) ? $params->EXT_FIELD_first_name: null, |
|
61 | - 'EXT_FIELD_last_name' => isset($params->EXT_FIELD_last_name) ? $params->EXT_FIELD_last_name: null, |
|
62 | - 'EXT_FIELD_email' => isset($params->EXT_FIELD_email) ? $params->EXT_FIELD_email: null, |
|
63 | - 'EXT_FIELD_phone' => isset($params->EXT_FIELD_phone) ? $params->EXT_FIELD_phone: null, |
|
64 | - 'EXT_FIELD_custom_data' => isset($params->EXT_FIELD_custom_data) ? $params->EXT_FIELD_custom_data: null, |
|
56 | + 'cached_lat' => isset($params->cached_lat) ? $params->cached_lat : null, |
|
57 | + 'cached_lng' => isset($params->cached_lng) ? $params->cached_lng : null, |
|
58 | + 'address_alias' => isset($params->address_alias) ? $params->address_alias : null, |
|
59 | + 'address_city' => isset($params->address_1) ? $params->address_city: null, |
|
60 | + 'EXT_FIELD_first_name' => isset($params->EXT_FIELD_first_name) ? $params->EXT_FIELD_first_name: null, |
|
61 | + 'EXT_FIELD_last_name' => isset($params->EXT_FIELD_last_name) ? $params->EXT_FIELD_last_name: null, |
|
62 | + 'EXT_FIELD_email' => isset($params->EXT_FIELD_email) ? $params->EXT_FIELD_email: null, |
|
63 | + 'EXT_FIELD_phone' => isset($params->EXT_FIELD_phone) ? $params->EXT_FIELD_phone: null, |
|
64 | + 'EXT_FIELD_custom_data' => isset($params->EXT_FIELD_custom_data) ? $params->EXT_FIELD_custom_data: null, |
|
65 | 65 | ) |
66 | - )); |
|
66 | + )); |
|
67 | 67 | |
68 | 68 | return $response; |
69 | 69 | } |
70 | 70 | |
71 | 71 | public static function addOrder2Route($params,$body) |
72 | - { |
|
73 | - $response = Route4Me::makeRequst(array( |
|
74 | - 'url' => self::$apiUrlRoute, |
|
75 | - 'method' => 'PUT', |
|
76 | - 'query' => array( |
|
72 | + { |
|
73 | + $response = Route4Me::makeRequst(array( |
|
74 | + 'url' => self::$apiUrlRoute, |
|
75 | + 'method' => 'PUT', |
|
76 | + 'query' => array( |
|
77 | 77 | 'route_id' => isset($params->route_id) ? $params->route_id: null, |
78 | - 'redirect' => isset($params->redirect) ? $params->redirect : null |
|
78 | + 'redirect' => isset($params->redirect) ? $params->redirect : null |
|
79 | 79 | ), |
80 | 80 | 'body' => (array)$body |
81 | 81 | )); |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | public static function addOrder2Destination($params,$body) |
87 | - { |
|
88 | - $response = Route4Me::makeRequst(array( |
|
89 | - 'url' => self::$apiUrlOpt, |
|
90 | - 'method' => 'PUT', |
|
91 | - 'query' => array( |
|
87 | + { |
|
88 | + $response = Route4Me::makeRequst(array( |
|
89 | + 'url' => self::$apiUrlOpt, |
|
90 | + 'method' => 'PUT', |
|
91 | + 'query' => array( |
|
92 | 92 | 'optimization_problem_id' => isset($params->optimization_problem_id) ? $params->optimization_problem_id: null, |
93 | - 'redirect' => isset($params->redirect) ? $params->redirect : null |
|
93 | + 'redirect' => isset($params->redirect) ? $params->redirect : null |
|
94 | 94 | ), |
95 | 95 | 'body' => (array)$body |
96 | 96 | )); |
@@ -99,58 +99,58 @@ discard block |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | public static function getOrder($params) |
102 | - { |
|
103 | - $response = Route4Me::makeRequst(array( |
|
104 | - 'url' => self::$apiUrl, |
|
105 | - 'method' => 'GET', |
|
106 | - 'query' => array( |
|
102 | + { |
|
103 | + $response = Route4Me::makeRequst(array( |
|
104 | + 'url' => self::$apiUrl, |
|
105 | + 'method' => 'GET', |
|
106 | + 'query' => array( |
|
107 | 107 | 'order_id' => isset($params->order_id) ? $params->order_id: null, |
108 | 108 | ) |
109 | - )); |
|
109 | + )); |
|
110 | 110 | |
111 | 111 | return $response; |
112 | 112 | } |
113 | 113 | |
114 | 114 | public static function getOrders() |
115 | - { |
|
116 | - $response = Route4Me::makeRequst(array( |
|
117 | - 'url' => self::$apiUrl, |
|
118 | - 'method' => 'GET' |
|
119 | - )); |
|
115 | + { |
|
116 | + $response = Route4Me::makeRequst(array( |
|
117 | + 'url' => self::$apiUrl, |
|
118 | + 'method' => 'GET' |
|
119 | + )); |
|
120 | 120 | |
121 | 121 | return $response; |
122 | 122 | } |
123 | 123 | |
124 | 124 | public static function removeOrder($params) |
125 | - { |
|
126 | - $response = Route4Me::makeRequst(array( |
|
127 | - 'url' => self::$apiUrl, |
|
128 | - 'method' => 'DELETE', |
|
129 | - 'body' => array( |
|
125 | + { |
|
126 | + $response = Route4Me::makeRequst(array( |
|
127 | + 'url' => self::$apiUrl, |
|
128 | + 'method' => 'DELETE', |
|
129 | + 'body' => array( |
|
130 | 130 | 'order_ids' => isset($params->order_ids) ? $params->order_ids: null |
131 | 131 | ) |
132 | - )); |
|
132 | + )); |
|
133 | 133 | |
134 | 134 | return $response; |
135 | 135 | } |
136 | 136 | |
137 | 137 | public static function updateOrder($body) |
138 | - { |
|
139 | - $response = Route4Me::makeRequst(array( |
|
140 | - 'url' => self::$apiUrl, |
|
141 | - 'method' => 'PUT', |
|
142 | - 'body' => (array)$body |
|
143 | - )); |
|
138 | + { |
|
139 | + $response = Route4Me::makeRequst(array( |
|
140 | + 'url' => self::$apiUrl, |
|
141 | + 'method' => 'PUT', |
|
142 | + 'body' => (array)$body |
|
143 | + )); |
|
144 | 144 | |
145 | 145 | return $response; |
146 | 146 | } |
147 | 147 | |
148 | 148 | public static function searchOrder($params) |
149 | - { |
|
150 | - $response = Route4Me::makeRequst(array( |
|
151 | - 'url' => self::$apiUrl, |
|
152 | - 'method' => 'GET', |
|
153 | - 'query' => array( |
|
149 | + { |
|
150 | + $response = Route4Me::makeRequst(array( |
|
151 | + 'url' => self::$apiUrl, |
|
152 | + 'method' => 'GET', |
|
153 | + 'query' => array( |
|
154 | 154 | 'day_added_YYMMDD' => isset($params->day_added_YYMMDD) ? $params->day_added_YYMMDD: null, |
155 | 155 | 'scheduled_for_YYMMDD' => isset($params->scheduled_for_YYMMDD) ? $params->scheduled_for_YYMMDD: null, |
156 | 156 | 'fields' => isset($params->fields) ? $params->fields: null, |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | 'limit' => isset($params->limit) ? $params->limit: null, |
159 | 159 | 'query' => isset($params->query) ? $params->query: null, |
160 | 160 | ) |
161 | - )); |
|
161 | + )); |
|
162 | 162 | |
163 | 163 | return $response; |
164 | 164 | } |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | |
24 | 24 | public static function fromArray(array $params) { |
25 | 25 | $geocoding = new Geocoding(); |
26 | - foreach($params as $key => $value) { |
|
27 | - if (property_exists($geocoding, $key)) { |
|
28 | - $geocoding->{$key} = $value; |
|
29 | - } |
|
26 | + foreach($params as $key => $value) { |
|
27 | + if (property_exists($geocoding, $key)) { |
|
28 | + $geocoding->{$key} = $value; |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | return $geocoding; |
32 | 32 | } |
@@ -35,15 +35,15 @@ discard block |
||
35 | 35 | { |
36 | 36 | //Route4Me::simplePrint($params); |
37 | 37 | $query = array( |
38 | - 'format' => isset($params['format']) ? $params['format']: null, |
|
39 | - 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
|
40 | - ); |
|
38 | + 'format' => isset($params['format']) ? $params['format']: null, |
|
39 | + 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
|
40 | + ); |
|
41 | 41 | //var_dump($query); |
42 | 42 | $fgcoding = Route4Me::makeRequst(array( |
43 | - 'url' => self::$apiUrl, |
|
44 | - 'method' => 'POST', |
|
45 | - 'query' => $query |
|
46 | - )); |
|
43 | + 'url' => self::$apiUrl, |
|
44 | + 'method' => 'POST', |
|
45 | + 'query' => $query |
|
46 | + )); |
|
47 | 47 | |
48 | 48 | return $fgcoding; |
49 | 49 | } |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | $query = array(); |
65 | 65 | |
66 | 66 | $response = Route4Me::makeUrlRequst($url_query, array( |
67 | - 'method' => 'GET', |
|
68 | - 'query' => $query |
|
69 | - )); |
|
67 | + 'method' => 'GET', |
|
68 | + 'query' => $query |
|
69 | + )); |
|
70 | 70 | |
71 | 71 | return $response; |
72 | 72 | } |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | $query = array(); |
88 | 88 | |
89 | 89 | $response = Route4Me::makeUrlRequst($url_query, array( |
90 | - 'method' => 'GET', |
|
91 | - 'query' => $query |
|
92 | - )); |
|
90 | + 'method' => 'GET', |
|
91 | + 'query' => $query |
|
92 | + )); |
|
93 | 93 | |
94 | 94 | return $response; |
95 | 95 | } |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | $query = array(); |
114 | 114 | |
115 | 115 | $response = Route4Me::makeUrlRequst($url_query, array( |
116 | - 'method' => 'GET', |
|
117 | - 'query' => $query |
|
118 | - )); |
|
116 | + 'method' => 'GET', |
|
117 | + 'query' => $query |
|
118 | + )); |
|
119 | 119 | |
120 | 120 | return $response; |
121 | 121 | } |