@@ -13,14 +13,14 @@ |
||
13 | 13 | $territory = new Territory(); |
14 | 14 | $territory->type = TerritoryTypes::CIRCLE; |
15 | 15 | $territory->data = array ( |
16 | - "37.569752822786455,-77.47833251953125", |
|
17 | - "5000" |
|
16 | + "37.569752822786455,-77.47833251953125", |
|
17 | + "5000" |
|
18 | 18 | ); |
19 | 19 | |
20 | 20 | $TerritoryParameters= Territory::fromArray(array( |
21 | - "territory_name" => "Test Territory ".strval(rand(10000,99999)), |
|
22 | - "territory_color" => "ff7700", |
|
23 | - "territory" => $territory |
|
21 | + "territory_name" => "Test Territory ".strval(rand(10000,99999)), |
|
22 | + "territory_color" => "ff7700", |
|
23 | + "territory" => $territory |
|
24 | 24 | )); |
25 | 25 | |
26 | 26 | $territory = new Territory(); |
@@ -26,23 +26,23 @@ discard block |
||
26 | 26 | |
27 | 27 | $addresses = array(); |
28 | 28 | foreach($json as $address) { |
29 | - $addresses[] = Address::fromArray($address); |
|
29 | + $addresses[] = Address::fromArray($address); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | $parameters = RouteParameters::fromArray(array( |
33 | - "algorithm_type" => Algorithmtype::CVRP_TW_SD, |
|
34 | - "route_name" => "Multiple Depot, Multiple Driver, Time Window", |
|
35 | - "route_date" => time() + 24*60*60, |
|
36 | - "route_time" => 60 * 60 * 7, |
|
37 | - "rt" => TRUE, |
|
38 | - "distance_unit" => DistanceUnit::MILES, |
|
39 | - "device_type" => DeviceType::WEB, |
|
40 | - "optimize" => OptimizationType::TIME, |
|
41 | - "metric" => Metric::GEODESIC, |
|
42 | - "route_max_duration" => 86400 * 3, |
|
43 | - "travel_mode" => TravelMode::DRIVING, |
|
44 | - "vehicle_capacity" => 99, |
|
45 | - "vehicle_max_distance_mi" => 99999 |
|
33 | + "algorithm_type" => Algorithmtype::CVRP_TW_SD, |
|
34 | + "route_name" => "Multiple Depot, Multiple Driver, Time Window", |
|
35 | + "route_date" => time() + 24*60*60, |
|
36 | + "route_time" => 60 * 60 * 7, |
|
37 | + "rt" => TRUE, |
|
38 | + "distance_unit" => DistanceUnit::MILES, |
|
39 | + "device_type" => DeviceType::WEB, |
|
40 | + "optimize" => OptimizationType::TIME, |
|
41 | + "metric" => Metric::GEODESIC, |
|
42 | + "route_max_duration" => 86400 * 3, |
|
43 | + "travel_mode" => TravelMode::DRIVING, |
|
44 | + "vehicle_capacity" => 99, |
|
45 | + "vehicle_max_distance_mi" => 99999 |
|
46 | 46 | )); |
47 | 47 | |
48 | 48 | $optimizationParams = new OptimizationProblemParams; |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | $problem = OptimizationProblem::optimize($optimizationParams); |
53 | 53 | |
54 | 54 | foreach ((array)$problem as $key => $value) { |
55 | - if (is_string($value)) { |
|
56 | - echo $key." --> ".$value."<br>"; |
|
57 | - } else { |
|
58 | - echo "************ $key ************* <br>"; |
|
59 | - Route4Me::simplePrint((array)$value, true); |
|
60 | - echo "******************************* <br>"; |
|
61 | - } |
|
55 | + if (is_string($value)) { |
|
56 | + echo $key." --> ".$value."<br>"; |
|
57 | + } else { |
|
58 | + echo "************ $key ************* <br>"; |
|
59 | + Route4Me::simplePrint((array)$value, true); |
|
60 | + echo "******************************* <br>"; |
|
61 | + } |
|
62 | 62 | } |
63 | 63 |
@@ -8,18 +8,18 @@ |
||
8 | 8 | |
9 | 9 | class Track extends Common |
10 | 10 | { |
11 | - public static function set(TrackSetParams $param) |
|
12 | - { |
|
13 | - $query = array_merge($param->toArray(), array( |
|
14 | - 'api_key' => Route4Me::getApiKey() |
|
15 | - )); |
|
11 | + public static function set(TrackSetParams $param) |
|
12 | + { |
|
13 | + $query = array_merge($param->toArray(), array( |
|
14 | + 'api_key' => Route4Me::getApiKey() |
|
15 | + )); |
|
16 | 16 | |
17 | - $json = Route4Me::makeRequst(array( |
|
18 | - 'url' => Endpoint::TRACK_SET, |
|
19 | - 'method' => 'GET', |
|
20 | - 'query' => $query |
|
21 | - )); |
|
17 | + $json = Route4Me::makeRequst(array( |
|
18 | + 'url' => Endpoint::TRACK_SET, |
|
19 | + 'method' => 'GET', |
|
20 | + 'query' => $query |
|
21 | + )); |
|
22 | 22 | |
23 | - return $json; |
|
24 | - } |
|
23 | + return $json; |
|
24 | + } |
|
25 | 25 | } |
@@ -12,267 +12,267 @@ |
||
12 | 12 | |
13 | 13 | class OptimizationProblem extends Common |
14 | 14 | { |
15 | - public $optimization_problem_id; |
|
16 | - public $user_errors = array(); |
|
17 | - public $state; |
|
18 | - public $optimization_errors = array(); |
|
19 | - public $parameters; |
|
20 | - public $sent_to_background; |
|
21 | - public $created_timestamp; |
|
22 | - public $scheduled_for; |
|
23 | - public $optimization_completed_timestamp; |
|
24 | - public $addresses = array(); |
|
25 | - public $routes = array(); |
|
26 | - public $links = array(); |
|
15 | + public $optimization_problem_id; |
|
16 | + public $user_errors = array(); |
|
17 | + public $state; |
|
18 | + public $optimization_errors = array(); |
|
19 | + public $parameters; |
|
20 | + public $sent_to_background; |
|
21 | + public $created_timestamp; |
|
22 | + public $scheduled_for; |
|
23 | + public $optimization_completed_timestamp; |
|
24 | + public $addresses = array(); |
|
25 | + public $routes = array(); |
|
26 | + public $links = array(); |
|
27 | 27 | |
28 | - function __construct() |
|
29 | - { |
|
30 | - $this->parameters = new RouteParameters; |
|
31 | - } |
|
28 | + function __construct() |
|
29 | + { |
|
30 | + $this->parameters = new RouteParameters; |
|
31 | + } |
|
32 | 32 | |
33 | - public static function fromArray(array $params) |
|
34 | - { |
|
35 | - $problem = new OptimizationProblem; |
|
36 | - $problem->optimization_problem_id = Common::getValue($params, 'optimization_problem_id'); |
|
37 | - $problem->user_errors = Common::getValue($params, 'user_errors', array()); |
|
38 | - $problem->state = Common::getValue($params, 'state', array()); |
|
39 | - $problem->sent_to_background = Common::getValue($params, 'sent_to_background', array()); |
|
40 | - $problem->links = Common::getValue($params, 'links', array()); |
|
33 | + public static function fromArray(array $params) |
|
34 | + { |
|
35 | + $problem = new OptimizationProblem; |
|
36 | + $problem->optimization_problem_id = Common::getValue($params, 'optimization_problem_id'); |
|
37 | + $problem->user_errors = Common::getValue($params, 'user_errors', array()); |
|
38 | + $problem->state = Common::getValue($params, 'state', array()); |
|
39 | + $problem->sent_to_background = Common::getValue($params, 'sent_to_background', array()); |
|
40 | + $problem->links = Common::getValue($params, 'links', array()); |
|
41 | 41 | |
42 | - if (isset($params['parameters'])) { |
|
43 | - $problem->parameters = RouteParameters::fromArray($params['parameters']); |
|
44 | - } |
|
42 | + if (isset($params['parameters'])) { |
|
43 | + $problem->parameters = RouteParameters::fromArray($params['parameters']); |
|
44 | + } |
|
45 | 45 | |
46 | - if (isset($params['addresses'])) { |
|
47 | - $addresses = array(); |
|
46 | + if (isset($params['addresses'])) { |
|
47 | + $addresses = array(); |
|
48 | 48 | |
49 | - foreach ($params['addresses'] as $address) { |
|
50 | - $addresses[] = Address::fromArray($address); |
|
51 | - } |
|
49 | + foreach ($params['addresses'] as $address) { |
|
50 | + $addresses[] = Address::fromArray($address); |
|
51 | + } |
|
52 | 52 | |
53 | - $problem->addresses = $addresses; |
|
54 | - } |
|
53 | + $problem->addresses = $addresses; |
|
54 | + } |
|
55 | 55 | |
56 | - if (isset($params['routes'])) { |
|
57 | - $routes = array(); |
|
56 | + if (isset($params['routes'])) { |
|
57 | + $routes = array(); |
|
58 | 58 | |
59 | - foreach ($params['routes'] as $route) { |
|
60 | - $routes[] = Route::fromArray($route); |
|
61 | - } |
|
59 | + foreach ($params['routes'] as $route) { |
|
60 | + $routes[] = Route::fromArray($route); |
|
61 | + } |
|
62 | 62 | |
63 | - $problem->routes = $routes; |
|
64 | - } |
|
63 | + $problem->routes = $routes; |
|
64 | + } |
|
65 | 65 | |
66 | - return $problem; |
|
67 | - } |
|
66 | + return $problem; |
|
67 | + } |
|
68 | 68 | |
69 | - public static function optimize(OptimizationProblemParams $params) |
|
70 | - { |
|
71 | - $optimize = Route4Me::makeRequst(array( |
|
72 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
73 | - 'method' => 'POST', |
|
74 | - 'query' => array( |
|
75 | - 'redirect' => isset($params->redirect) ? $params->redirect : null, |
|
76 | - 'directions' => isset($params->directions) ? $params->directions : null, |
|
77 | - 'format' => isset($params->format) ? $params->format : null, |
|
78 | - 'route_path_output' => isset($params->route_path_output) ? $params->route_path_output : null, |
|
79 | - 'optimized_callback_url' => isset($params->optimized_callback_url) ? $params->optimized_callback_url : null |
|
80 | - ), |
|
81 | - 'body' => array( |
|
82 | - 'addresses' => $params->getAddressesArray(), |
|
83 | - 'parameters' => $params->getParametersArray() |
|
84 | - ) |
|
85 | - )); |
|
69 | + public static function optimize(OptimizationProblemParams $params) |
|
70 | + { |
|
71 | + $optimize = Route4Me::makeRequst(array( |
|
72 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
73 | + 'method' => 'POST', |
|
74 | + 'query' => array( |
|
75 | + 'redirect' => isset($params->redirect) ? $params->redirect : null, |
|
76 | + 'directions' => isset($params->directions) ? $params->directions : null, |
|
77 | + 'format' => isset($params->format) ? $params->format : null, |
|
78 | + 'route_path_output' => isset($params->route_path_output) ? $params->route_path_output : null, |
|
79 | + 'optimized_callback_url' => isset($params->optimized_callback_url) ? $params->optimized_callback_url : null |
|
80 | + ), |
|
81 | + 'body' => array( |
|
82 | + 'addresses' => $params->getAddressesArray(), |
|
83 | + 'parameters' => $params->getParametersArray() |
|
84 | + ) |
|
85 | + )); |
|
86 | 86 | |
87 | - return OptimizationProblem::fromArray($optimize); |
|
88 | - } |
|
87 | + return OptimizationProblem::fromArray($optimize); |
|
88 | + } |
|
89 | 89 | |
90 | - public static function get($params) |
|
91 | - { |
|
92 | - $optimize = Route4Me::makeRequst(array( |
|
93 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
94 | - 'method' => 'GET', |
|
95 | - 'query' => array( |
|
96 | - 'state' => isset($params['state']) ? $params['state'] : null, |
|
97 | - 'limit' => isset($params['limit']) ? $params['limit'] : null, |
|
98 | - 'offset' => isset($params['offset']) ? $params['offset'] : null, |
|
99 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
100 | - ? $params['optimization_problem_id'] : null, |
|
101 | - 'wait_for_final_state' => isset($params['wait_for_final_state']) |
|
102 | - ? $params['wait_for_final_state'] : null, |
|
103 | - ) |
|
104 | - )); |
|
90 | + public static function get($params) |
|
91 | + { |
|
92 | + $optimize = Route4Me::makeRequst(array( |
|
93 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
94 | + 'method' => 'GET', |
|
95 | + 'query' => array( |
|
96 | + 'state' => isset($params['state']) ? $params['state'] : null, |
|
97 | + 'limit' => isset($params['limit']) ? $params['limit'] : null, |
|
98 | + 'offset' => isset($params['offset']) ? $params['offset'] : null, |
|
99 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
100 | + ? $params['optimization_problem_id'] : null, |
|
101 | + 'wait_for_final_state' => isset($params['wait_for_final_state']) |
|
102 | + ? $params['wait_for_final_state'] : null, |
|
103 | + ) |
|
104 | + )); |
|
105 | 105 | |
106 | - if (isset($optimize['optimizations'])) { |
|
107 | - $problems = array(); |
|
106 | + if (isset($optimize['optimizations'])) { |
|
107 | + $problems = array(); |
|
108 | 108 | |
109 | - foreach($optimize['optimizations'] as $problem) { |
|
110 | - $problems[] = OptimizationProblem::fromArray($problem); |
|
111 | - } |
|
109 | + foreach($optimize['optimizations'] as $problem) { |
|
110 | + $problems[] = OptimizationProblem::fromArray($problem); |
|
111 | + } |
|
112 | 112 | |
113 | - return $problems; |
|
114 | - } else { |
|
115 | - return OptimizationProblem::fromArray($optimize); |
|
116 | - } |
|
117 | - } |
|
113 | + return $problems; |
|
114 | + } else { |
|
115 | + return OptimizationProblem::fromArray($optimize); |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - public static function reoptimize($params) |
|
120 | - { |
|
121 | - $param = new OptimizationProblemParams; |
|
122 | - $param->optimization_problem_id = isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null; |
|
123 | - $param->reoptimize = 1; |
|
119 | + public static function reoptimize($params) |
|
120 | + { |
|
121 | + $param = new OptimizationProblemParams; |
|
122 | + $param->optimization_problem_id = isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null; |
|
123 | + $param->reoptimize = 1; |
|
124 | 124 | |
125 | - return self::update((array)$param); |
|
126 | - } |
|
125 | + return self::update((array)$param); |
|
126 | + } |
|
127 | 127 | |
128 | - public static function update($params) |
|
129 | - { |
|
130 | - $optimize = Route4Me::makeRequst(array( |
|
131 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
132 | - 'method' => 'PUT', |
|
133 | - 'query' => array( |
|
134 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
135 | - ? $params['optimization_problem_id'] : null, |
|
136 | - 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
|
137 | - 'reoptimize' => isset($params['reoptimize']) ? $params['reoptimize'] : null, |
|
138 | - ) |
|
139 | - )); |
|
128 | + public static function update($params) |
|
129 | + { |
|
130 | + $optimize = Route4Me::makeRequst(array( |
|
131 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
132 | + 'method' => 'PUT', |
|
133 | + 'query' => array( |
|
134 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
135 | + ? $params['optimization_problem_id'] : null, |
|
136 | + 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
|
137 | + 'reoptimize' => isset($params['reoptimize']) ? $params['reoptimize'] : null, |
|
138 | + ) |
|
139 | + )); |
|
140 | 140 | |
141 | - return $optimize; |
|
142 | - } |
|
141 | + return $optimize; |
|
142 | + } |
|
143 | 143 | |
144 | - public function getOptimizationId() |
|
145 | - { |
|
146 | - return $this->optimization_problem_id; |
|
147 | - } |
|
144 | + public function getOptimizationId() |
|
145 | + { |
|
146 | + return $this->optimization_problem_id; |
|
147 | + } |
|
148 | 148 | |
149 | - public function getRoutes() |
|
150 | - { |
|
151 | - return $this->routes; |
|
152 | - } |
|
149 | + public function getRoutes() |
|
150 | + { |
|
151 | + return $this->routes; |
|
152 | + } |
|
153 | 153 | |
154 | - public function getRandomOptimizationId($offset,$limit) |
|
155 | - { |
|
156 | - $query['limit'] = isset($params['limit']) ? $params['limit'] : 30; |
|
157 | - $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
154 | + public function getRandomOptimizationId($offset,$limit) |
|
155 | + { |
|
156 | + $query['limit'] = isset($params['limit']) ? $params['limit'] : 30; |
|
157 | + $query['offset'] = isset($params['offset']) ? $params['offset'] : 0; |
|
158 | 158 | |
159 | - $json = Route4Me::makeRequst(array( |
|
160 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
161 | - 'method' => 'GET', |
|
162 | - 'query' => $query |
|
163 | - )); |
|
159 | + $json = Route4Me::makeRequst(array( |
|
160 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
161 | + 'method' => 'GET', |
|
162 | + 'query' => $query |
|
163 | + )); |
|
164 | 164 | |
165 | - $optimizations = array(); |
|
166 | - foreach($json as $optimization) { |
|
167 | - if (gettype($optimization)!="array") continue; |
|
165 | + $optimizations = array(); |
|
166 | + foreach($json as $optimization) { |
|
167 | + if (gettype($optimization)!="array") continue; |
|
168 | 168 | |
169 | - foreach ($optimization as $otp1) { |
|
170 | - $optimizations[] = $otp1; |
|
171 | - } |
|
172 | - } |
|
169 | + foreach ($optimization as $otp1) { |
|
170 | + $optimizations[] = $otp1; |
|
171 | + } |
|
172 | + } |
|
173 | 173 | |
174 | - $num = rand(0,sizeof($optimizations)-1); |
|
174 | + $num = rand(0,sizeof($optimizations)-1); |
|
175 | 175 | |
176 | - $rOptimization = $optimizations[$num]; |
|
176 | + $rOptimization = $optimizations[$num]; |
|
177 | 177 | |
178 | - return $rOptimization['optimization_problem_id']; |
|
179 | - } |
|
178 | + return $rOptimization['optimization_problem_id']; |
|
179 | + } |
|
180 | 180 | |
181 | - public function getAddresses($opt_id) |
|
182 | - { |
|
183 | - if ($opt_id == null) return null; |
|
181 | + public function getAddresses($opt_id) |
|
182 | + { |
|
183 | + if ($opt_id == null) return null; |
|
184 | 184 | |
185 | - $params = array( "optimization_problem_id" => $opt_id ); |
|
185 | + $params = array( "optimization_problem_id" => $opt_id ); |
|
186 | 186 | |
187 | - $optimization = (array)$this->get($params); |
|
187 | + $optimization = (array)$this->get($params); |
|
188 | 188 | |
189 | - $addresses = $optimization["addresses"]; |
|
189 | + $addresses = $optimization["addresses"]; |
|
190 | 190 | |
191 | - return $addresses; |
|
192 | - } |
|
191 | + return $addresses; |
|
192 | + } |
|
193 | 193 | |
194 | - public function getRandomAddressFromOptimization($opt_id) |
|
195 | - { |
|
196 | - $addresses = (array)$this->getAddresses($opt_id); |
|
194 | + public function getRandomAddressFromOptimization($opt_id) |
|
195 | + { |
|
196 | + $addresses = (array)$this->getAddresses($opt_id); |
|
197 | 197 | |
198 | - if ($addresses == null) { |
|
199 | - echo "There are no addresses in this optimization!.. Try again."; |
|
200 | - return null; |
|
201 | - } |
|
198 | + if ($addresses == null) { |
|
199 | + echo "There are no addresses in this optimization!.. Try again."; |
|
200 | + return null; |
|
201 | + } |
|
202 | 202 | |
203 | - $num = rand(0,sizeof($addresses)-1); |
|
203 | + $num = rand(0,sizeof($addresses)-1); |
|
204 | 204 | |
205 | - $rAddress = $addresses[$num]; |
|
205 | + $rAddress = $addresses[$num]; |
|
206 | 206 | |
207 | - return $rAddress; |
|
208 | - } |
|
207 | + return $rAddress; |
|
208 | + } |
|
209 | 209 | |
210 | - public function removeAddress($params) |
|
211 | - { |
|
212 | - $response = Route4Me::makeRequst(array( |
|
213 | - 'url' => Endpoint::ADDRESS_V4, |
|
214 | - 'method' => 'DELETE', |
|
215 | - 'query' => array( |
|
216 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
217 | - ? $params['optimization_problem_id'] : null, |
|
218 | - 'route_destination_id' => isset($params['route_destination_id']) |
|
219 | - ? $params['route_destination_id'] : null, |
|
220 | - ) |
|
221 | - )); |
|
210 | + public function removeAddress($params) |
|
211 | + { |
|
212 | + $response = Route4Me::makeRequst(array( |
|
213 | + 'url' => Endpoint::ADDRESS_V4, |
|
214 | + 'method' => 'DELETE', |
|
215 | + 'query' => array( |
|
216 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
217 | + ? $params['optimization_problem_id'] : null, |
|
218 | + 'route_destination_id' => isset($params['route_destination_id']) |
|
219 | + ? $params['route_destination_id'] : null, |
|
220 | + ) |
|
221 | + )); |
|
222 | 222 | |
223 | - return $response; |
|
224 | - } |
|
223 | + return $response; |
|
224 | + } |
|
225 | 225 | |
226 | - public function removeOptimization($params) |
|
227 | - { |
|
228 | - $response = Route4Me::makeRequst(array( |
|
229 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
230 | - 'method' => 'DELETE', |
|
231 | - 'query' => array( |
|
232 | - 'redirect' => isset($params['redirect']) ? $params['redirect'] : null, |
|
233 | - ), |
|
234 | - 'body' => array( |
|
235 | - 'optimization_problem_ids' => isset($params['optimization_problem_ids']) |
|
236 | - ? $params['optimization_problem_ids'] : null, |
|
237 | - ) |
|
238 | - )); |
|
226 | + public function removeOptimization($params) |
|
227 | + { |
|
228 | + $response = Route4Me::makeRequst(array( |
|
229 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
230 | + 'method' => 'DELETE', |
|
231 | + 'query' => array( |
|
232 | + 'redirect' => isset($params['redirect']) ? $params['redirect'] : null, |
|
233 | + ), |
|
234 | + 'body' => array( |
|
235 | + 'optimization_problem_ids' => isset($params['optimization_problem_ids']) |
|
236 | + ? $params['optimization_problem_ids'] : null, |
|
237 | + ) |
|
238 | + )); |
|
239 | 239 | |
240 | - return $response; |
|
241 | - } |
|
240 | + return $response; |
|
241 | + } |
|
242 | 242 | |
243 | - public function getHybridOptimization($params) |
|
244 | - { |
|
245 | - $optimize = Route4Me::makeRequst(array( |
|
246 | - 'url' => Endpoint::HYBRID_DATE_OPTIMIZATION, |
|
247 | - 'method' => 'GET', |
|
248 | - 'query' => array( |
|
249 | - 'target_date_string' => isset($params['target_date_string']) |
|
250 | - ? $params['target_date_string'] : null, |
|
251 | - 'timezone_offset_minutes' => isset($params['timezone_offset_minutes']) |
|
252 | - ? $params['timezone_offset_minutes'] : null |
|
253 | - ) |
|
254 | - )); |
|
243 | + public function getHybridOptimization($params) |
|
244 | + { |
|
245 | + $optimize = Route4Me::makeRequst(array( |
|
246 | + 'url' => Endpoint::HYBRID_DATE_OPTIMIZATION, |
|
247 | + 'method' => 'GET', |
|
248 | + 'query' => array( |
|
249 | + 'target_date_string' => isset($params['target_date_string']) |
|
250 | + ? $params['target_date_string'] : null, |
|
251 | + 'timezone_offset_minutes' => isset($params['timezone_offset_minutes']) |
|
252 | + ? $params['timezone_offset_minutes'] : null |
|
253 | + ) |
|
254 | + )); |
|
255 | 255 | |
256 | - return $optimize; |
|
257 | - } |
|
256 | + return $optimize; |
|
257 | + } |
|
258 | 258 | |
259 | - Public function addDepotsToHybrid($params) |
|
260 | - { |
|
261 | - $depots = Route4Me::makeRequst(array( |
|
262 | - 'url' => Endpoint::CHANGE_HYBRID_OPTIMIZATION_DEPOT, |
|
263 | - 'method' => 'POST', |
|
264 | - 'query' => array( |
|
265 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
266 | - ? $params['optimization_problem_id'] : null, |
|
267 | - ), |
|
268 | - 'body' => array( |
|
269 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
270 | - ? $params['optimization_problem_id'] : null, |
|
271 | - 'delete_old_depots' => isset($params['delete_old_depots']) ? $params['delete_old_depots'] : null, |
|
272 | - 'new_depots' => isset($params['new_depots']) ? $params['new_depots'] : null, |
|
273 | - ) |
|
274 | - )); |
|
259 | + Public function addDepotsToHybrid($params) |
|
260 | + { |
|
261 | + $depots = Route4Me::makeRequst(array( |
|
262 | + 'url' => Endpoint::CHANGE_HYBRID_OPTIMIZATION_DEPOT, |
|
263 | + 'method' => 'POST', |
|
264 | + 'query' => array( |
|
265 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
266 | + ? $params['optimization_problem_id'] : null, |
|
267 | + ), |
|
268 | + 'body' => array( |
|
269 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) |
|
270 | + ? $params['optimization_problem_id'] : null, |
|
271 | + 'delete_old_depots' => isset($params['delete_old_depots']) ? $params['delete_old_depots'] : null, |
|
272 | + 'new_depots' => isset($params['new_depots']) ? $params['new_depots'] : null, |
|
273 | + ) |
|
274 | + )); |
|
275 | 275 | |
276 | - return $depots; |
|
277 | - } |
|
276 | + return $depots; |
|
277 | + } |
|
278 | 278 | } |
@@ -6,380 +6,380 @@ |
||
6 | 6 | |
7 | 7 | class Order extends Common |
8 | 8 | { |
9 | - public $address_1; |
|
10 | - public $address_2; |
|
11 | - public $cached_lat; |
|
12 | - public $cached_lng; |
|
13 | - public $curbside_lat; |
|
14 | - public $curbside_lng; |
|
15 | - public $address_alias; |
|
16 | - public $address_city; |
|
17 | - public $EXT_FIELD_first_name; |
|
18 | - public $EXT_FIELD_last_name; |
|
19 | - public $EXT_FIELD_email; |
|
20 | - public $EXT_FIELD_phone; |
|
21 | - public $EXT_FIELD_custom_data; |
|
9 | + public $address_1; |
|
10 | + public $address_2; |
|
11 | + public $cached_lat; |
|
12 | + public $cached_lng; |
|
13 | + public $curbside_lat; |
|
14 | + public $curbside_lng; |
|
15 | + public $address_alias; |
|
16 | + public $address_city; |
|
17 | + public $EXT_FIELD_first_name; |
|
18 | + public $EXT_FIELD_last_name; |
|
19 | + public $EXT_FIELD_email; |
|
20 | + public $EXT_FIELD_phone; |
|
21 | + public $EXT_FIELD_custom_data; |
|
22 | 22 | |
23 | - public $color; |
|
24 | - public $order_icon; |
|
25 | - public $local_time_window_start; |
|
26 | - public $local_time_window_end; |
|
27 | - public $local_time_window_start_2; |
|
28 | - public $local_time_window_end_2; |
|
29 | - public $service_time; |
|
23 | + public $color; |
|
24 | + public $order_icon; |
|
25 | + public $local_time_window_start; |
|
26 | + public $local_time_window_end; |
|
27 | + public $local_time_window_start_2; |
|
28 | + public $local_time_window_end_2; |
|
29 | + public $service_time; |
|
30 | 30 | |
31 | - public $day_scheduled_for_YYMMDD; |
|
31 | + public $day_scheduled_for_YYMMDD; |
|
32 | 32 | |
33 | - public $route_id; |
|
34 | - public $redirect; |
|
35 | - public $optimization_problem_id; |
|
36 | - public $order_id; |
|
37 | - public $order_ids; |
|
33 | + public $route_id; |
|
34 | + public $redirect; |
|
35 | + public $optimization_problem_id; |
|
36 | + public $order_id; |
|
37 | + public $order_ids; |
|
38 | 38 | |
39 | - public $day_added_YYMMDD; |
|
40 | - public $scheduled_for_YYMMDD; |
|
41 | - public $fields; |
|
42 | - public $offset; |
|
43 | - public $limit; |
|
44 | - public $query; |
|
39 | + public $day_added_YYMMDD; |
|
40 | + public $scheduled_for_YYMMDD; |
|
41 | + public $fields; |
|
42 | + public $offset; |
|
43 | + public $limit; |
|
44 | + public $query; |
|
45 | 45 | |
46 | - public $created_timestamp; |
|
47 | - public $order_status_id; |
|
48 | - public $member_id; |
|
49 | - public $address_state_id; |
|
50 | - public $address_country_id; |
|
51 | - public $address_zip; |
|
52 | - public $in_route_count; |
|
53 | - public $last_visited_timestamp; |
|
54 | - public $last_routed_timestamp; |
|
55 | - public $local_timezone_string; |
|
56 | - public $is_validated; |
|
57 | - public $is_pending; |
|
58 | - public $is_accepted; |
|
59 | - public $is_started; |
|
60 | - public $is_completed; |
|
61 | - public $custom_user_fields; |
|
46 | + public $created_timestamp; |
|
47 | + public $order_status_id; |
|
48 | + public $member_id; |
|
49 | + public $address_state_id; |
|
50 | + public $address_country_id; |
|
51 | + public $address_zip; |
|
52 | + public $in_route_count; |
|
53 | + public $last_visited_timestamp; |
|
54 | + public $last_routed_timestamp; |
|
55 | + public $local_timezone_string; |
|
56 | + public $is_validated; |
|
57 | + public $is_pending; |
|
58 | + public $is_accepted; |
|
59 | + public $is_started; |
|
60 | + public $is_completed; |
|
61 | + public $custom_user_fields; |
|
62 | 62 | |
63 | - public static function fromArray(array $params) { |
|
64 | - $order= new Order(); |
|
65 | - foreach($params as $key => $value) { |
|
66 | - if (property_exists($order, $key)) { |
|
67 | - $order->{$key} = $value; |
|
68 | - } |
|
69 | - } |
|
63 | + public static function fromArray(array $params) { |
|
64 | + $order= new Order(); |
|
65 | + foreach($params as $key => $value) { |
|
66 | + if (property_exists($order, $key)) { |
|
67 | + $order->{$key} = $value; |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - return $order; |
|
72 | - } |
|
71 | + return $order; |
|
72 | + } |
|
73 | 73 | |
74 | - public static function addOrder($params) |
|
75 | - { |
|
76 | - $response = Route4Me::makeRequst(array( |
|
77 | - 'url' => Endpoint::ORDER_V4, |
|
78 | - 'method' => 'POST', |
|
79 | - 'body' => array( |
|
80 | - 'address_1' => isset($params->address_1) ? $params->address_1: null, |
|
81 | - 'address_2' => isset($params->address_2) ? $params->address_2: null, |
|
82 | - 'member_id' => isset($params->member_id) ? $params->member_id: null, |
|
83 | - 'cached_lat' => isset($params->cached_lat) ? $params->cached_lat : null, |
|
84 | - 'cached_lng' => isset($params->cached_lng) ? $params->cached_lng : null, |
|
85 | - 'curbside_lat' => isset($params->curbside_lat) ? $params->curbside_lat : null, |
|
86 | - 'curbside_lng' => isset($params->curbside_lng) ? $params->curbside_lng : null, |
|
87 | - 'color' => isset($params->color) ? $params->color : null, |
|
88 | - 'order_icon' => isset($params->order_icon) ? $params->order_icon : null, |
|
89 | - 'day_scheduled_for_YYMMDD' => isset($params->day_scheduled_for_YYMMDD) ? $params->day_scheduled_for_YYMMDD : null, |
|
90 | - 'address_alias' => isset($params->address_alias) ? $params->address_alias : null, |
|
91 | - 'address_city' => isset($params->address_city) ? $params->address_city: null, |
|
92 | - 'address_state_id' => isset($params->address_state_id) ? $params->address_state_id: null, |
|
93 | - 'address_country_id' => isset($params->address_country_id) ? $params->address_country_id: null, |
|
94 | - 'address_zip' => isset($params->address_zip) ? $params->address_zip: null, |
|
95 | - 'local_time_window_start' => isset($params->local_time_window_start) ? $params->local_time_window_start: null, |
|
96 | - 'local_time_window_end' => isset($params->local_time_window_end) ? $params->local_time_window_end: null, |
|
97 | - 'local_time_window_start_2' => isset($params->local_time_window_start_2) ? $params->local_time_window_start_2: null, |
|
98 | - 'local_time_window_end_2' => isset($params->local_time_window_end_2) ? $params->local_time_window_end_2: null, |
|
99 | - 'service_time' => isset($params->service_time) ? $params->service_time: null, |
|
100 | - 'local_timezone_string' => isset($params->local_timezone_string) ? $params->local_timezone_string: null, |
|
101 | - 'EXT_FIELD_first_name' => isset($params->EXT_FIELD_first_name) ? $params->EXT_FIELD_first_name: null, |
|
102 | - 'EXT_FIELD_last_name' => isset($params->EXT_FIELD_last_name) ? $params->EXT_FIELD_last_name: null, |
|
103 | - 'EXT_FIELD_email' => isset($params->EXT_FIELD_email) ? $params->EXT_FIELD_email: null, |
|
104 | - 'EXT_FIELD_phone' => isset($params->EXT_FIELD_phone) ? $params->EXT_FIELD_phone: null, |
|
105 | - 'EXT_FIELD_custom_data' => isset($params->EXT_FIELD_custom_data) ? $params->EXT_FIELD_custom_data: null, |
|
106 | - 'is_validated' => isset($params->is_validated) ? $params->is_validated: null, |
|
107 | - 'is_pending' => isset($params->is_pending) ? $params->is_pending: null, |
|
108 | - 'is_accepted' => isset($params->is_accepted) ? $params->is_accepted: null, |
|
109 | - 'is_started' => isset($params->is_started) ? $params->is_started: null, |
|
110 | - 'is_completed' => isset($params->is_completed) ? $params->is_completed: null, |
|
111 | - 'custom_user_fields' => isset($params->custom_user_fields) ? $params->custom_user_fields: null |
|
112 | - ) |
|
113 | - )); |
|
74 | + public static function addOrder($params) |
|
75 | + { |
|
76 | + $response = Route4Me::makeRequst(array( |
|
77 | + 'url' => Endpoint::ORDER_V4, |
|
78 | + 'method' => 'POST', |
|
79 | + 'body' => array( |
|
80 | + 'address_1' => isset($params->address_1) ? $params->address_1: null, |
|
81 | + 'address_2' => isset($params->address_2) ? $params->address_2: null, |
|
82 | + 'member_id' => isset($params->member_id) ? $params->member_id: null, |
|
83 | + 'cached_lat' => isset($params->cached_lat) ? $params->cached_lat : null, |
|
84 | + 'cached_lng' => isset($params->cached_lng) ? $params->cached_lng : null, |
|
85 | + 'curbside_lat' => isset($params->curbside_lat) ? $params->curbside_lat : null, |
|
86 | + 'curbside_lng' => isset($params->curbside_lng) ? $params->curbside_lng : null, |
|
87 | + 'color' => isset($params->color) ? $params->color : null, |
|
88 | + 'order_icon' => isset($params->order_icon) ? $params->order_icon : null, |
|
89 | + 'day_scheduled_for_YYMMDD' => isset($params->day_scheduled_for_YYMMDD) ? $params->day_scheduled_for_YYMMDD : null, |
|
90 | + 'address_alias' => isset($params->address_alias) ? $params->address_alias : null, |
|
91 | + 'address_city' => isset($params->address_city) ? $params->address_city: null, |
|
92 | + 'address_state_id' => isset($params->address_state_id) ? $params->address_state_id: null, |
|
93 | + 'address_country_id' => isset($params->address_country_id) ? $params->address_country_id: null, |
|
94 | + 'address_zip' => isset($params->address_zip) ? $params->address_zip: null, |
|
95 | + 'local_time_window_start' => isset($params->local_time_window_start) ? $params->local_time_window_start: null, |
|
96 | + 'local_time_window_end' => isset($params->local_time_window_end) ? $params->local_time_window_end: null, |
|
97 | + 'local_time_window_start_2' => isset($params->local_time_window_start_2) ? $params->local_time_window_start_2: null, |
|
98 | + 'local_time_window_end_2' => isset($params->local_time_window_end_2) ? $params->local_time_window_end_2: null, |
|
99 | + 'service_time' => isset($params->service_time) ? $params->service_time: null, |
|
100 | + 'local_timezone_string' => isset($params->local_timezone_string) ? $params->local_timezone_string: null, |
|
101 | + 'EXT_FIELD_first_name' => isset($params->EXT_FIELD_first_name) ? $params->EXT_FIELD_first_name: null, |
|
102 | + 'EXT_FIELD_last_name' => isset($params->EXT_FIELD_last_name) ? $params->EXT_FIELD_last_name: null, |
|
103 | + 'EXT_FIELD_email' => isset($params->EXT_FIELD_email) ? $params->EXT_FIELD_email: null, |
|
104 | + 'EXT_FIELD_phone' => isset($params->EXT_FIELD_phone) ? $params->EXT_FIELD_phone: null, |
|
105 | + 'EXT_FIELD_custom_data' => isset($params->EXT_FIELD_custom_data) ? $params->EXT_FIELD_custom_data: null, |
|
106 | + 'is_validated' => isset($params->is_validated) ? $params->is_validated: null, |
|
107 | + 'is_pending' => isset($params->is_pending) ? $params->is_pending: null, |
|
108 | + 'is_accepted' => isset($params->is_accepted) ? $params->is_accepted: null, |
|
109 | + 'is_started' => isset($params->is_started) ? $params->is_started: null, |
|
110 | + 'is_completed' => isset($params->is_completed) ? $params->is_completed: null, |
|
111 | + 'custom_user_fields' => isset($params->custom_user_fields) ? $params->custom_user_fields: null |
|
112 | + ) |
|
113 | + )); |
|
114 | 114 | |
115 | - return $response; |
|
116 | - } |
|
115 | + return $response; |
|
116 | + } |
|
117 | 117 | |
118 | - public static function addOrder2Route($params,$body) |
|
119 | - { |
|
120 | - $response = Route4Me::makeRequst(array( |
|
121 | - 'url' => Endpoint::ROUTE_V4, |
|
122 | - 'method' => 'PUT', |
|
123 | - 'query' => array( |
|
124 | - 'route_id' => isset($params->route_id) ? $params->route_id: null, |
|
125 | - 'redirect' => isset($params->redirect) ? $params->redirect : null |
|
126 | - ), |
|
127 | - 'body' => (array)$body |
|
128 | - )); |
|
118 | + public static function addOrder2Route($params,$body) |
|
119 | + { |
|
120 | + $response = Route4Me::makeRequst(array( |
|
121 | + 'url' => Endpoint::ROUTE_V4, |
|
122 | + 'method' => 'PUT', |
|
123 | + 'query' => array( |
|
124 | + 'route_id' => isset($params->route_id) ? $params->route_id: null, |
|
125 | + 'redirect' => isset($params->redirect) ? $params->redirect : null |
|
126 | + ), |
|
127 | + 'body' => (array)$body |
|
128 | + )); |
|
129 | 129 | |
130 | - return $response; |
|
131 | - } |
|
130 | + return $response; |
|
131 | + } |
|
132 | 132 | |
133 | - public static function addOrder2Optimization($params,$body) |
|
134 | - { |
|
135 | - $response = Route4Me::makeRequst(array( |
|
136 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
137 | - 'method' => 'PUT', |
|
138 | - 'query' => array( |
|
139 | - 'optimization_problem_id' => isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null, |
|
140 | - 'redirect' => isset($params['redirect']) ? $params['redirect'] : null, |
|
141 | - 'device_type' => isset($params['device_type']) ? $params['device_type'] : null |
|
142 | - ), |
|
143 | - 'body' => (array)$body |
|
144 | - )); |
|
133 | + public static function addOrder2Optimization($params,$body) |
|
134 | + { |
|
135 | + $response = Route4Me::makeRequst(array( |
|
136 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
137 | + 'method' => 'PUT', |
|
138 | + 'query' => array( |
|
139 | + 'optimization_problem_id' => isset($params['optimization_problem_id']) ? $params['optimization_problem_id'] : null, |
|
140 | + 'redirect' => isset($params['redirect']) ? $params['redirect'] : null, |
|
141 | + 'device_type' => isset($params['device_type']) ? $params['device_type'] : null |
|
142 | + ), |
|
143 | + 'body' => (array)$body |
|
144 | + )); |
|
145 | 145 | |
146 | - return $response; |
|
147 | - } |
|
146 | + return $response; |
|
147 | + } |
|
148 | 148 | |
149 | - public static function getOrder($params) |
|
150 | - { |
|
151 | - $response = Route4Me::makeRequst(array( |
|
152 | - 'url' => Endpoint::ORDER_V4, |
|
153 | - 'method' => 'GET', |
|
154 | - 'query' => array( |
|
155 | - 'order_id' => isset($params->order_id) ? $params->order_id: null, |
|
156 | - 'fields' => isset($params->fields) ? $params->fields: null, |
|
157 | - 'day_added_YYMMDD' => isset($params->day_added_YYMMDD) ? $params->day_added_YYMMDD: null, |
|
158 | - 'scheduled_for_YYMMDD' => isset($params->scheduled_for_YYMMDD) ? $params->scheduled_for_YYMMDD: null, |
|
159 | - 'query' => isset($params->query) ? $params->query: null, |
|
160 | - 'offset' => isset($params->offset) ? $params->offset: null, |
|
161 | - 'limit' => isset($params->limit) ? $params->limit: null |
|
162 | - ) |
|
163 | - )); |
|
149 | + public static function getOrder($params) |
|
150 | + { |
|
151 | + $response = Route4Me::makeRequst(array( |
|
152 | + 'url' => Endpoint::ORDER_V4, |
|
153 | + 'method' => 'GET', |
|
154 | + 'query' => array( |
|
155 | + 'order_id' => isset($params->order_id) ? $params->order_id: null, |
|
156 | + 'fields' => isset($params->fields) ? $params->fields: null, |
|
157 | + 'day_added_YYMMDD' => isset($params->day_added_YYMMDD) ? $params->day_added_YYMMDD: null, |
|
158 | + 'scheduled_for_YYMMDD' => isset($params->scheduled_for_YYMMDD) ? $params->scheduled_for_YYMMDD: null, |
|
159 | + 'query' => isset($params->query) ? $params->query: null, |
|
160 | + 'offset' => isset($params->offset) ? $params->offset: null, |
|
161 | + 'limit' => isset($params->limit) ? $params->limit: null |
|
162 | + ) |
|
163 | + )); |
|
164 | 164 | |
165 | - return $response; |
|
166 | - } |
|
165 | + return $response; |
|
166 | + } |
|
167 | 167 | |
168 | - public static function getOrders($params) |
|
169 | - { |
|
170 | - $response = Route4Me::makeRequst(array( |
|
171 | - 'url' => Endpoint::ORDER_V4, |
|
172 | - 'method' => 'GET', |
|
173 | - 'query' => array( |
|
174 | - 'offset' => isset($params->offset) ? $params->offset: null, |
|
175 | - 'limit' => isset($params->limit) ? $params->limit: null |
|
176 | - ) |
|
177 | - )); |
|
168 | + public static function getOrders($params) |
|
169 | + { |
|
170 | + $response = Route4Me::makeRequst(array( |
|
171 | + 'url' => Endpoint::ORDER_V4, |
|
172 | + 'method' => 'GET', |
|
173 | + 'query' => array( |
|
174 | + 'offset' => isset($params->offset) ? $params->offset: null, |
|
175 | + 'limit' => isset($params->limit) ? $params->limit: null |
|
176 | + ) |
|
177 | + )); |
|
178 | 178 | |
179 | - return $response; |
|
180 | - } |
|
179 | + return $response; |
|
180 | + } |
|
181 | 181 | |
182 | - public function getRandomOrderId($offset,$limit) |
|
183 | - { |
|
184 | - $params = array('offset' => $offset, 'limit' => $limit); |
|
182 | + public function getRandomOrderId($offset,$limit) |
|
183 | + { |
|
184 | + $params = array('offset' => $offset, 'limit' => $limit); |
|
185 | 185 | |
186 | - $orders = self::getOrders($params); |
|
186 | + $orders = self::getOrders($params); |
|
187 | 187 | |
188 | - if (is_null($orders)) return null; |
|
189 | - if (!isset($orders['results'])) return null; |
|
188 | + if (is_null($orders)) return null; |
|
189 | + if (!isset($orders['results'])) return null; |
|
190 | 190 | |
191 | - $randomIndex = rand(0, sizeof($orders['results'])-1); |
|
191 | + $randomIndex = rand(0, sizeof($orders['results'])-1); |
|
192 | 192 | |
193 | - $order = $orders['results'][$randomIndex]; |
|
193 | + $order = $orders['results'][$randomIndex]; |
|
194 | 194 | |
195 | - return $order['order_id']; |
|
196 | - } |
|
195 | + return $order['order_id']; |
|
196 | + } |
|
197 | 197 | |
198 | - public function getRandomOrder($offset,$limit) |
|
199 | - { |
|
200 | - $params = array('offset' => $offset, 'limit' => $limit); |
|
198 | + public function getRandomOrder($offset,$limit) |
|
199 | + { |
|
200 | + $params = array('offset' => $offset, 'limit' => $limit); |
|
201 | 201 | |
202 | - $orders = self::getOrders($params); |
|
202 | + $orders = self::getOrders($params); |
|
203 | 203 | |
204 | - if (is_null($orders)) return null; |
|
205 | - if (!isset($orders['results'])) return null; |
|
204 | + if (is_null($orders)) return null; |
|
205 | + if (!isset($orders['results'])) return null; |
|
206 | 206 | |
207 | - $randomIndex = rand(0, sizeof($orders['results'])-1); |
|
207 | + $randomIndex = rand(0, sizeof($orders['results'])-1); |
|
208 | 208 | |
209 | - $order = $orders['results'][$randomIndex]; |
|
209 | + $order = $orders['results'][$randomIndex]; |
|
210 | 210 | |
211 | - return $order; |
|
212 | - } |
|
211 | + return $order; |
|
212 | + } |
|
213 | 213 | |
214 | - public static function removeOrder($params) |
|
215 | - { |
|
216 | - $response = Route4Me::makeRequst(array( |
|
217 | - 'url' => Endpoint::ORDER_V4, |
|
218 | - 'method' => 'DELETE', |
|
219 | - 'body' => array( |
|
220 | - 'order_ids' => isset($params->order_ids) ? $params->order_ids: null |
|
221 | - ) |
|
222 | - )); |
|
214 | + public static function removeOrder($params) |
|
215 | + { |
|
216 | + $response = Route4Me::makeRequst(array( |
|
217 | + 'url' => Endpoint::ORDER_V4, |
|
218 | + 'method' => 'DELETE', |
|
219 | + 'body' => array( |
|
220 | + 'order_ids' => isset($params->order_ids) ? $params->order_ids: null |
|
221 | + ) |
|
222 | + )); |
|
223 | 223 | |
224 | - return $response; |
|
225 | - } |
|
224 | + return $response; |
|
225 | + } |
|
226 | 226 | |
227 | - public static function updateOrder($body) |
|
228 | - { |
|
229 | - $response = Route4Me::makeRequst(array( |
|
230 | - 'url' => Endpoint::ORDER_V4, |
|
231 | - 'method' => 'PUT', |
|
232 | - 'body' => (array)$body |
|
233 | - )); |
|
227 | + public static function updateOrder($body) |
|
228 | + { |
|
229 | + $response = Route4Me::makeRequst(array( |
|
230 | + 'url' => Endpoint::ORDER_V4, |
|
231 | + 'method' => 'PUT', |
|
232 | + 'body' => (array)$body |
|
233 | + )); |
|
234 | 234 | |
235 | - return $response; |
|
236 | - } |
|
235 | + return $response; |
|
236 | + } |
|
237 | 237 | |
238 | - public static function searchOrder($params) |
|
239 | - { |
|
240 | - $response = Route4Me::makeRequst(array( |
|
241 | - 'url' => Endpoint::ORDER_V4, |
|
242 | - 'method' => 'GET', |
|
243 | - 'query' => array( |
|
244 | - 'day_added_YYMMDD' => isset($params->day_added_YYMMDD) ? $params->day_added_YYMMDD: null, |
|
245 | - 'scheduled_for_YYMMDD' => isset($params->scheduled_for_YYMMDD) ? $params->scheduled_for_YYMMDD: null, |
|
246 | - 'fields' => isset($params->fields) ? $params->fields: null, |
|
247 | - 'offset' => isset($params->offset) ? $params->offset: null, |
|
248 | - 'limit' => isset($params->limit) ? $params->limit: null, |
|
249 | - 'query' => isset($params->query) ? $params->query: null, |
|
250 | - ) |
|
251 | - )); |
|
238 | + public static function searchOrder($params) |
|
239 | + { |
|
240 | + $response = Route4Me::makeRequst(array( |
|
241 | + 'url' => Endpoint::ORDER_V4, |
|
242 | + 'method' => 'GET', |
|
243 | + 'query' => array( |
|
244 | + 'day_added_YYMMDD' => isset($params->day_added_YYMMDD) ? $params->day_added_YYMMDD: null, |
|
245 | + 'scheduled_for_YYMMDD' => isset($params->scheduled_for_YYMMDD) ? $params->scheduled_for_YYMMDD: null, |
|
246 | + 'fields' => isset($params->fields) ? $params->fields: null, |
|
247 | + 'offset' => isset($params->offset) ? $params->offset: null, |
|
248 | + 'limit' => isset($params->limit) ? $params->limit: null, |
|
249 | + 'query' => isset($params->query) ? $params->query: null, |
|
250 | + ) |
|
251 | + )); |
|
252 | 252 | |
253 | - return $response; |
|
254 | - } |
|
253 | + return $response; |
|
254 | + } |
|
255 | 255 | |
256 | - public static function validateLatitude($lat) |
|
257 | - { |
|
258 | - if (!is_numeric($lat)) return false; |
|
256 | + public static function validateLatitude($lat) |
|
257 | + { |
|
258 | + if (!is_numeric($lat)) return false; |
|
259 | 259 | |
260 | - if ($lat>90 || $lat<-90) return false; |
|
260 | + if ($lat>90 || $lat<-90) return false; |
|
261 | 261 | |
262 | - return true; |
|
263 | - } |
|
262 | + return true; |
|
263 | + } |
|
264 | 264 | |
265 | - public static function validateLongitude($lng) |
|
266 | - { |
|
267 | - if (!is_numeric($lng)) return false; |
|
265 | + public static function validateLongitude($lng) |
|
266 | + { |
|
267 | + if (!is_numeric($lng)) return false; |
|
268 | 268 | |
269 | - if ($lng>180 || $lng<-180) return false; |
|
269 | + if ($lng>180 || $lng<-180) return false; |
|
270 | 270 | |
271 | - return true; |
|
272 | - } |
|
271 | + return true; |
|
272 | + } |
|
273 | 273 | |
274 | - public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping) |
|
275 | - { |
|
276 | - $max_line_length = 512; |
|
277 | - $delemietr = ','; |
|
274 | + public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping) |
|
275 | + { |
|
276 | + $max_line_length = 512; |
|
277 | + $delemietr = ','; |
|
278 | 278 | |
279 | - $results = array(); |
|
280 | - $results['fail'] = array(); |
|
281 | - $results['success'] = array(); |
|
279 | + $results = array(); |
|
280 | + $results['fail'] = array(); |
|
281 | + $results['success'] = array(); |
|
282 | 282 | |
283 | - $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr); |
|
283 | + $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr); |
|
284 | 284 | |
285 | - if (!empty($columns)) { |
|
286 | - array_push($results['fail'],'Empty CSV table'); |
|
287 | - return ($results); |
|
288 | - } |
|
285 | + if (!empty($columns)) { |
|
286 | + array_push($results['fail'],'Empty CSV table'); |
|
287 | + return ($results); |
|
288 | + } |
|
289 | 289 | |
290 | - $iRow=1; |
|
290 | + $iRow=1; |
|
291 | 291 | |
292 | - while (($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr)) !== false) { |
|
293 | - if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && array(null) !== $rows) { |
|
292 | + while (($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr)) !== false) { |
|
293 | + if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && array(null) !== $rows) { |
|
294 | 294 | |
295 | - $cached_lat = 0.000; |
|
295 | + $cached_lat = 0.000; |
|
296 | 296 | |
297 | - if (!$this->validateLatitude($rows[$ordersFieldsMapping['cached_lat']])) { |
|
298 | - array_push($results['fail'],"$iRow --> Wrong cached_lat"); |
|
299 | - $iRow++; |
|
300 | - continue; |
|
301 | - } |
|
302 | - else $cached_lat = doubleval($rows[$ordersFieldsMapping['cached_lat']]); |
|
297 | + if (!$this->validateLatitude($rows[$ordersFieldsMapping['cached_lat']])) { |
|
298 | + array_push($results['fail'],"$iRow --> Wrong cached_lat"); |
|
299 | + $iRow++; |
|
300 | + continue; |
|
301 | + } |
|
302 | + else $cached_lat = doubleval($rows[$ordersFieldsMapping['cached_lat']]); |
|
303 | 303 | |
304 | - $cached_lng = 0.000; |
|
304 | + $cached_lng = 0.000; |
|
305 | 305 | |
306 | - if (!$this->validateLongitude($rows[$ordersFieldsMapping['cached_lng']])) { |
|
307 | - array_push($results['fail'],"$iRow --> Wrong cached_lng"); |
|
308 | - $iRow++; |
|
309 | - continue; |
|
310 | - } |
|
311 | - else $cached_lng = doubleval($rows[$ordersFieldsMapping['cached_lng']]); |
|
306 | + if (!$this->validateLongitude($rows[$ordersFieldsMapping['cached_lng']])) { |
|
307 | + array_push($results['fail'],"$iRow --> Wrong cached_lng"); |
|
308 | + $iRow++; |
|
309 | + continue; |
|
310 | + } |
|
311 | + else $cached_lng = doubleval($rows[$ordersFieldsMapping['cached_lng']]); |
|
312 | 312 | |
313 | - if (isset($ordersFieldsMapping['curbside_lat'])) { |
|
314 | - if (!$this->validateLatitude($rows[$ordersFieldsMapping['curbside_lat']])) { |
|
315 | - array_push($results['fail'],"$iRow --> Wrong curbside_lat"); |
|
316 | - $iRow++; |
|
317 | - continue; |
|
318 | - } |
|
319 | - } |
|
313 | + if (isset($ordersFieldsMapping['curbside_lat'])) { |
|
314 | + if (!$this->validateLatitude($rows[$ordersFieldsMapping['curbside_lat']])) { |
|
315 | + array_push($results['fail'],"$iRow --> Wrong curbside_lat"); |
|
316 | + $iRow++; |
|
317 | + continue; |
|
318 | + } |
|
319 | + } |
|
320 | 320 | |
321 | - if (isset($ordersFieldsMapping['curbside_lng'])) { |
|
322 | - if (!$this->validateLongitude($rows[$ordersFieldsMapping['curbside_lng']])) { |
|
323 | - array_push($results['fail'],"$iRow --> Wrong curbside_lng"); |
|
324 | - $iRow++; |
|
325 | - continue; |
|
326 | - } |
|
327 | - } |
|
321 | + if (isset($ordersFieldsMapping['curbside_lng'])) { |
|
322 | + if (!$this->validateLongitude($rows[$ordersFieldsMapping['curbside_lng']])) { |
|
323 | + array_push($results['fail'],"$iRow --> Wrong curbside_lng"); |
|
324 | + $iRow++; |
|
325 | + continue; |
|
326 | + } |
|
327 | + } |
|
328 | 328 | |
329 | - $address = $rows[$ordersFieldsMapping['address_1']]; |
|
329 | + $address = $rows[$ordersFieldsMapping['address_1']]; |
|
330 | 330 | |
331 | - if (isset($ordersFieldsMapping['order_city'])) $address.=', '.$rows[$ordersFieldsMapping['order_city']]; |
|
332 | - if (isset($ordersFieldsMapping['order_state_id'])) $address.=', '.$rows[$ordersFieldsMapping['order_state_id']]; |
|
333 | - if (isset($ordersFieldsMapping['order_zip_code'])) $address.=', '.$rows[$ordersFieldsMapping['order_zip_code']]; |
|
334 | - if (isset($ordersFieldsMapping['order_country_id'])) $address.=', '.$rows[$ordersFieldsMapping['order_country_id']]; |
|
331 | + if (isset($ordersFieldsMapping['order_city'])) $address.=', '.$rows[$ordersFieldsMapping['order_city']]; |
|
332 | + if (isset($ordersFieldsMapping['order_state_id'])) $address.=', '.$rows[$ordersFieldsMapping['order_state_id']]; |
|
333 | + if (isset($ordersFieldsMapping['order_zip_code'])) $address.=', '.$rows[$ordersFieldsMapping['order_zip_code']]; |
|
334 | + if (isset($ordersFieldsMapping['order_country_id'])) $address.=', '.$rows[$ordersFieldsMapping['order_country_id']]; |
|
335 | 335 | |
336 | - echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].", ".$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']]."<br>"; |
|
336 | + echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].", ".$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']]."<br>"; |
|
337 | 337 | |
338 | - $orderParameters = Order::fromArray(array( |
|
339 | - "cached_lat" => $cached_lat, |
|
340 | - "cached_lng" => $cached_lng, |
|
341 | - "curbside_lat" => isset($ordersFieldsMapping['curbside_lat']) ? $rows[$ordersFieldsMapping['curbside_lat']] : null, |
|
342 | - "curbside_lng" => isset($ordersFieldsMapping['curbside_lng']) ? $rows[$ordersFieldsMapping['curbside_lng']] : null, |
|
343 | - "color" => isset($ordersFieldsMapping['color']) ? $rows[$ordersFieldsMapping['color']] : null, |
|
344 | - "day_scheduled_for_YYMMDD" => isset($ordersFieldsMapping['day_scheduled_for_YYMMDD']) |
|
345 | - ? $rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']] : null, |
|
346 | - "address_alias" => isset($ordersFieldsMapping['address_alias']) ? $rows[$ordersFieldsMapping['address_alias']] : null, |
|
347 | - "address_1" => $address, |
|
348 | - "address_2" => isset($ordersFieldsMapping['address_2']) ? $rows[$ordersFieldsMapping['address_2']] : null, |
|
349 | - "local_time_window_start" => isset($ordersFieldsMapping['local_time_window_start']) |
|
350 | - ? $rows[$ordersFieldsMapping['local_time_window_start']] : null, |
|
351 | - "local_time_window_end" => isset($ordersFieldsMapping['local_time_window_end']) |
|
352 | - ? $rows[$ordersFieldsMapping['local_time_window_end']] : null, |
|
353 | - "local_time_window_start_2" => isset($ordersFieldsMapping['local_time_window_start_2']) |
|
354 | - ? $rows[$ordersFieldsMapping['local_time_window_start_2']] : null, |
|
355 | - "local_time_window_end_2" => isset($ordersFieldsMapping['local_time_window_end_2']) |
|
356 | - ? $rows[$ordersFieldsMapping['local_time_window_end_2']] : null, |
|
357 | - "service_time" => isset($ordersFieldsMapping['service_time']) |
|
358 | - ? $rows[$ordersFieldsMapping['service_time']] : null, |
|
359 | - "EXT_FIELD_first_name" => isset($ordersFieldsMapping['EXT_FIELD_first_name']) |
|
360 | - ? $rows[$ordersFieldsMapping['EXT_FIELD_first_name']] : null, |
|
361 | - "EXT_FIELD_last_name" => isset($ordersFieldsMapping['EXT_FIELD_last_name']) |
|
362 | - ? $rows[$ordersFieldsMapping['EXT_FIELD_last_name']] : null, |
|
363 | - "EXT_FIELD_email" => isset($ordersFieldsMapping['EXT_FIELD_email']) |
|
364 | - ? $rows[$ordersFieldsMapping['EXT_FIELD_email']] : null, |
|
365 | - "EXT_FIELD_phone" => isset($ordersFieldsMapping['EXT_FIELD_phone']) |
|
366 | - ? $rows[$ordersFieldsMapping['EXT_FIELD_phone']] : null, |
|
367 | - "EXT_FIELD_custom_data" => isset($ordersFieldsMapping['EXT_FIELD_custom_data']) |
|
368 | - ? $rows[$ordersFieldsMapping['EXT_FIELD_custom_data']] : null, |
|
369 | - "order_icon" => isset($ordersFieldsMapping['order_icon']) ? $rows[$ordersFieldsMapping['order_icon']] : null, |
|
370 | - )); |
|
338 | + $orderParameters = Order::fromArray(array( |
|
339 | + "cached_lat" => $cached_lat, |
|
340 | + "cached_lng" => $cached_lng, |
|
341 | + "curbside_lat" => isset($ordersFieldsMapping['curbside_lat']) ? $rows[$ordersFieldsMapping['curbside_lat']] : null, |
|
342 | + "curbside_lng" => isset($ordersFieldsMapping['curbside_lng']) ? $rows[$ordersFieldsMapping['curbside_lng']] : null, |
|
343 | + "color" => isset($ordersFieldsMapping['color']) ? $rows[$ordersFieldsMapping['color']] : null, |
|
344 | + "day_scheduled_for_YYMMDD" => isset($ordersFieldsMapping['day_scheduled_for_YYMMDD']) |
|
345 | + ? $rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']] : null, |
|
346 | + "address_alias" => isset($ordersFieldsMapping['address_alias']) ? $rows[$ordersFieldsMapping['address_alias']] : null, |
|
347 | + "address_1" => $address, |
|
348 | + "address_2" => isset($ordersFieldsMapping['address_2']) ? $rows[$ordersFieldsMapping['address_2']] : null, |
|
349 | + "local_time_window_start" => isset($ordersFieldsMapping['local_time_window_start']) |
|
350 | + ? $rows[$ordersFieldsMapping['local_time_window_start']] : null, |
|
351 | + "local_time_window_end" => isset($ordersFieldsMapping['local_time_window_end']) |
|
352 | + ? $rows[$ordersFieldsMapping['local_time_window_end']] : null, |
|
353 | + "local_time_window_start_2" => isset($ordersFieldsMapping['local_time_window_start_2']) |
|
354 | + ? $rows[$ordersFieldsMapping['local_time_window_start_2']] : null, |
|
355 | + "local_time_window_end_2" => isset($ordersFieldsMapping['local_time_window_end_2']) |
|
356 | + ? $rows[$ordersFieldsMapping['local_time_window_end_2']] : null, |
|
357 | + "service_time" => isset($ordersFieldsMapping['service_time']) |
|
358 | + ? $rows[$ordersFieldsMapping['service_time']] : null, |
|
359 | + "EXT_FIELD_first_name" => isset($ordersFieldsMapping['EXT_FIELD_first_name']) |
|
360 | + ? $rows[$ordersFieldsMapping['EXT_FIELD_first_name']] : null, |
|
361 | + "EXT_FIELD_last_name" => isset($ordersFieldsMapping['EXT_FIELD_last_name']) |
|
362 | + ? $rows[$ordersFieldsMapping['EXT_FIELD_last_name']] : null, |
|
363 | + "EXT_FIELD_email" => isset($ordersFieldsMapping['EXT_FIELD_email']) |
|
364 | + ? $rows[$ordersFieldsMapping['EXT_FIELD_email']] : null, |
|
365 | + "EXT_FIELD_phone" => isset($ordersFieldsMapping['EXT_FIELD_phone']) |
|
366 | + ? $rows[$ordersFieldsMapping['EXT_FIELD_phone']] : null, |
|
367 | + "EXT_FIELD_custom_data" => isset($ordersFieldsMapping['EXT_FIELD_custom_data']) |
|
368 | + ? $rows[$ordersFieldsMapping['EXT_FIELD_custom_data']] : null, |
|
369 | + "order_icon" => isset($ordersFieldsMapping['order_icon']) ? $rows[$ordersFieldsMapping['order_icon']] : null, |
|
370 | + )); |
|
371 | 371 | |
372 | - $order = new Order(); |
|
372 | + $order = new Order(); |
|
373 | 373 | |
374 | - $orderResults = $order->addOrder($orderParameters); |
|
374 | + $orderResults = $order->addOrder($orderParameters); |
|
375 | 375 | |
376 | - array_push($results['success'],"The order with order_id = ".strval($orderResults["order_id"])." added successfuly."); |
|
377 | - } |
|
378 | - else { |
|
379 | - array_push($results['fail'],"$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set"); |
|
380 | - } |
|
376 | + array_push($results['success'],"The order with order_id = ".strval($orderResults["order_id"])." added successfuly."); |
|
377 | + } |
|
378 | + else { |
|
379 | + array_push($results['fail'],"$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set"); |
|
380 | + } |
|
381 | 381 | |
382 | - $iRow++; |
|
383 | - } |
|
384 | - } |
|
382 | + $iRow++; |
|
383 | + } |
|
384 | + } |
|
385 | 385 | } |
@@ -6,141 +6,141 @@ |
||
6 | 6 | |
7 | 7 | class Geocoding extends Common |
8 | 8 | { |
9 | - public $strExportFormat; |
|
10 | - public $format; |
|
11 | - public $addresses; |
|
12 | - public $pk; |
|
13 | - public $offset; |
|
14 | - public $limit; |
|
15 | - public $housenumber; |
|
16 | - public $zipcode; |
|
9 | + public $strExportFormat; |
|
10 | + public $format; |
|
11 | + public $addresses; |
|
12 | + public $pk; |
|
13 | + public $offset; |
|
14 | + public $limit; |
|
15 | + public $housenumber; |
|
16 | + public $zipcode; |
|
17 | 17 | |
18 | - public static function fromArray(array $params) |
|
19 | - { |
|
20 | - $geocoding = new Geocoding(); |
|
21 | - |
|
22 | - foreach($params as $key => $value) { |
|
23 | - if (property_exists($geocoding, $key)) { |
|
24 | - $geocoding->{$key} = $value; |
|
25 | - } |
|
26 | - } |
|
27 | - |
|
28 | - return $geocoding; |
|
29 | - } |
|
18 | + public static function fromArray(array $params) |
|
19 | + { |
|
20 | + $geocoding = new Geocoding(); |
|
21 | + |
|
22 | + foreach($params as $key => $value) { |
|
23 | + if (property_exists($geocoding, $key)) { |
|
24 | + $geocoding->{$key} = $value; |
|
25 | + } |
|
26 | + } |
|
27 | + |
|
28 | + return $geocoding; |
|
29 | + } |
|
30 | 30 | |
31 | - public static function forwardGeocoding($params) |
|
32 | - { |
|
33 | - $body = array( |
|
34 | - 'strExportFormat' => isset($params['strExportFormat']) ? $params['strExportFormat']: null, |
|
35 | - 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
|
36 | - ); |
|
31 | + public static function forwardGeocoding($params) |
|
32 | + { |
|
33 | + $body = array( |
|
34 | + 'strExportFormat' => isset($params['strExportFormat']) ? $params['strExportFormat']: null, |
|
35 | + 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
|
36 | + ); |
|
37 | 37 | |
38 | - $fgCoding = Route4Me::makeRequst(array( |
|
39 | - 'url' => Endpoint::GEOCODER, |
|
40 | - 'method' => 'POST', |
|
41 | - 'body' => $body, |
|
42 | - 'HTTPHEADER' => 'Content-Type: multipart/form-data' |
|
43 | - )); |
|
44 | - |
|
45 | - return $fgCoding; |
|
46 | - } |
|
38 | + $fgCoding = Route4Me::makeRequst(array( |
|
39 | + 'url' => Endpoint::GEOCODER, |
|
40 | + 'method' => 'POST', |
|
41 | + 'body' => $body, |
|
42 | + 'HTTPHEADER' => 'Content-Type: multipart/form-data' |
|
43 | + )); |
|
44 | + |
|
45 | + return $fgCoding; |
|
46 | + } |
|
47 | 47 | |
48 | - public static function reverseGeocoding($params) |
|
49 | - { |
|
50 | - $query = array( |
|
51 | - 'format' => isset($params['format']) ? $params['format']: null, |
|
52 | - 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
|
53 | - 'detailed' => isset($params['detailed']) ? $params['detailed'] : null, |
|
54 | - ); |
|
48 | + public static function reverseGeocoding($params) |
|
49 | + { |
|
50 | + $query = array( |
|
51 | + 'format' => isset($params['format']) ? $params['format']: null, |
|
52 | + 'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
|
53 | + 'detailed' => isset($params['detailed']) ? $params['detailed'] : null, |
|
54 | + ); |
|
55 | 55 | |
56 | - $fgcoding = Route4Me::makeRequst(array( |
|
57 | - 'url' => Endpoint::GEOCODER, |
|
58 | - 'method' => 'POST', |
|
59 | - 'query' => $query |
|
60 | - )); |
|
61 | - |
|
62 | - return $fgcoding; |
|
63 | - } |
|
56 | + $fgcoding = Route4Me::makeRequst(array( |
|
57 | + 'url' => Endpoint::GEOCODER, |
|
58 | + 'method' => 'POST', |
|
59 | + 'query' => $query |
|
60 | + )); |
|
61 | + |
|
62 | + return $fgcoding; |
|
63 | + } |
|
64 | 64 | |
65 | - public static function getStreetData($params) |
|
66 | - { |
|
67 | - $url_query = Endpoint::STREET_DATA; |
|
65 | + public static function getStreetData($params) |
|
66 | + { |
|
67 | + $url_query = Endpoint::STREET_DATA; |
|
68 | 68 | |
69 | - if (isset($params['pk'])) { |
|
70 | - $url_query.=$params['pk'].'/'; |
|
71 | - } |
|
69 | + if (isset($params['pk'])) { |
|
70 | + $url_query.=$params['pk'].'/'; |
|
71 | + } |
|
72 | 72 | |
73 | - if (isset($params['offset'])) { |
|
74 | - $url_query.=$params['offset'].'/'; |
|
75 | - } |
|
73 | + if (isset($params['offset'])) { |
|
74 | + $url_query.=$params['offset'].'/'; |
|
75 | + } |
|
76 | 76 | |
77 | - if (isset($params['limit'])) { |
|
78 | - $url_query.=$params['limit'].'/'; |
|
79 | - } |
|
77 | + if (isset($params['limit'])) { |
|
78 | + $url_query.=$params['limit'].'/'; |
|
79 | + } |
|
80 | 80 | |
81 | - $query = array(); |
|
81 | + $query = array(); |
|
82 | 82 | |
83 | - $response = Route4Me::makeUrlRequst($url_query, array( |
|
84 | - 'method' => 'GET', |
|
85 | - 'query' => $query |
|
86 | - )); |
|
83 | + $response = Route4Me::makeUrlRequst($url_query, array( |
|
84 | + 'method' => 'GET', |
|
85 | + 'query' => $query |
|
86 | + )); |
|
87 | 87 | |
88 | - return $response; |
|
89 | - } |
|
88 | + return $response; |
|
89 | + } |
|
90 | 90 | |
91 | - public static function getZipCode($params) |
|
92 | - { |
|
93 | - $url_query = Endpoint::STREET_DATA_ZIPCODE; |
|
91 | + public static function getZipCode($params) |
|
92 | + { |
|
93 | + $url_query = Endpoint::STREET_DATA_ZIPCODE; |
|
94 | 94 | |
95 | - if (isset($params['zipcode'])) { |
|
96 | - $url_query.=$params['zipcode'].'/'; |
|
97 | - } |
|
95 | + if (isset($params['zipcode'])) { |
|
96 | + $url_query.=$params['zipcode'].'/'; |
|
97 | + } |
|
98 | 98 | |
99 | - if (isset($params['offset'])) { |
|
100 | - $url_query.=$params['offset'].'/'; |
|
101 | - } |
|
99 | + if (isset($params['offset'])) { |
|
100 | + $url_query.=$params['offset'].'/'; |
|
101 | + } |
|
102 | 102 | |
103 | - if (isset($params['limit'])) { |
|
104 | - $url_query.=$params['limit'].'/'; |
|
105 | - } |
|
103 | + if (isset($params['limit'])) { |
|
104 | + $url_query.=$params['limit'].'/'; |
|
105 | + } |
|
106 | 106 | |
107 | - $query = array(); |
|
107 | + $query = array(); |
|
108 | 108 | |
109 | - $response = Route4Me::makeUrlRequst($url_query, array( |
|
110 | - 'method' => 'GET', |
|
111 | - 'query' => $query |
|
112 | - )); |
|
109 | + $response = Route4Me::makeUrlRequst($url_query, array( |
|
110 | + 'method' => 'GET', |
|
111 | + 'query' => $query |
|
112 | + )); |
|
113 | 113 | |
114 | - return $response; |
|
115 | - } |
|
114 | + return $response; |
|
115 | + } |
|
116 | 116 | |
117 | - public static function getService($params) |
|
118 | - { |
|
119 | - $url_query = Endpoint::STREET_DATA_SERVICE; |
|
117 | + public static function getService($params) |
|
118 | + { |
|
119 | + $url_query = Endpoint::STREET_DATA_SERVICE; |
|
120 | 120 | |
121 | - if (isset($params['zipcode'])) { |
|
122 | - $url_query.=$params['zipcode'].'/'; |
|
123 | - } |
|
121 | + if (isset($params['zipcode'])) { |
|
122 | + $url_query.=$params['zipcode'].'/'; |
|
123 | + } |
|
124 | 124 | |
125 | - if (isset($params['housenumber'])) { |
|
126 | - $url_query.=$params['housenumber'].'/'; |
|
127 | - } |
|
125 | + if (isset($params['housenumber'])) { |
|
126 | + $url_query.=$params['housenumber'].'/'; |
|
127 | + } |
|
128 | 128 | |
129 | - if (isset($params['offset'])) { |
|
130 | - $url_query.=$params['offset'].'/'; |
|
131 | - } |
|
129 | + if (isset($params['offset'])) { |
|
130 | + $url_query.=$params['offset'].'/'; |
|
131 | + } |
|
132 | 132 | |
133 | - if (isset($params['limit'])) { |
|
134 | - $url_query.=$params['limit'].'/'; |
|
135 | - } |
|
133 | + if (isset($params['limit'])) { |
|
134 | + $url_query.=$params['limit'].'/'; |
|
135 | + } |
|
136 | 136 | |
137 | - $query = array(); |
|
137 | + $query = array(); |
|
138 | 138 | |
139 | - $response = Route4Me::makeUrlRequst($url_query, array( |
|
140 | - 'method' => 'GET', |
|
141 | - 'query' => $query |
|
142 | - )); |
|
139 | + $response = Route4Me::makeUrlRequst($url_query, array( |
|
140 | + 'method' => 'GET', |
|
141 | + 'query' => $query |
|
142 | + )); |
|
143 | 143 | |
144 | - return $response; |
|
145 | - } |
|
144 | + return $response; |
|
145 | + } |
|
146 | 146 | } |
@@ -6,88 +6,88 @@ |
||
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 get($params) |
|
46 | - { |
|
47 | - $activity = Route4Me::makeRequst(array( |
|
48 | - 'url' => Endpoint::GET_ACTIVITIES, |
|
49 | - 'method' => 'GET', |
|
50 | - 'query' => array( |
|
51 | - 'route_id' => isset($params->route_id) ? $params->route_id : null, |
|
52 | - 'team' => isset($params->team) ? $params->team : null, |
|
53 | - 'limit' => isset($params->limit) ? $params->limit : null, |
|
54 | - 'offset' => isset($params->offset) ? $params->offset : null, |
|
55 | - 'start' => isset($params->start) ? $params->start : null, |
|
56 | - ) |
|
57 | - )); |
|
45 | + public static function get($params) |
|
46 | + { |
|
47 | + $activity = Route4Me::makeRequst(array( |
|
48 | + 'url' => Endpoint::GET_ACTIVITIES, |
|
49 | + 'method' => 'GET', |
|
50 | + 'query' => array( |
|
51 | + 'route_id' => isset($params->route_id) ? $params->route_id : null, |
|
52 | + 'team' => isset($params->team) ? $params->team : null, |
|
53 | + 'limit' => isset($params->limit) ? $params->limit : null, |
|
54 | + 'offset' => isset($params->offset) ? $params->offset : null, |
|
55 | + 'start' => isset($params->start) ? $params->start : null, |
|
56 | + ) |
|
57 | + )); |
|
58 | 58 | |
59 | - return $activity; |
|
60 | - } |
|
59 | + return $activity; |
|
60 | + } |
|
61 | 61 | |
62 | - public static function searcActivities($params) |
|
63 | - { |
|
64 | - $activity = Route4Me::makeRequst(array( |
|
65 | - 'url' => Endpoint::GET_ACTIVITIES, |
|
66 | - 'method' => 'GET', |
|
67 | - 'query' => array( |
|
68 | - 'route_id' => isset($params->route_id) ? $params->route_id : null, |
|
69 | - 'limit' => isset($params->limit) ? $params->limit : null, |
|
70 | - 'offset' => isset($params->offset) ? $params->offset : null, |
|
71 | - 'activity_type' => isset($params->activity_type) ? $params->activity_type : null, |
|
72 | - ) |
|
73 | - )); |
|
62 | + public static function searcActivities($params) |
|
63 | + { |
|
64 | + $activity = Route4Me::makeRequst(array( |
|
65 | + 'url' => Endpoint::GET_ACTIVITIES, |
|
66 | + 'method' => 'GET', |
|
67 | + 'query' => array( |
|
68 | + 'route_id' => isset($params->route_id) ? $params->route_id : null, |
|
69 | + 'limit' => isset($params->limit) ? $params->limit : null, |
|
70 | + 'offset' => isset($params->offset) ? $params->offset : null, |
|
71 | + 'activity_type' => isset($params->activity_type) ? $params->activity_type : null, |
|
72 | + ) |
|
73 | + )); |
|
74 | 74 | |
75 | - return $activity; |
|
76 | - } |
|
75 | + return $activity; |
|
76 | + } |
|
77 | 77 | |
78 | - public static function sendUserMessage($postParameters) |
|
79 | - { |
|
80 | - $result = Route4Me::makeRequst(array( |
|
81 | - 'url' => Endpoint::ACTIVITY_FEED, |
|
82 | - 'method' => 'POST', |
|
83 | - 'body' => array( |
|
84 | - 'activity_type' => isset($postParameters->activity_type) ? $postParameters->activity_type : null, |
|
85 | - 'activity_message' => isset($postParameters->activity_message) ? $postParameters->activity_message : null, |
|
86 | - 'route_id' => isset($postParameters->route_id) ? $postParameters->route_id : null, |
|
87 | - ) |
|
88 | - )); |
|
78 | + public static function sendUserMessage($postParameters) |
|
79 | + { |
|
80 | + $result = Route4Me::makeRequst(array( |
|
81 | + 'url' => Endpoint::ACTIVITY_FEED, |
|
82 | + 'method' => 'POST', |
|
83 | + 'body' => array( |
|
84 | + 'activity_type' => isset($postParameters->activity_type) ? $postParameters->activity_type : null, |
|
85 | + 'activity_message' => isset($postParameters->activity_message) ? $postParameters->activity_message : null, |
|
86 | + 'route_id' => isset($postParameters->route_id) ? $postParameters->route_id : null, |
|
87 | + ) |
|
88 | + )); |
|
89 | 89 | |
90 | - return $result; |
|
91 | - } |
|
90 | + return $result; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
@@ -97,19 +97,19 @@ |
||
97 | 97 | |
98 | 98 | public function updateTerritory($params) |
99 | 99 | { |
100 | - //var_dump($params); die(""); |
|
100 | + //var_dump($params); die(""); |
|
101 | 101 | $response = Route4Me::makeRequst(array( |
102 | 102 | 'url' => Endpoint::TERRITORY_V4, |
103 | 103 | 'method' => 'PUT', |
104 | 104 | 'query' => array( |
105 | - 'territory_id' => isset($params->territory_id) ? $params->territory_id : null |
|
106 | - ), |
|
107 | - 'body' => array( |
|
108 | - 'territory_name' => isset($params->territory_name) ? $params->territory_name : null, |
|
109 | - 'member_id' => isset($params->member_id) ? $params->member_id : null, |
|
110 | - 'territory_color' => isset($params->territory_color) ? $params->territory_color : null, |
|
111 | - 'territory' => isset($params->territory) ? $params->territory : null |
|
112 | - ) |
|
105 | + 'territory_id' => isset($params->territory_id) ? $params->territory_id : null |
|
106 | + ), |
|
107 | + 'body' => array( |
|
108 | + 'territory_name' => isset($params->territory_name) ? $params->territory_name : null, |
|
109 | + 'member_id' => isset($params->member_id) ? $params->member_id : null, |
|
110 | + 'territory_color' => isset($params->territory_color) ? $params->territory_color : null, |
|
111 | + 'territory' => isset($params->territory) ? $params->territory : null |
|
112 | + ) |
|
113 | 113 | |
114 | 114 | )); |
115 | 115 |
@@ -7,341 +7,341 @@ |
||
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 fileUploadRequest($options) { |
|
34 | - $query = isset($options['query']) ? |
|
35 | - array_filter($options['query']) : array(); |
|
33 | + public static function fileUploadRequest($options) { |
|
34 | + $query = isset($options['query']) ? |
|
35 | + array_filter($options['query']) : array(); |
|
36 | 36 | |
37 | - if (sizeof($query)==0) return null; |
|
37 | + if (sizeof($query)==0) return null; |
|
38 | 38 | |
39 | - $body = isset($options['body']) ? |
|
40 | - array_filter($options['body']) : null; |
|
39 | + $body = isset($options['body']) ? |
|
40 | + array_filter($options['body']) : null; |
|
41 | 41 | |
42 | - $fname = isset($body['strFilename']) ? $body['strFilename'] : ''; |
|
43 | - if ($fname=='') return null; |
|
42 | + $fname = isset($body['strFilename']) ? $body['strFilename'] : ''; |
|
43 | + if ($fname=='') return null; |
|
44 | 44 | |
45 | - $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fname)) : '@'.realpath($fname); |
|
45 | + $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fname)) : '@'.realpath($fname); |
|
46 | 46 | |
47 | - $url = self::$baseUrl.$options['url'] . '?' . http_build_query(array_merge( |
|
48 | - array( 'api_key' => self::getApiKey()), $query) |
|
49 | - ); |
|
47 | + $url = self::$baseUrl.$options['url'] . '?' . http_build_query(array_merge( |
|
48 | + array( 'api_key' => self::getApiKey()), $query) |
|
49 | + ); |
|
50 | 50 | |
51 | - $ch = curl_init($url); |
|
51 | + $ch = curl_init($url); |
|
52 | 52 | |
53 | - $curlOpts = array( |
|
54 | - CURLOPT_POST => true, |
|
55 | - CURLOPT_RETURNTRANSFER => false, |
|
56 | - CURLOPT_TIMEOUT => 60, |
|
57 | - CURLOPT_FOLLOWLOCATION => true, |
|
58 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
59 | - CURLOPT_SSL_VERIFYPEER => FALSE |
|
60 | - ); |
|
53 | + $curlOpts = array( |
|
54 | + CURLOPT_POST => true, |
|
55 | + CURLOPT_RETURNTRANSFER => false, |
|
56 | + CURLOPT_TIMEOUT => 60, |
|
57 | + CURLOPT_FOLLOWLOCATION => true, |
|
58 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
59 | + CURLOPT_SSL_VERIFYPEER => FALSE |
|
60 | + ); |
|
61 | 61 | |
62 | - curl_setopt_array($ch, $curlOpts); |
|
62 | + curl_setopt_array($ch, $curlOpts); |
|
63 | 63 | |
64 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
64 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
65 | 65 | |
66 | - curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
67 | - "Content-Type: multipart/form-data", |
|
68 | - 'Content-Disposition: form-data; name="strFilename"' |
|
69 | - )); |
|
70 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
71 | - curl_setopt($ch, CURLOPT_POSTFIELDS, array('strFilename' => $rpath)); |
|
66 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
67 | + "Content-Type: multipart/form-data", |
|
68 | + 'Content-Disposition: form-data; name="strFilename"' |
|
69 | + )); |
|
70 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
71 | + curl_setopt($ch, CURLOPT_POSTFIELDS, array('strFilename' => $rpath)); |
|
72 | 72 | |
73 | - $result = curl_exec($ch); |
|
73 | + $result = curl_exec($ch); |
|
74 | 74 | |
75 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
76 | - curl_close($ch); |
|
75 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
76 | + curl_close($ch); |
|
77 | 77 | |
78 | - $json = json_decode($result, true); |
|
78 | + $json = json_decode($result, true); |
|
79 | 79 | |
80 | - if (200 == $code) { |
|
81 | - return $json; |
|
82 | - } elseif (isset($json['errors'])) { |
|
83 | - throw new ApiError(implode(', ', $json['errors'])); |
|
84 | - } else { |
|
85 | - throw new ApiError('Something wrong'); |
|
86 | - } |
|
87 | - } |
|
80 | + if (200 == $code) { |
|
81 | + return $json; |
|
82 | + } elseif (isset($json['errors'])) { |
|
83 | + throw new ApiError(implode(', ', $json['errors'])); |
|
84 | + } else { |
|
85 | + throw new ApiError('Something wrong'); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - public static function makeRequst($options) { |
|
90 | - $errorHandler = new myErrorHandler(); |
|
89 | + public static function makeRequst($options) { |
|
90 | + $errorHandler = new myErrorHandler(); |
|
91 | 91 | |
92 | - $old_error_handler = set_error_handler(array( $errorHandler, "proc_error")); |
|
93 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
94 | - $query = isset($options['query']) ? |
|
95 | - array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
92 | + $old_error_handler = set_error_handler(array( $errorHandler, "proc_error")); |
|
93 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
94 | + $query = isset($options['query']) ? |
|
95 | + array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
96 | 96 | |
97 | - $body = isset($options['body']) ? $options['body'] : null; |
|
98 | - $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
99 | - $headers = array( |
|
100 | - "User-Agent: Route4Me php-sdk" |
|
101 | - ); |
|
97 | + $body = isset($options['body']) ? $options['body'] : null; |
|
98 | + $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
99 | + $headers = array( |
|
100 | + "User-Agent: Route4Me php-sdk" |
|
101 | + ); |
|
102 | 102 | |
103 | - if (isset($options['HTTPHEADER'])) { |
|
104 | - $headers[]=$options['HTTPHEADER']; |
|
105 | - } |
|
103 | + if (isset($options['HTTPHEADER'])) { |
|
104 | + $headers[]=$options['HTTPHEADER']; |
|
105 | + } |
|
106 | 106 | |
107 | - if (isset($options['HTTPHEADERS'])) { |
|
108 | - foreach ($options['HTTPHEADERS'] As $header) $headers[]=$header; |
|
109 | - } |
|
107 | + if (isset($options['HTTPHEADERS'])) { |
|
108 | + foreach ($options['HTTPHEADERS'] As $header) $headers[]=$header; |
|
109 | + } |
|
110 | 110 | |
111 | - $ch = curl_init(); |
|
112 | - $url = $options['url'] . '?' . http_build_query(array_merge( |
|
113 | - $query, array( 'api_key' => self::getApiKey()) |
|
114 | - )); |
|
111 | + $ch = curl_init(); |
|
112 | + $url = $options['url'] . '?' . http_build_query(array_merge( |
|
113 | + $query, array( 'api_key' => self::getApiKey()) |
|
114 | + )); |
|
115 | 115 | |
116 | - $baseUrl=self::getBaseUrl(); |
|
116 | + $baseUrl=self::getBaseUrl(); |
|
117 | 117 | |
118 | - $curlOpts = arraY( |
|
119 | - CURLOPT_URL => $baseUrl. $url, |
|
120 | - CURLOPT_RETURNTRANSFER => true, |
|
121 | - CURLOPT_TIMEOUT => 80, |
|
122 | - CURLOPT_FOLLOWLOCATION => true, |
|
123 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
124 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
125 | - CURLOPT_HTTPHEADER => $headers |
|
126 | - ); |
|
118 | + $curlOpts = arraY( |
|
119 | + CURLOPT_URL => $baseUrl. $url, |
|
120 | + CURLOPT_RETURNTRANSFER => true, |
|
121 | + CURLOPT_TIMEOUT => 80, |
|
122 | + CURLOPT_FOLLOWLOCATION => true, |
|
123 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
124 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
125 | + CURLOPT_HTTPHEADER => $headers |
|
126 | + ); |
|
127 | 127 | |
128 | - curl_setopt_array($ch, $curlOpts); |
|
128 | + curl_setopt_array($ch, $curlOpts); |
|
129 | 129 | |
130 | - if ($file !=null) { |
|
131 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
132 | - $fp=fopen($file,'r'); |
|
133 | - curl_setopt($ch, CURLOPT_INFILE , $fp); |
|
134 | - curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
135 | - } |
|
130 | + if ($file !=null) { |
|
131 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
132 | + $fp=fopen($file,'r'); |
|
133 | + curl_setopt($ch, CURLOPT_INFILE , $fp); |
|
134 | + curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
135 | + } |
|
136 | 136 | |
137 | - switch($method) { |
|
138 | - case 'DELETE': |
|
139 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
137 | + switch($method) { |
|
138 | + case 'DELETE': |
|
139 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
140 | 140 | |
141 | - if (isset($body)) { |
|
141 | + if (isset($body)) { |
|
142 | 142 | |
143 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
144 | - } |
|
145 | - break; |
|
146 | - case 'DELETEARRAY': |
|
147 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
148 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
149 | - break; |
|
150 | - case 'PUT': |
|
151 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
143 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
144 | + } |
|
145 | + break; |
|
146 | + case 'DELETEARRAY': |
|
147 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
148 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
149 | + break; |
|
150 | + case 'PUT': |
|
151 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
152 | 152 | |
153 | - if (isset($body)) { |
|
154 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
155 | - } |
|
156 | - break; |
|
157 | - case 'POST': |
|
158 | - if (isset($body)) { |
|
159 | - $bodyData = json_encode($body); |
|
160 | - if (isset($options['HTTPHEADER'])) { |
|
161 | - if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) $bodyData = $body; |
|
162 | - } |
|
153 | + if (isset($body)) { |
|
154 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
155 | + } |
|
156 | + break; |
|
157 | + case 'POST': |
|
158 | + if (isset($body)) { |
|
159 | + $bodyData = json_encode($body); |
|
160 | + if (isset($options['HTTPHEADER'])) { |
|
161 | + if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) $bodyData = $body; |
|
162 | + } |
|
163 | 163 | |
164 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
165 | - } |
|
166 | - break; |
|
167 | - case 'ADD': |
|
168 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
169 | - } |
|
164 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
165 | + } |
|
166 | + break; |
|
167 | + case 'ADD': |
|
168 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
169 | + } |
|
170 | 170 | |
171 | - $result = curl_exec($ch); |
|
171 | + $result = curl_exec($ch); |
|
172 | 172 | |
173 | - $isxml=FALSE; |
|
174 | - $jxml=""; |
|
175 | - if (strpos($result, '<?xml')>-1) |
|
176 | - { |
|
177 | - $xml = simplexml_load_string($result); |
|
178 | - //$jxml = json_encode($xml); |
|
179 | - $jxml=self::object2array($xml); |
|
180 | - $isxml = TRUE; |
|
181 | - } |
|
173 | + $isxml=FALSE; |
|
174 | + $jxml=""; |
|
175 | + if (strpos($result, '<?xml')>-1) |
|
176 | + { |
|
177 | + $xml = simplexml_load_string($result); |
|
178 | + //$jxml = json_encode($xml); |
|
179 | + $jxml=self::object2array($xml); |
|
180 | + $isxml = TRUE; |
|
181 | + } |
|
182 | 182 | |
183 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
184 | - curl_close($ch); |
|
183 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
184 | + curl_close($ch); |
|
185 | 185 | |
186 | - if (200 == $code) { |
|
187 | - if ($isxml) { |
|
188 | - $json = $jxml; |
|
189 | - } else $json = json_decode($result, true); |
|
186 | + if (200 == $code) { |
|
187 | + if ($isxml) { |
|
188 | + $json = $jxml; |
|
189 | + } else $json = json_decode($result, true); |
|
190 | 190 | |
191 | - if (isset($json['errors'])) { |
|
192 | - throw new ApiError(implode(', ', $json['errors'])); |
|
193 | - } else { |
|
194 | - return $json; |
|
195 | - } |
|
196 | - } elseif (409 == $code) { |
|
197 | - throw new ApiError('Wrong API key'); |
|
198 | - } else { |
|
199 | - throw new ApiError('Something wrong'); |
|
200 | - } |
|
201 | - } |
|
191 | + if (isset($json['errors'])) { |
|
192 | + throw new ApiError(implode(', ', $json['errors'])); |
|
193 | + } else { |
|
194 | + return $json; |
|
195 | + } |
|
196 | + } elseif (409 == $code) { |
|
197 | + throw new ApiError('Wrong API key'); |
|
198 | + } else { |
|
199 | + throw new ApiError('Something wrong'); |
|
200 | + } |
|
201 | + } |
|
202 | 202 | |
203 | - public static function object2array($object) |
|
204 | - { |
|
205 | - return @json_decode(@json_encode($object),1); |
|
206 | - } |
|
203 | + public static function object2array($object) |
|
204 | + { |
|
205 | + return @json_decode(@json_encode($object),1); |
|
206 | + } |
|
207 | 207 | |
208 | - public static function makeUrlRequst($url, $options) { |
|
209 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
210 | - $query = isset($options['query']) ? |
|
211 | - array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
212 | - $body = isset($options['body']) ? $options['body'] : null; |
|
213 | - $ch = curl_init(); |
|
208 | + public static function makeUrlRequst($url, $options) { |
|
209 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
210 | + $query = isset($options['query']) ? |
|
211 | + array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
212 | + $body = isset($options['body']) ? $options['body'] : null; |
|
213 | + $ch = curl_init(); |
|
214 | 214 | |
215 | - $curlOpts = arraY( |
|
216 | - CURLOPT_URL => $url, |
|
217 | - CURLOPT_RETURNTRANSFER => true, |
|
218 | - CURLOPT_TIMEOUT => 60, |
|
219 | - CURLOPT_FOLLOWLOCATION => true, |
|
220 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
221 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
222 | - CURLOPT_HTTPHEADER => array( |
|
223 | - 'User-Agent' => 'Route4Me php-sdk' |
|
224 | - ) |
|
225 | - ); |
|
215 | + $curlOpts = arraY( |
|
216 | + CURLOPT_URL => $url, |
|
217 | + CURLOPT_RETURNTRANSFER => true, |
|
218 | + CURLOPT_TIMEOUT => 60, |
|
219 | + CURLOPT_FOLLOWLOCATION => true, |
|
220 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
221 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
222 | + CURLOPT_HTTPHEADER => array( |
|
223 | + 'User-Agent' => 'Route4Me php-sdk' |
|
224 | + ) |
|
225 | + ); |
|
226 | 226 | |
227 | - curl_setopt_array($ch, $curlOpts); |
|
227 | + curl_setopt_array($ch, $curlOpts); |
|
228 | 228 | |
229 | - switch($method) { |
|
230 | - case 'DELETE': |
|
231 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
229 | + switch($method) { |
|
230 | + case 'DELETE': |
|
231 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
232 | 232 | |
233 | - if (isset($body)) { |
|
234 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
235 | - } |
|
236 | - break; |
|
237 | - case 'DELETEARRAY': |
|
238 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
239 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
240 | - break; |
|
241 | - case 'PUT': |
|
242 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
243 | - if (isset($query)) { |
|
244 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
245 | - } |
|
233 | + if (isset($body)) { |
|
234 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
235 | + } |
|
236 | + break; |
|
237 | + case 'DELETEARRAY': |
|
238 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
239 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
240 | + break; |
|
241 | + case 'PUT': |
|
242 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
243 | + if (isset($query)) { |
|
244 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
245 | + } |
|
246 | 246 | |
247 | - if (isset($body)) { |
|
248 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
249 | - } |
|
250 | - break; |
|
251 | - case 'POST': |
|
252 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
253 | - if (isset($query)) { |
|
254 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
255 | - } |
|
247 | + if (isset($body)) { |
|
248 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
249 | + } |
|
250 | + break; |
|
251 | + case 'POST': |
|
252 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
253 | + if (isset($query)) { |
|
254 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
255 | + } |
|
256 | 256 | |
257 | - if (isset($body)) { |
|
258 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
259 | - } |
|
260 | - break; |
|
261 | - case 'ADD': |
|
262 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
263 | - } |
|
257 | + if (isset($body)) { |
|
258 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
259 | + } |
|
260 | + break; |
|
261 | + case 'ADD': |
|
262 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
263 | + } |
|
264 | 264 | |
265 | - $result = curl_exec($ch); |
|
265 | + $result = curl_exec($ch); |
|
266 | 266 | |
267 | - $isxml=FALSE; |
|
268 | - $jxml=""; |
|
269 | - if (strpos($result, '<?xml')>-1) |
|
270 | - { |
|
271 | - $xml = simplexml_load_string($result); |
|
272 | - $jxml = json_encode($xml); |
|
273 | - $isxml = TRUE; |
|
274 | - } |
|
267 | + $isxml=FALSE; |
|
268 | + $jxml=""; |
|
269 | + if (strpos($result, '<?xml')>-1) |
|
270 | + { |
|
271 | + $xml = simplexml_load_string($result); |
|
272 | + $jxml = json_encode($xml); |
|
273 | + $isxml = TRUE; |
|
274 | + } |
|
275 | 275 | |
276 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
277 | - curl_close($ch); |
|
276 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
277 | + curl_close($ch); |
|
278 | 278 | |
279 | - if ($isxml) { |
|
280 | - $json = $jxml; |
|
281 | - } else $json = json_decode($result, true); |
|
279 | + if ($isxml) { |
|
280 | + $json = $jxml; |
|
281 | + } else $json = json_decode($result, true); |
|
282 | 282 | |
283 | - if (200 == $code) { |
|
284 | - return $json; |
|
285 | - } elseif (isset($json['errors'])) { |
|
286 | - throw new ApiError(implode(', ', $json['errors'])); |
|
287 | - } else { |
|
288 | - throw new ApiError('Something wrong'); |
|
289 | - } |
|
290 | - } |
|
283 | + if (200 == $code) { |
|
284 | + return $json; |
|
285 | + } elseif (isset($json['errors'])) { |
|
286 | + throw new ApiError(implode(', ', $json['errors'])); |
|
287 | + } else { |
|
288 | + throw new ApiError('Something wrong'); |
|
289 | + } |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * Prints on the screen main keys and values of the array |
|
294 | - * |
|
295 | - */ |
|
296 | - public static function simplePrint($results, $deepPrinting=null) |
|
297 | - { |
|
298 | - if (isset($results)) { |
|
299 | - if (is_array($results)) { |
|
300 | - foreach ($results as $key=>$result) { |
|
301 | - if (is_array($result)) { |
|
302 | - foreach ($result as $key1=>$result1) { |
|
303 | - if (is_array($result1)) { |
|
304 | - if ($deepPrinting) { |
|
305 | - echo "<br>$key1 ------><br>"; |
|
306 | - Route4Me::simplePrint($result1,true); |
|
307 | - echo "------<br>"; |
|
308 | - } else { |
|
309 | - echo $key1." --> "."Array() <br>"; |
|
310 | - } |
|
311 | - } else { |
|
312 | - if (is_object($result1)) { |
|
313 | - if ($deepPrinting) { |
|
314 | - echo "<br>$key1 ------><br>"; |
|
315 | - $oarray=(array)$result1; |
|
316 | - Route4Me::simplePrint($oarray,true); |
|
317 | - echo "------<br>"; |
|
318 | - } else { |
|
319 | - echo $key1." --> "."Object <br>"; |
|
320 | - } |
|
321 | - } else { |
|
322 | - if (!is_null($result1)) echo $key1." --> ".$result1."<br>"; |
|
323 | - } |
|
324 | - } |
|
325 | - } |
|
326 | - } else { |
|
327 | - if (is_object($result)) { |
|
328 | - if ($deepPrinting) { |
|
329 | - echo "<br>$key ------><br>"; |
|
330 | - $oarray=(array)$result; |
|
331 | - Route4Me::simplePrint($oarray,true); |
|
332 | - echo "------<br>"; |
|
333 | - } else { |
|
334 | - echo $key." --> "."Object <br>"; |
|
335 | - } |
|
336 | - } else { |
|
337 | - if (!is_null($result)) echo $key." --> ".$result."<br>"; |
|
338 | - } |
|
292 | + /** |
|
293 | + * Prints on the screen main keys and values of the array |
|
294 | + * |
|
295 | + */ |
|
296 | + public static function simplePrint($results, $deepPrinting=null) |
|
297 | + { |
|
298 | + if (isset($results)) { |
|
299 | + if (is_array($results)) { |
|
300 | + foreach ($results as $key=>$result) { |
|
301 | + if (is_array($result)) { |
|
302 | + foreach ($result as $key1=>$result1) { |
|
303 | + if (is_array($result1)) { |
|
304 | + if ($deepPrinting) { |
|
305 | + echo "<br>$key1 ------><br>"; |
|
306 | + Route4Me::simplePrint($result1,true); |
|
307 | + echo "------<br>"; |
|
308 | + } else { |
|
309 | + echo $key1." --> "."Array() <br>"; |
|
310 | + } |
|
311 | + } else { |
|
312 | + if (is_object($result1)) { |
|
313 | + if ($deepPrinting) { |
|
314 | + echo "<br>$key1 ------><br>"; |
|
315 | + $oarray=(array)$result1; |
|
316 | + Route4Me::simplePrint($oarray,true); |
|
317 | + echo "------<br>"; |
|
318 | + } else { |
|
319 | + echo $key1." --> "."Object <br>"; |
|
320 | + } |
|
321 | + } else { |
|
322 | + if (!is_null($result1)) echo $key1." --> ".$result1."<br>"; |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | + } else { |
|
327 | + if (is_object($result)) { |
|
328 | + if ($deepPrinting) { |
|
329 | + echo "<br>$key ------><br>"; |
|
330 | + $oarray=(array)$result; |
|
331 | + Route4Me::simplePrint($oarray,true); |
|
332 | + echo "------<br>"; |
|
333 | + } else { |
|
334 | + echo $key." --> "."Object <br>"; |
|
335 | + } |
|
336 | + } else { |
|
337 | + if (!is_null($result)) echo $key." --> ".$result."<br>"; |
|
338 | + } |
|
339 | 339 | |
340 | - } |
|
341 | - //echo "<br>"; |
|
342 | - } |
|
343 | - } |
|
344 | - } |
|
345 | - } |
|
340 | + } |
|
341 | + //echo "<br>"; |
|
342 | + } |
|
343 | + } |
|
344 | + } |
|
345 | + } |
|
346 | 346 | |
347 | 347 | } |