@@ -15,10 +15,10 @@ |
||
15 | 15 | Route4Me::setApiKey(Constants::API_KEY); |
16 | 16 | |
17 | 17 | try { |
18 | - $schedules = new Schedules(); |
|
18 | + $schedules = new Schedules(); |
|
19 | 19 | |
20 | - $res = $schedules->isScheduledRouteCopy('66C2AC4A323053FF0A40FEB6918ACF5E'); |
|
21 | - echo var_export($res) . PHP_EOL; |
|
20 | + $res = $schedules->isScheduledRouteCopy('66C2AC4A323053FF0A40FEB6918ACF5E'); |
|
21 | + echo var_export($res) . PHP_EOL; |
|
22 | 22 | } catch (\Exception $e) { |
23 | - echo $e->getMessage() . PHP_EOL; |
|
23 | + echo $e->getMessage() . PHP_EOL; |
|
24 | 24 | } |
@@ -15,13 +15,13 @@ |
||
15 | 15 | Route4Me::setApiKey(Constants::API_KEY); |
16 | 16 | |
17 | 17 | try { |
18 | - $schedules = new Schedules(); |
|
19 | - $route_id = '66C2AC4A323053FF0A40FEB6918ACF5E'; |
|
20 | - $start = '2022-01-01'; |
|
21 | - $end = '2023-12-31'; |
|
18 | + $schedules = new Schedules(); |
|
19 | + $route_id = '66C2AC4A323053FF0A40FEB6918ACF5E'; |
|
20 | + $start = '2022-01-01'; |
|
21 | + $end = '2023-12-31'; |
|
22 | 22 | |
23 | - $schedule = $schedules->getRouteSchedulePreview($route_id, $start, $end); |
|
24 | - print_r($schedule); |
|
23 | + $schedule = $schedules->getRouteSchedulePreview($route_id, $start, $end); |
|
24 | + print_r($schedule); |
|
25 | 25 | } catch (\Exception $e) { |
26 | - echo $e->getMessage() . PHP_EOL; |
|
26 | + echo $e->getMessage() . PHP_EOL; |
|
27 | 27 | } |
@@ -13,30 +13,30 @@ |
||
13 | 13 | */ |
14 | 14 | class RouteSchedule extends Common |
15 | 15 | { |
16 | - /** |
|
17 | - * The Route ID |
|
18 | - */ |
|
19 | - public ?string $route_id = null; |
|
16 | + /** |
|
17 | + * The Route ID |
|
18 | + */ |
|
19 | + public ?string $route_id = null; |
|
20 | 20 | |
21 | - /** |
|
22 | - * The Schedule ID |
|
23 | - */ |
|
24 | - public ?string $schedule_uid = null; |
|
21 | + /** |
|
22 | + * The Schedule ID |
|
23 | + */ |
|
24 | + public ?string $schedule_uid = null; |
|
25 | 25 | |
26 | - /** |
|
27 | - * The Schedule ID |
|
28 | - */ |
|
29 | - public ?int $member_id = null; |
|
26 | + /** |
|
27 | + * The Schedule ID |
|
28 | + */ |
|
29 | + public ?int $member_id = null; |
|
30 | 30 | |
31 | - /** |
|
32 | - * The Schedule ID |
|
33 | - */ |
|
34 | - public ?string $vehicle_id = null; |
|
31 | + /** |
|
32 | + * The Schedule ID |
|
33 | + */ |
|
34 | + public ?string $vehicle_id = null; |
|
35 | 35 | |
36 | - public function __construct(?array $params = null) |
|
37 | - { |
|
38 | - if ($params !== null) { |
|
39 | - $this->fillFromArray($params); |
|
40 | - } |
|
41 | - } |
|
36 | + public function __construct(?array $params = null) |
|
37 | + { |
|
38 | + if ($params !== null) { |
|
39 | + $this->fillFromArray($params); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | } |
@@ -13,72 +13,72 @@ |
||
13 | 13 | */ |
14 | 14 | class PageInfo extends Common |
15 | 15 | { |
16 | - /** |
|
17 | - * URL of first page |
|
18 | - */ |
|
19 | - public ?string $url_of_first_page = null; |
|
16 | + /** |
|
17 | + * URL of first page |
|
18 | + */ |
|
19 | + public ?string $url_of_first_page = null; |
|
20 | 20 | |
21 | - /** |
|
22 | - * URL of last page |
|
23 | - */ |
|
24 | - public ?string $url_of_last_page = null; |
|
21 | + /** |
|
22 | + * URL of last page |
|
23 | + */ |
|
24 | + public ?string $url_of_last_page = null; |
|
25 | 25 | |
26 | - /** |
|
27 | - * URL of previous page |
|
28 | - */ |
|
29 | - public ?string $url_of_previous_page = null; |
|
26 | + /** |
|
27 | + * URL of previous page |
|
28 | + */ |
|
29 | + public ?string $url_of_previous_page = null; |
|
30 | 30 | |
31 | - /** |
|
32 | - * URL of next page |
|
33 | - */ |
|
34 | - public ?string $url_of_next_page = null; |
|
31 | + /** |
|
32 | + * URL of next page |
|
33 | + */ |
|
34 | + public ?string $url_of_next_page = null; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Number of current page |
|
38 | - */ |
|
39 | - public ?int $number_of_current_page = null; |
|
36 | + /** |
|
37 | + * Number of current page |
|
38 | + */ |
|
39 | + public ?int $number_of_current_page = null; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Number of last page |
|
43 | - */ |
|
44 | - public ?int $number_of_last_page = null; |
|
41 | + /** |
|
42 | + * Number of last page |
|
43 | + */ |
|
44 | + public ?int $number_of_last_page = null; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Items per page |
|
48 | - */ |
|
49 | - public ?int $items_per_page = null; |
|
46 | + /** |
|
47 | + * Items per page |
|
48 | + */ |
|
49 | + public ?int $items_per_page = null; |
|
50 | 50 | |
51 | - /** |
|
52 | - * Index of first item on page |
|
53 | - */ |
|
54 | - public ?int $index_of_first = null; |
|
51 | + /** |
|
52 | + * Index of first item on page |
|
53 | + */ |
|
54 | + public ?int $index_of_first = null; |
|
55 | 55 | |
56 | - /** |
|
57 | - * Index of last item on page |
|
58 | - */ |
|
59 | - public ?int $index_of_last = null; |
|
56 | + /** |
|
57 | + * Index of last item on page |
|
58 | + */ |
|
59 | + public ?int $index_of_last = null; |
|
60 | 60 | |
61 | - /** |
|
62 | - * Total items |
|
63 | - */ |
|
64 | - public ?int $total_items = null; |
|
61 | + /** |
|
62 | + * Total items |
|
63 | + */ |
|
64 | + public ?int $total_items = null; |
|
65 | 65 | |
66 | - public function __construct(array $links = null, array $meta = null) |
|
67 | - { |
|
68 | - if ($links !== null && is_array($links)) { |
|
69 | - $this->url_of_first_page = Common::getValue($links, 'first'); |
|
70 | - $this->url_of_last_page = Common::getValue($links, 'last'); |
|
71 | - $this->url_of_previous_page = Common::getValue($links, 'prev'); |
|
72 | - $this->url_of_next_page = Common::getValue($links, 'next'); |
|
73 | - } |
|
66 | + public function __construct(array $links = null, array $meta = null) |
|
67 | + { |
|
68 | + if ($links !== null && is_array($links)) { |
|
69 | + $this->url_of_first_page = Common::getValue($links, 'first'); |
|
70 | + $this->url_of_last_page = Common::getValue($links, 'last'); |
|
71 | + $this->url_of_previous_page = Common::getValue($links, 'prev'); |
|
72 | + $this->url_of_next_page = Common::getValue($links, 'next'); |
|
73 | + } |
|
74 | 74 | |
75 | - if ($meta !== null && is_array($meta)) { |
|
76 | - $this->number_of_current_page = Common::getValue($meta, 'current_page'); |
|
77 | - $this->number_of_last_page = Common::getValue($meta, 'last_page'); |
|
78 | - $this->items_per_page = Common::getValue($meta, 'per_page'); |
|
79 | - $this->index_of_first = Common::getValue($meta, 'from'); |
|
80 | - $this->index_of_last = Common::getValue($meta, 'to'); |
|
81 | - $this->total_items = Common::getValue($meta, 'total'); |
|
82 | - } |
|
83 | - } |
|
75 | + if ($meta !== null && is_array($meta)) { |
|
76 | + $this->number_of_current_page = Common::getValue($meta, 'current_page'); |
|
77 | + $this->number_of_last_page = Common::getValue($meta, 'last_page'); |
|
78 | + $this->items_per_page = Common::getValue($meta, 'per_page'); |
|
79 | + $this->index_of_first = Common::getValue($meta, 'from'); |
|
80 | + $this->index_of_last = Common::getValue($meta, 'to'); |
|
81 | + $this->total_items = Common::getValue($meta, 'total'); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | } |
@@ -13,40 +13,40 @@ |
||
13 | 13 | */ |
14 | 14 | class Schedule extends Common |
15 | 15 | { |
16 | - /** |
|
17 | - * The Schedule ID |
|
18 | - */ |
|
19 | - public ?string $schedule_uid = null; |
|
20 | - |
|
21 | - /** |
|
22 | - * The name of Schedule |
|
23 | - */ |
|
24 | - public ?string $name = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Array of blacklisted dates as string 'YYYY-MM-DD'. |
|
28 | - */ |
|
29 | - public ?array $schedule_blacklist = null; |
|
30 | - |
|
31 | - public int $advance_interval = 1; |
|
32 | - |
|
33 | - public int $advance_schedule_interval_days = 0; |
|
34 | - |
|
35 | - /** |
|
36 | - * Schedule as JSON string |
|
37 | - * e.g. '{"enabled":true,"mode":"daily","daily":{"every":2}, "from":"2019-06-05","timestamp":1558538737}' |
|
38 | - */ |
|
39 | - public ?string $schedule = null; |
|
40 | - |
|
41 | - /** |
|
42 | - * Timezone as 'America/New_York'. |
|
43 | - */ |
|
44 | - public ?string $timezone = null; |
|
45 | - |
|
46 | - public function __construct(?array $params = null) |
|
47 | - { |
|
48 | - if ($params !== null) { |
|
49 | - $this->fillFromArray($params); |
|
50 | - } |
|
51 | - } |
|
16 | + /** |
|
17 | + * The Schedule ID |
|
18 | + */ |
|
19 | + public ?string $schedule_uid = null; |
|
20 | + |
|
21 | + /** |
|
22 | + * The name of Schedule |
|
23 | + */ |
|
24 | + public ?string $name = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Array of blacklisted dates as string 'YYYY-MM-DD'. |
|
28 | + */ |
|
29 | + public ?array $schedule_blacklist = null; |
|
30 | + |
|
31 | + public int $advance_interval = 1; |
|
32 | + |
|
33 | + public int $advance_schedule_interval_days = 0; |
|
34 | + |
|
35 | + /** |
|
36 | + * Schedule as JSON string |
|
37 | + * e.g. '{"enabled":true,"mode":"daily","daily":{"every":2}, "from":"2019-06-05","timestamp":1558538737}' |
|
38 | + */ |
|
39 | + public ?string $schedule = null; |
|
40 | + |
|
41 | + /** |
|
42 | + * Timezone as 'America/New_York'. |
|
43 | + */ |
|
44 | + public ?string $timezone = null; |
|
45 | + |
|
46 | + public function __construct(?array $params = null) |
|
47 | + { |
|
48 | + if ($params !== null) { |
|
49 | + $this->fillFromArray($params); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |
@@ -4,16 +4,16 @@ |
||
4 | 4 | |
5 | 5 | class ApiError extends \Exception |
6 | 6 | { |
7 | - protected string $source = ''; |
|
7 | + protected string $source = ''; |
|
8 | 8 | |
9 | - public function __construct(string $message = '', int $code = 0, string $source = '', \Throwable $previous = null) |
|
10 | - { |
|
11 | - parent::__construct($message, $code, $previous); |
|
12 | - $this->source = $source; |
|
13 | - } |
|
9 | + public function __construct(string $message = '', int $code = 0, string $source = '', \Throwable $previous = null) |
|
10 | + { |
|
11 | + parent::__construct($message, $code, $previous); |
|
12 | + $this->source = $source; |
|
13 | + } |
|
14 | 14 | |
15 | - final public function getSource() : string |
|
16 | - { |
|
17 | - return $this->source; |
|
18 | - } |
|
15 | + final public function getSource() : string |
|
16 | + { |
|
17 | + return $this->source; |
|
18 | + } |
|
19 | 19 | } |
@@ -16,279 +16,279 @@ |
||
16 | 16 | */ |
17 | 17 | class VehicleV4 extends \Route4Me\Common |
18 | 18 | { |
19 | - /** @var string $vehicle_id |
|
20 | - * Vehicle unique 32-chars ID |
|
21 | - */ |
|
22 | - public $vehicle_id; |
|
23 | - |
|
24 | - /** @var int $member_id |
|
25 | - * Member unique ID |
|
26 | - */ |
|
27 | - public $member_id; |
|
28 | - |
|
29 | - /** @var boolean $is_deleted |
|
30 | - * True, if the vehicle was deleted. |
|
31 | - */ |
|
32 | - public $is_deleted; |
|
33 | - |
|
34 | - /** @var string $vehicle_alias |
|
35 | - * Vehicle alias |
|
36 | - */ |
|
37 | - public $vehicle_alias; |
|
38 | - |
|
39 | - /** @var string $vehicle_vin |
|
40 | - * Vehicle VIN (vehicle identification number) |
|
41 | - */ |
|
42 | - public $vehicle_vin; |
|
43 | - |
|
44 | - /** @var int $vehicle_reg_state_id |
|
45 | - * The ID of a state the vehicle was registered. |
|
46 | - */ |
|
47 | - public $vehicle_reg_state_id; |
|
48 | - |
|
49 | - /** @var int $vehicle_reg_country_id |
|
50 | - * The ID of a country the vehicle was registered. |
|
51 | - */ |
|
52 | - public $vehicle_reg_country_id; |
|
53 | - |
|
54 | - /** @var string $vehicle_license_plate |
|
55 | - * A license plate of the vehicle. |
|
56 | - */ |
|
57 | - public $vehicle_license_plate; |
|
58 | - |
|
59 | - /** @var string $vehicle_type_id |
|
60 | - * Vehicle type ID. |
|
61 | - * Available values: |
|
62 | - * 'sedan', 'suv', 'pickup_truck', 'van', '18wheeler', 'cabin', 'hatchback', |
|
63 | - * 'motorcyle', 'waste_disposal', 'tree_cutting', 'bigrig', 'cement_mixer', |
|
64 | - * 'livestock_carrier', 'dairy','tractor_trailer' |
|
65 | - */ |
|
66 | - public $vehicle_type_id; |
|
67 | - |
|
68 | - /** @var string $timestamp_added |
|
69 | - * When the vehicle was added. |
|
70 | - */ |
|
71 | - public $timestamp_added; |
|
72 | - |
|
73 | - /** @var string $vehicle_make |
|
74 | - * Vehicle maker brend. |
|
75 | - * Available values: |
|
76 | - * 'american coleman', 'bmw', 'chevrolet', 'ford', 'freightliner', 'gmc', |
|
77 | - * 'hino', 'honda', 'isuzu', 'kenworth', 'mack', 'mercedes-benz', 'mitsubishi', |
|
78 | - * 'navistar', 'nissan', 'peterbilt', 'renault', 'scania', 'sterling', 'toyota', |
|
79 | - * 'volvo', 'western star' |
|
80 | - */ |
|
81 | - public $vehicle_make; |
|
82 | - |
|
83 | - /** @var int $vehicle_model_year |
|
84 | - * A year of the vehicle model. |
|
85 | - */ |
|
86 | - public $vehicle_model_year; |
|
87 | - |
|
88 | - /** @var string $vehicle_model |
|
89 | - * A model of the vehicle. |
|
90 | - */ |
|
91 | - public $vehicle_model; |
|
92 | - |
|
93 | - /** @var int $vehicle_year_acquired |
|
94 | - * A year, the vehicle was acquired. |
|
95 | - */ |
|
96 | - public $vehicle_year_acquired; |
|
97 | - |
|
98 | - /** @var string $vehicle_cost_new |
|
99 | - * A cost of the new vehicle. |
|
100 | - */ |
|
101 | - public $vehicle_cost_new; |
|
102 | - |
|
103 | - /** @var string $purchased_new |
|
104 | - * If true, the vehicle was purchased new. |
|
105 | - */ |
|
106 | - public $purchased_new; |
|
107 | - |
|
108 | - /** @var string $license_start_date |
|
109 | - * Start date of the license (e.g. '2020-12-20'). |
|
110 | - */ |
|
111 | - public $license_start_date; |
|
112 | - |
|
113 | - /** @var string $license_end_date |
|
114 | - * End date of the license (e.g. '2020-12-20'). |
|
115 | - */ |
|
116 | - public $license_end_date; |
|
117 | - |
|
118 | - /** @var boolean $is_operational |
|
119 | - * If true, the vehicle is operational. |
|
120 | - */ |
|
121 | - public $is_operational; |
|
122 | - |
|
123 | - /** @var string $fuel_type |
|
124 | - * A type of the fuel. |
|
125 | - * Available values: |
|
126 | - * 'unleaded 87', 'unleaded 89', 'unleaded 91', 'unleaded 93', 'diesel', 'electric', 'hybrid' |
|
127 | - */ |
|
128 | - public $fuel_type; |
|
129 | - |
|
130 | - /** @var string $external_telematics_vehicle_id |
|
131 | - * External telematics vehicle ID. |
|
132 | - */ |
|
133 | - public $external_telematics_vehicle_id; |
|
134 | - |
|
135 | - /** @var string $timestamp_removed |
|
136 | - * When the vehicle was removed. |
|
137 | - */ |
|
138 | - public $timestamp_removed; |
|
139 | - |
|
140 | - /** @var string $vehicle_profile_id |
|
141 | - * Vehicle profile ID |
|
142 | - */ |
|
143 | - public $vehicle_profile_id; |
|
144 | - |
|
145 | - /** @var double $fuel_consumption_city |
|
146 | - * Fuel consumption in the city area. |
|
147 | - */ |
|
148 | - public $fuel_consumption_city; |
|
149 | - |
|
150 | - /** @var double $fuel_consumption_highway |
|
151 | - * Fuel consumption in the highway area. |
|
152 | - */ |
|
153 | - public $fuel_consumption_highway; |
|
154 | - |
|
155 | - /** @var string $fuel_consumption_city_unit |
|
156 | - * Fuel consumption unit in the city area (e.g. 'mi/l'). |
|
157 | - */ |
|
158 | - public $fuel_consumption_city_unit; |
|
159 | - |
|
160 | - /** @var string $fuel_consumption_highway_unit |
|
161 | - * Fuel consumption unit in the highway area (e.g. 'mi/l'). |
|
162 | - */ |
|
163 | - public $fuel_consumption_highway_unit; |
|
164 | - |
|
165 | - /** @var double $mpg_city |
|
166 | - * Miles per gallon in the city area. |
|
167 | - */ |
|
168 | - public $mpg_city; |
|
169 | - |
|
170 | - /** @var double $mpg_highway |
|
171 | - * Miles per gallon in the highway area. |
|
172 | - */ |
|
173 | - public $mpg_highway; |
|
174 | - |
|
175 | - /** @var string $fuel_consumption_city_uf_value |
|
176 | - * Fuel consumption UF (utility factor) value in the city area. |
|
177 | - */ |
|
178 | - public $fuel_consumption_city_uf_value; |
|
179 | - |
|
180 | - /** @var string $fuel_consumption_highway_uf_value |
|
181 | - * Fuel consumption UF (utility factor) value in the highway area. |
|
182 | - */ |
|
183 | - public $fuel_consumption_highway_uf_value; |
|
184 | - |
|
185 | - public function __construct() |
|
186 | - { |
|
187 | - Route4Me::setBaseUrl(Endpoint::WH_BASE_URL); |
|
188 | - } |
|
189 | - |
|
190 | - public static function fromArray(array $params) |
|
191 | - { |
|
192 | - $vehicle = new self(); |
|
193 | - |
|
194 | - foreach ($params as $key => $value) { |
|
195 | - if (is_null(Common::getValue($params, $key))) { |
|
196 | - continue; |
|
197 | - } |
|
198 | - if (property_exists($vehicle, $key)) { |
|
199 | - $vehicle->$key = $value; |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - return $vehicle; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @deprecated 1.2.6 |
|
208 | - * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::getVehiclesPaginatedList() |
|
209 | - */ |
|
210 | - public static function getVehicles($params) |
|
211 | - { |
|
212 | - $allQueryFields = ['with_pagination', 'page', 'perPage']; |
|
213 | - |
|
214 | - $response = Route4Me::makeRequst([ |
|
215 | - 'url' => Endpoint::VEHICLE_V4, |
|
216 | - 'method' => 'GET', |
|
217 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
218 | - ]); |
|
219 | - |
|
220 | - return $response; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @deprecated 1.2.6 |
|
225 | - * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::getVehicleById() |
|
226 | - */ |
|
227 | - public function getVehicleByID($vehicleID) |
|
228 | - { |
|
229 | - $response = Route4Me::makeRequst([ |
|
230 | - 'url' => Endpoint::VEHICLE_V4.'/'.$vehicleID, |
|
231 | - 'method' => 'GET', |
|
232 | - ]); |
|
233 | - |
|
234 | - return $response; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @deprecated 1.2.6 |
|
239 | - * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::updateVehicle() |
|
240 | - */ |
|
241 | - public function updateVehicle($params) |
|
242 | - { |
|
243 | - $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
244 | - |
|
245 | - $allBodyFields = Route4Me::getObjectProperties(new self(), ['vehicle_id']); |
|
246 | - |
|
247 | - $response = Route4Me::makeRequst([ |
|
248 | - 'url' => Endpoint::VEHICLE_V4.'/'.$vehicleID, |
|
249 | - 'method' => 'PUT', |
|
250 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
251 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
252 | - ]); |
|
253 | - |
|
254 | - return $response; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * @deprecated 1.2.6 |
|
259 | - * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::createVehicle() |
|
260 | - */ |
|
261 | - public function createVehicle($params) |
|
262 | - { |
|
263 | - $excludeFields = ['vehicle_id','is_deleted','created_time','timestamp_added','timestamp_removed']; |
|
264 | - $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
265 | - |
|
266 | - //Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
267 | - |
|
268 | - $response = Route4Me::makeRequst([ |
|
269 | - 'url' => Endpoint::VEHICLE_V4, |
|
270 | - 'method' => 'POST', |
|
271 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
272 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
273 | - ]); |
|
274 | - |
|
275 | - return $response; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @deprecated 1.2.6 |
|
280 | - * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::removeVehicle() |
|
281 | - */ |
|
282 | - public function removeVehicle($params) |
|
283 | - { |
|
284 | - $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
285 | - |
|
286 | - $response = Route4Me::makeRequst([ |
|
287 | - 'url' => Endpoint::VEHICLE_V4.'/'.$vehicleID, |
|
288 | - 'method' => 'DELETE', |
|
289 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
290 | - ]); |
|
291 | - |
|
292 | - return $response; |
|
293 | - } |
|
19 | + /** @var string $vehicle_id |
|
20 | + * Vehicle unique 32-chars ID |
|
21 | + */ |
|
22 | + public $vehicle_id; |
|
23 | + |
|
24 | + /** @var int $member_id |
|
25 | + * Member unique ID |
|
26 | + */ |
|
27 | + public $member_id; |
|
28 | + |
|
29 | + /** @var boolean $is_deleted |
|
30 | + * True, if the vehicle was deleted. |
|
31 | + */ |
|
32 | + public $is_deleted; |
|
33 | + |
|
34 | + /** @var string $vehicle_alias |
|
35 | + * Vehicle alias |
|
36 | + */ |
|
37 | + public $vehicle_alias; |
|
38 | + |
|
39 | + /** @var string $vehicle_vin |
|
40 | + * Vehicle VIN (vehicle identification number) |
|
41 | + */ |
|
42 | + public $vehicle_vin; |
|
43 | + |
|
44 | + /** @var int $vehicle_reg_state_id |
|
45 | + * The ID of a state the vehicle was registered. |
|
46 | + */ |
|
47 | + public $vehicle_reg_state_id; |
|
48 | + |
|
49 | + /** @var int $vehicle_reg_country_id |
|
50 | + * The ID of a country the vehicle was registered. |
|
51 | + */ |
|
52 | + public $vehicle_reg_country_id; |
|
53 | + |
|
54 | + /** @var string $vehicle_license_plate |
|
55 | + * A license plate of the vehicle. |
|
56 | + */ |
|
57 | + public $vehicle_license_plate; |
|
58 | + |
|
59 | + /** @var string $vehicle_type_id |
|
60 | + * Vehicle type ID. |
|
61 | + * Available values: |
|
62 | + * 'sedan', 'suv', 'pickup_truck', 'van', '18wheeler', 'cabin', 'hatchback', |
|
63 | + * 'motorcyle', 'waste_disposal', 'tree_cutting', 'bigrig', 'cement_mixer', |
|
64 | + * 'livestock_carrier', 'dairy','tractor_trailer' |
|
65 | + */ |
|
66 | + public $vehicle_type_id; |
|
67 | + |
|
68 | + /** @var string $timestamp_added |
|
69 | + * When the vehicle was added. |
|
70 | + */ |
|
71 | + public $timestamp_added; |
|
72 | + |
|
73 | + /** @var string $vehicle_make |
|
74 | + * Vehicle maker brend. |
|
75 | + * Available values: |
|
76 | + * 'american coleman', 'bmw', 'chevrolet', 'ford', 'freightliner', 'gmc', |
|
77 | + * 'hino', 'honda', 'isuzu', 'kenworth', 'mack', 'mercedes-benz', 'mitsubishi', |
|
78 | + * 'navistar', 'nissan', 'peterbilt', 'renault', 'scania', 'sterling', 'toyota', |
|
79 | + * 'volvo', 'western star' |
|
80 | + */ |
|
81 | + public $vehicle_make; |
|
82 | + |
|
83 | + /** @var int $vehicle_model_year |
|
84 | + * A year of the vehicle model. |
|
85 | + */ |
|
86 | + public $vehicle_model_year; |
|
87 | + |
|
88 | + /** @var string $vehicle_model |
|
89 | + * A model of the vehicle. |
|
90 | + */ |
|
91 | + public $vehicle_model; |
|
92 | + |
|
93 | + /** @var int $vehicle_year_acquired |
|
94 | + * A year, the vehicle was acquired. |
|
95 | + */ |
|
96 | + public $vehicle_year_acquired; |
|
97 | + |
|
98 | + /** @var string $vehicle_cost_new |
|
99 | + * A cost of the new vehicle. |
|
100 | + */ |
|
101 | + public $vehicle_cost_new; |
|
102 | + |
|
103 | + /** @var string $purchased_new |
|
104 | + * If true, the vehicle was purchased new. |
|
105 | + */ |
|
106 | + public $purchased_new; |
|
107 | + |
|
108 | + /** @var string $license_start_date |
|
109 | + * Start date of the license (e.g. '2020-12-20'). |
|
110 | + */ |
|
111 | + public $license_start_date; |
|
112 | + |
|
113 | + /** @var string $license_end_date |
|
114 | + * End date of the license (e.g. '2020-12-20'). |
|
115 | + */ |
|
116 | + public $license_end_date; |
|
117 | + |
|
118 | + /** @var boolean $is_operational |
|
119 | + * If true, the vehicle is operational. |
|
120 | + */ |
|
121 | + public $is_operational; |
|
122 | + |
|
123 | + /** @var string $fuel_type |
|
124 | + * A type of the fuel. |
|
125 | + * Available values: |
|
126 | + * 'unleaded 87', 'unleaded 89', 'unleaded 91', 'unleaded 93', 'diesel', 'electric', 'hybrid' |
|
127 | + */ |
|
128 | + public $fuel_type; |
|
129 | + |
|
130 | + /** @var string $external_telematics_vehicle_id |
|
131 | + * External telematics vehicle ID. |
|
132 | + */ |
|
133 | + public $external_telematics_vehicle_id; |
|
134 | + |
|
135 | + /** @var string $timestamp_removed |
|
136 | + * When the vehicle was removed. |
|
137 | + */ |
|
138 | + public $timestamp_removed; |
|
139 | + |
|
140 | + /** @var string $vehicle_profile_id |
|
141 | + * Vehicle profile ID |
|
142 | + */ |
|
143 | + public $vehicle_profile_id; |
|
144 | + |
|
145 | + /** @var double $fuel_consumption_city |
|
146 | + * Fuel consumption in the city area. |
|
147 | + */ |
|
148 | + public $fuel_consumption_city; |
|
149 | + |
|
150 | + /** @var double $fuel_consumption_highway |
|
151 | + * Fuel consumption in the highway area. |
|
152 | + */ |
|
153 | + public $fuel_consumption_highway; |
|
154 | + |
|
155 | + /** @var string $fuel_consumption_city_unit |
|
156 | + * Fuel consumption unit in the city area (e.g. 'mi/l'). |
|
157 | + */ |
|
158 | + public $fuel_consumption_city_unit; |
|
159 | + |
|
160 | + /** @var string $fuel_consumption_highway_unit |
|
161 | + * Fuel consumption unit in the highway area (e.g. 'mi/l'). |
|
162 | + */ |
|
163 | + public $fuel_consumption_highway_unit; |
|
164 | + |
|
165 | + /** @var double $mpg_city |
|
166 | + * Miles per gallon in the city area. |
|
167 | + */ |
|
168 | + public $mpg_city; |
|
169 | + |
|
170 | + /** @var double $mpg_highway |
|
171 | + * Miles per gallon in the highway area. |
|
172 | + */ |
|
173 | + public $mpg_highway; |
|
174 | + |
|
175 | + /** @var string $fuel_consumption_city_uf_value |
|
176 | + * Fuel consumption UF (utility factor) value in the city area. |
|
177 | + */ |
|
178 | + public $fuel_consumption_city_uf_value; |
|
179 | + |
|
180 | + /** @var string $fuel_consumption_highway_uf_value |
|
181 | + * Fuel consumption UF (utility factor) value in the highway area. |
|
182 | + */ |
|
183 | + public $fuel_consumption_highway_uf_value; |
|
184 | + |
|
185 | + public function __construct() |
|
186 | + { |
|
187 | + Route4Me::setBaseUrl(Endpoint::WH_BASE_URL); |
|
188 | + } |
|
189 | + |
|
190 | + public static function fromArray(array $params) |
|
191 | + { |
|
192 | + $vehicle = new self(); |
|
193 | + |
|
194 | + foreach ($params as $key => $value) { |
|
195 | + if (is_null(Common::getValue($params, $key))) { |
|
196 | + continue; |
|
197 | + } |
|
198 | + if (property_exists($vehicle, $key)) { |
|
199 | + $vehicle->$key = $value; |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + return $vehicle; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @deprecated 1.2.6 |
|
208 | + * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::getVehiclesPaginatedList() |
|
209 | + */ |
|
210 | + public static function getVehicles($params) |
|
211 | + { |
|
212 | + $allQueryFields = ['with_pagination', 'page', 'perPage']; |
|
213 | + |
|
214 | + $response = Route4Me::makeRequst([ |
|
215 | + 'url' => Endpoint::VEHICLE_V4, |
|
216 | + 'method' => 'GET', |
|
217 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
218 | + ]); |
|
219 | + |
|
220 | + return $response; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @deprecated 1.2.6 |
|
225 | + * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::getVehicleById() |
|
226 | + */ |
|
227 | + public function getVehicleByID($vehicleID) |
|
228 | + { |
|
229 | + $response = Route4Me::makeRequst([ |
|
230 | + 'url' => Endpoint::VEHICLE_V4.'/'.$vehicleID, |
|
231 | + 'method' => 'GET', |
|
232 | + ]); |
|
233 | + |
|
234 | + return $response; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @deprecated 1.2.6 |
|
239 | + * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::updateVehicle() |
|
240 | + */ |
|
241 | + public function updateVehicle($params) |
|
242 | + { |
|
243 | + $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
244 | + |
|
245 | + $allBodyFields = Route4Me::getObjectProperties(new self(), ['vehicle_id']); |
|
246 | + |
|
247 | + $response = Route4Me::makeRequst([ |
|
248 | + 'url' => Endpoint::VEHICLE_V4.'/'.$vehicleID, |
|
249 | + 'method' => 'PUT', |
|
250 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
251 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
252 | + ]); |
|
253 | + |
|
254 | + return $response; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * @deprecated 1.2.6 |
|
259 | + * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::createVehicle() |
|
260 | + */ |
|
261 | + public function createVehicle($params) |
|
262 | + { |
|
263 | + $excludeFields = ['vehicle_id','is_deleted','created_time','timestamp_added','timestamp_removed']; |
|
264 | + $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
265 | + |
|
266 | + //Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
267 | + |
|
268 | + $response = Route4Me::makeRequst([ |
|
269 | + 'url' => Endpoint::VEHICLE_V4, |
|
270 | + 'method' => 'POST', |
|
271 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
272 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
273 | + ]); |
|
274 | + |
|
275 | + return $response; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @deprecated 1.2.6 |
|
280 | + * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::removeVehicle() |
|
281 | + */ |
|
282 | + public function removeVehicle($params) |
|
283 | + { |
|
284 | + $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
285 | + |
|
286 | + $response = Route4Me::makeRequst([ |
|
287 | + 'url' => Endpoint::VEHICLE_V4.'/'.$vehicleID, |
|
288 | + 'method' => 'DELETE', |
|
289 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
290 | + ]); |
|
291 | + |
|
292 | + return $response; |
|
293 | + } |
|
294 | 294 | } |
@@ -16,192 +16,192 @@ |
||
16 | 16 | */ |
17 | 17 | class Vehicle extends \Route4Me\Common |
18 | 18 | { |
19 | - public $vehicle_id; |
|
20 | - public $member_id; |
|
21 | - public $is_deleted; |
|
22 | - public $vehicle_name; |
|
23 | - public $vehicle_alias; |
|
24 | - public $vehicle_vin; |
|
25 | - //public $created_time; |
|
26 | - public $vehicle_reg_state_id; |
|
27 | - public $vehicle_reg_country_id; |
|
28 | - public $vehicle_license_plate; |
|
29 | - public $vehicle_type_id; |
|
30 | - public $timestamp_added; |
|
31 | - public $vehicle_make; |
|
32 | - public $vehicle_model_year; |
|
33 | - public $vehicle_model; |
|
34 | - public $vehicle_year_acquired; |
|
35 | - public $vehicle_cost_new; |
|
36 | - public $purchased_new; |
|
37 | - public $license_start_date; |
|
38 | - public $license_end_date; |
|
39 | - public $vehicle_axle_count; |
|
40 | - public $mpg_city; |
|
41 | - public $mpg_highway; |
|
42 | - public $fuel_type; |
|
43 | - public $height_inches; |
|
44 | - public $weight_lb; |
|
45 | - public $route4me_telematics_internal_api_key; |
|
46 | - public $is_operational; |
|
47 | - public $external_telematics_vehicle_id; |
|
48 | - public $r4m_telematics_gateway_connection_id; |
|
49 | - public $r4m_telematics_gateway_vehicle_id; |
|
50 | - public $has_trailer; |
|
51 | - public $heightInInches; |
|
52 | - public $lengthInInches; |
|
53 | - public $widthInInches; |
|
54 | - public $maxWeightPerAxleGroupInPounds; |
|
55 | - public $numAxles; |
|
56 | - public $weightInPounds; |
|
57 | - public $HazmatType; |
|
58 | - public $LowEmissionZonePref; |
|
59 | - public $Use53FootTrailerRouting; |
|
60 | - public $UseNationalNetwork; |
|
61 | - public $UseTruckRestrictions; |
|
62 | - public $AvoidFerries; |
|
63 | - public $DividedHighwayAvoidPreference; |
|
64 | - public $FreewayAvoidPreference; |
|
65 | - public $InternationalBordersOpen; |
|
66 | - public $TollRoadUsage; |
|
67 | - public $hwy_only; |
|
68 | - public $long_combination_vehicle; |
|
69 | - public $avoid_highways; |
|
70 | - public $side_street_adherence; |
|
71 | - public $truck_config; |
|
72 | - public $height_metric; |
|
73 | - public $length_metric; |
|
74 | - public $width_metric; |
|
75 | - public $weight_metric; |
|
76 | - public $max_weight_per_axle_group_metric; |
|
77 | - public $timestamp_removed; |
|
78 | - |
|
79 | - public function __construct() |
|
80 | - { |
|
81 | - Route4Me::setBaseUrl(Endpoint::WH_BASE_URL); |
|
82 | - } |
|
83 | - |
|
84 | - public static function fromArray(array $params) |
|
85 | - { |
|
86 | - $vehicle = new self(); |
|
87 | - |
|
88 | - foreach ($params as $key => $value) { |
|
89 | - if (is_null(Common::getValue($params, $key))) { |
|
90 | - continue; |
|
91 | - } |
|
92 | - if (property_exists($vehicle, $key)) { |
|
93 | - $vehicle->$key = $value; |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - return $vehicle; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @deprecated 1.2.6 |
|
102 | - * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::getVehiclesPaginatedList() |
|
103 | - */ |
|
104 | - public static function getVehicles($params) |
|
105 | - { |
|
106 | - $allQueryFields = ['with_pagination', 'page', 'perPage']; |
|
107 | - |
|
108 | - $response = Route4Me::makeRequst([ |
|
109 | - 'url' => Endpoint::VEHICLE_V4, |
|
110 | - 'method' => 'GET', |
|
111 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
112 | - ]); |
|
113 | - |
|
114 | - return $response; |
|
115 | - } |
|
116 | - |
|
117 | - public function getRandomVehicleId($page, $perPage) |
|
118 | - { |
|
119 | - $params = [ |
|
120 | - 'page' => isset($page) ? $page : 1, |
|
121 | - 'perPage' => isset($perPage) ? $perPage : 10, |
|
122 | - 'with_pagination' => true, |
|
123 | - ]; |
|
124 | - |
|
125 | - $vehicles = $this->getVehicles($params); |
|
126 | - |
|
127 | - if (is_null($vehicles) || !isset($vehicles['data']) || sizeof($vehicles['data']) < 1) { |
|
128 | - return null; |
|
129 | - } |
|
130 | - |
|
131 | - $randomIndex = rand(0, sizeof($vehicles['data']) - 1); |
|
132 | - |
|
133 | - return $vehicles['data'][$randomIndex]['vehicle_id']; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @deprecated 1.2.6 |
|
138 | - * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::getVehicleById() |
|
139 | - */ |
|
140 | - public function getVehicleByID($vehicleID) |
|
141 | - { |
|
142 | - $response = Route4Me::makeRequst([ |
|
143 | - 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
144 | - 'method' => 'GET', |
|
145 | - ]); |
|
146 | - |
|
147 | - return $response; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @deprecated 1.2.6 |
|
152 | - * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::updateVehicle() |
|
153 | - */ |
|
154 | - public function updateVehicle($params) |
|
155 | - { |
|
156 | - $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
157 | - |
|
158 | - $allBodyFields = Route4Me::getObjectProperties(new self(), ['vehicle_id']); |
|
159 | - |
|
160 | - $response = Route4Me::makeRequst([ |
|
161 | - 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
162 | - 'method' => 'PUT', |
|
163 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
164 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
165 | - ]); |
|
166 | - |
|
167 | - return $response; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @deprecated 1.2.6 |
|
172 | - * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::createVehicle() |
|
173 | - */ |
|
174 | - public function createVehicle($params) |
|
175 | - { |
|
176 | - $excludeFields = ['vehicle_id', 'is_deleted', 'created_time', 'timestamp_added', 'timestamp_removed']; |
|
177 | - $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
178 | - |
|
179 | - Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
180 | - |
|
181 | - $response = Route4Me::makeRequst([ |
|
182 | - 'url' => Endpoint::VEHICLE_V4_API, |
|
183 | - 'method' => 'POST', |
|
184 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
185 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
186 | - ]); |
|
187 | - |
|
188 | - return $response; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @deprecated 1.2.6 |
|
193 | - * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::removeVehicle() |
|
194 | - */ |
|
195 | - public function removeVehicle($params) |
|
196 | - { |
|
197 | - $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
198 | - |
|
199 | - $response = Route4Me::makeRequst([ |
|
200 | - 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
201 | - 'method' => 'DELETE', |
|
202 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
203 | - ]); |
|
204 | - |
|
205 | - return $response; |
|
206 | - } |
|
19 | + public $vehicle_id; |
|
20 | + public $member_id; |
|
21 | + public $is_deleted; |
|
22 | + public $vehicle_name; |
|
23 | + public $vehicle_alias; |
|
24 | + public $vehicle_vin; |
|
25 | + //public $created_time; |
|
26 | + public $vehicle_reg_state_id; |
|
27 | + public $vehicle_reg_country_id; |
|
28 | + public $vehicle_license_plate; |
|
29 | + public $vehicle_type_id; |
|
30 | + public $timestamp_added; |
|
31 | + public $vehicle_make; |
|
32 | + public $vehicle_model_year; |
|
33 | + public $vehicle_model; |
|
34 | + public $vehicle_year_acquired; |
|
35 | + public $vehicle_cost_new; |
|
36 | + public $purchased_new; |
|
37 | + public $license_start_date; |
|
38 | + public $license_end_date; |
|
39 | + public $vehicle_axle_count; |
|
40 | + public $mpg_city; |
|
41 | + public $mpg_highway; |
|
42 | + public $fuel_type; |
|
43 | + public $height_inches; |
|
44 | + public $weight_lb; |
|
45 | + public $route4me_telematics_internal_api_key; |
|
46 | + public $is_operational; |
|
47 | + public $external_telematics_vehicle_id; |
|
48 | + public $r4m_telematics_gateway_connection_id; |
|
49 | + public $r4m_telematics_gateway_vehicle_id; |
|
50 | + public $has_trailer; |
|
51 | + public $heightInInches; |
|
52 | + public $lengthInInches; |
|
53 | + public $widthInInches; |
|
54 | + public $maxWeightPerAxleGroupInPounds; |
|
55 | + public $numAxles; |
|
56 | + public $weightInPounds; |
|
57 | + public $HazmatType; |
|
58 | + public $LowEmissionZonePref; |
|
59 | + public $Use53FootTrailerRouting; |
|
60 | + public $UseNationalNetwork; |
|
61 | + public $UseTruckRestrictions; |
|
62 | + public $AvoidFerries; |
|
63 | + public $DividedHighwayAvoidPreference; |
|
64 | + public $FreewayAvoidPreference; |
|
65 | + public $InternationalBordersOpen; |
|
66 | + public $TollRoadUsage; |
|
67 | + public $hwy_only; |
|
68 | + public $long_combination_vehicle; |
|
69 | + public $avoid_highways; |
|
70 | + public $side_street_adherence; |
|
71 | + public $truck_config; |
|
72 | + public $height_metric; |
|
73 | + public $length_metric; |
|
74 | + public $width_metric; |
|
75 | + public $weight_metric; |
|
76 | + public $max_weight_per_axle_group_metric; |
|
77 | + public $timestamp_removed; |
|
78 | + |
|
79 | + public function __construct() |
|
80 | + { |
|
81 | + Route4Me::setBaseUrl(Endpoint::WH_BASE_URL); |
|
82 | + } |
|
83 | + |
|
84 | + public static function fromArray(array $params) |
|
85 | + { |
|
86 | + $vehicle = new self(); |
|
87 | + |
|
88 | + foreach ($params as $key => $value) { |
|
89 | + if (is_null(Common::getValue($params, $key))) { |
|
90 | + continue; |
|
91 | + } |
|
92 | + if (property_exists($vehicle, $key)) { |
|
93 | + $vehicle->$key = $value; |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + return $vehicle; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @deprecated 1.2.6 |
|
102 | + * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::getVehiclesPaginatedList() |
|
103 | + */ |
|
104 | + public static function getVehicles($params) |
|
105 | + { |
|
106 | + $allQueryFields = ['with_pagination', 'page', 'perPage']; |
|
107 | + |
|
108 | + $response = Route4Me::makeRequst([ |
|
109 | + 'url' => Endpoint::VEHICLE_V4, |
|
110 | + 'method' => 'GET', |
|
111 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
112 | + ]); |
|
113 | + |
|
114 | + return $response; |
|
115 | + } |
|
116 | + |
|
117 | + public function getRandomVehicleId($page, $perPage) |
|
118 | + { |
|
119 | + $params = [ |
|
120 | + 'page' => isset($page) ? $page : 1, |
|
121 | + 'perPage' => isset($perPage) ? $perPage : 10, |
|
122 | + 'with_pagination' => true, |
|
123 | + ]; |
|
124 | + |
|
125 | + $vehicles = $this->getVehicles($params); |
|
126 | + |
|
127 | + if (is_null($vehicles) || !isset($vehicles['data']) || sizeof($vehicles['data']) < 1) { |
|
128 | + return null; |
|
129 | + } |
|
130 | + |
|
131 | + $randomIndex = rand(0, sizeof($vehicles['data']) - 1); |
|
132 | + |
|
133 | + return $vehicles['data'][$randomIndex]['vehicle_id']; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @deprecated 1.2.6 |
|
138 | + * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::getVehicleById() |
|
139 | + */ |
|
140 | + public function getVehicleByID($vehicleID) |
|
141 | + { |
|
142 | + $response = Route4Me::makeRequst([ |
|
143 | + 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
144 | + 'method' => 'GET', |
|
145 | + ]); |
|
146 | + |
|
147 | + return $response; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @deprecated 1.2.6 |
|
152 | + * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::updateVehicle() |
|
153 | + */ |
|
154 | + public function updateVehicle($params) |
|
155 | + { |
|
156 | + $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
157 | + |
|
158 | + $allBodyFields = Route4Me::getObjectProperties(new self(), ['vehicle_id']); |
|
159 | + |
|
160 | + $response = Route4Me::makeRequst([ |
|
161 | + 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
162 | + 'method' => 'PUT', |
|
163 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
164 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
165 | + ]); |
|
166 | + |
|
167 | + return $response; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @deprecated 1.2.6 |
|
172 | + * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::createVehicle() |
|
173 | + */ |
|
174 | + public function createVehicle($params) |
|
175 | + { |
|
176 | + $excludeFields = ['vehicle_id', 'is_deleted', 'created_time', 'timestamp_added', 'timestamp_removed']; |
|
177 | + $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
178 | + |
|
179 | + Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
180 | + |
|
181 | + $response = Route4Me::makeRequst([ |
|
182 | + 'url' => Endpoint::VEHICLE_V4_API, |
|
183 | + 'method' => 'POST', |
|
184 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
185 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
186 | + ]); |
|
187 | + |
|
188 | + return $response; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @deprecated 1.2.6 |
|
193 | + * @see \Route4Me\V5\Vehicles\DataTypes\Vehicle::removeVehicle() |
|
194 | + */ |
|
195 | + public function removeVehicle($params) |
|
196 | + { |
|
197 | + $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null; |
|
198 | + |
|
199 | + $response = Route4Me::makeRequst([ |
|
200 | + 'url' => Endpoint::VEHICLE_V4 . '/' . $vehicleID, |
|
201 | + 'method' => 'DELETE', |
|
202 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
203 | + ]); |
|
204 | + |
|
205 | + return $response; |
|
206 | + } |
|
207 | 207 | } |
@@ -6,185 +6,185 @@ discard block |
||
6 | 6 | |
7 | 7 | class OptimizationProblem extends Common |
8 | 8 | { |
9 | - /** |
|
10 | - * Optimization problem ID |
|
11 | - * @var string |
|
12 | - */ |
|
13 | - public $optimization_problem_id; |
|
14 | - |
|
15 | - /** |
|
16 | - * Smart Optimization Problem ID |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $smart_optimization_id; |
|
20 | - |
|
21 | - /** |
|
22 | - * An array of the user errors. |
|
23 | - * @var string[] |
|
24 | - */ |
|
25 | - public $user_errors = []; |
|
26 | - |
|
27 | - /** |
|
28 | - * An optimization problem state.<br> |
|
29 | - * Available values: |
|
30 | - * - OptimizationStateNew = 0, |
|
31 | - * - Initial = 1, |
|
32 | - * - MatrixProcessing = 2, |
|
33 | - * - Optimizing = 3, |
|
34 | - * - Optimized = 4, |
|
35 | - * - Error = 5, |
|
36 | - * - ComputingDirections = 6, |
|
37 | - * - OptimizationStateInQueue = 7 |
|
38 | - * @var int |
|
39 | - */ |
|
40 | - public $state; |
|
41 | - |
|
42 | - /** |
|
43 | - * An array of the optimization errors. |
|
44 | - * @var string[] |
|
45 | - */ |
|
46 | - public $optimization_errors = []; |
|
47 | - |
|
48 | - /** |
|
49 | - * Route Parameters. |
|
50 | - * @var RouteParameters |
|
51 | - */ |
|
52 | - public $parameters; |
|
53 | - |
|
54 | - /** |
|
55 | - * If true it means the solution was not returned (it is being computed in the background). |
|
56 | - * @var boolean |
|
57 | - */ |
|
58 | - public $sent_to_background; |
|
59 | - |
|
60 | - /** |
|
61 | - * When the optimization problem was created. |
|
62 | - * @var long |
|
63 | - */ |
|
64 | - public $created_timestamp; |
|
65 | - |
|
66 | - /** |
|
67 | - * An Unix Timestamp the Optimization Problem was scheduled for. |
|
68 | - * @var long |
|
69 | - */ |
|
70 | - public $scheduled_for; |
|
71 | - |
|
72 | - /** |
|
73 | - * When the optimization completed. |
|
74 | - * @var long |
|
75 | - */ |
|
76 | - public $optimization_completed_timestamp; |
|
77 | - |
|
78 | - /** |
|
79 | - * An array ot the Address type objects. |
|
80 | - * @var Address[] |
|
81 | - */ |
|
82 | - public $addresses = []; |
|
83 | - |
|
84 | - /** |
|
85 | - * An array ot the DataObjectRoute type objects.<br> |
|
86 | - * The routes included in the optimization problem. |
|
87 | - * @var Route[] |
|
88 | - */ |
|
89 | - public $routes = []; |
|
90 | - |
|
91 | - /** @var string[] $links |
|
92 | - * The links to the GET operations for the optimization problem. |
|
93 | - */ |
|
94 | - public $links = []; |
|
95 | - |
|
96 | - public function __construct() |
|
97 | - { |
|
98 | - Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
99 | - $this->parameters = new RouteParameters(); |
|
100 | - } |
|
101 | - |
|
102 | - public static function fromArray(array $params) |
|
103 | - { |
|
104 | - $problem = new self(); |
|
105 | - $problem->optimization_problem_id = Common::getValue($params, 'optimization_problem_id'); |
|
106 | - $problem->user_errors = Common::getValue($params, 'user_errors', []); |
|
107 | - $problem->state = Common::getValue($params, 'state', []); |
|
108 | - $problem->sent_to_background = Common::getValue($params, 'sent_to_background', []); |
|
109 | - $problem->links = Common::getValue($params, 'links', []); |
|
110 | - |
|
111 | - if (isset($params['parameters'])) { |
|
112 | - $problem->parameters = RouteParameters::fromArray($params['parameters']); |
|
113 | - } |
|
114 | - |
|
115 | - if (isset($params['addresses'])) { |
|
116 | - $addresses = []; |
|
117 | - |
|
118 | - foreach ($params['addresses'] as $address) { |
|
119 | - $addresses[] = Address::fromArray($address); |
|
120 | - } |
|
121 | - |
|
122 | - $problem->addresses = $addresses; |
|
123 | - } |
|
124 | - |
|
125 | - if (isset($params['routes'])) { |
|
126 | - $routes = []; |
|
127 | - |
|
128 | - foreach ($params['routes'] as $route) { |
|
129 | - $routes[] = Route::fromArray($route); |
|
130 | - } |
|
131 | - |
|
132 | - $problem->routes = $routes; |
|
133 | - } |
|
134 | - |
|
135 | - return $problem; |
|
136 | - } |
|
137 | - |
|
138 | - public static function optimize(OptimizationProblemParams $params) |
|
139 | - { |
|
140 | - $allQueryFields = ['redirect', 'directions', 'format', 'route_path_output', 'optimized_callback_url']; |
|
141 | - |
|
142 | - $optimize = Route4Me::makeRequst([ |
|
143 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
144 | - 'method' => 'POST', |
|
145 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
146 | - 'body' => [ |
|
147 | - 'addresses' => $params->getAddressesArray(), |
|
148 | - 'depots' => $params->getDepotsArray(), |
|
149 | - 'parameters' => $params->getParametersArray(), |
|
150 | - ], |
|
151 | - ]); |
|
152 | - |
|
153 | - return self::fromArray($optimize); |
|
154 | - } |
|
155 | - |
|
156 | - public static function get($params) |
|
157 | - { |
|
158 | - $allQueryFields = ['state', 'limit', 'format', 'offset', |
|
159 | - 'optimization_problem_id', 'wait_for_final_state','start_date','end_date', ]; |
|
160 | - |
|
161 | - $result = Route4Me::makeRequst([ |
|
162 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
163 | - 'method' => 'GET', |
|
164 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
165 | - ]); |
|
166 | - |
|
167 | - if (isset($result['optimizations'])) { |
|
168 | - $problems = []; |
|
169 | - |
|
170 | - foreach ($result['optimizations'] as $problem) { |
|
171 | - $problems[] = self::fromArray($problem); |
|
172 | - } |
|
173 | - |
|
174 | - return $problems; |
|
175 | - } else { |
|
176 | - return self::fromArray($result); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - public function reoptimize($params) |
|
181 | - { |
|
182 | - $param['reoptimize'] = 1; |
|
183 | - |
|
184 | - return self::update($params); |
|
185 | - } |
|
186 | - |
|
187 | - /* |
|
9 | + /** |
|
10 | + * Optimization problem ID |
|
11 | + * @var string |
|
12 | + */ |
|
13 | + public $optimization_problem_id; |
|
14 | + |
|
15 | + /** |
|
16 | + * Smart Optimization Problem ID |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $smart_optimization_id; |
|
20 | + |
|
21 | + /** |
|
22 | + * An array of the user errors. |
|
23 | + * @var string[] |
|
24 | + */ |
|
25 | + public $user_errors = []; |
|
26 | + |
|
27 | + /** |
|
28 | + * An optimization problem state.<br> |
|
29 | + * Available values: |
|
30 | + * - OptimizationStateNew = 0, |
|
31 | + * - Initial = 1, |
|
32 | + * - MatrixProcessing = 2, |
|
33 | + * - Optimizing = 3, |
|
34 | + * - Optimized = 4, |
|
35 | + * - Error = 5, |
|
36 | + * - ComputingDirections = 6, |
|
37 | + * - OptimizationStateInQueue = 7 |
|
38 | + * @var int |
|
39 | + */ |
|
40 | + public $state; |
|
41 | + |
|
42 | + /** |
|
43 | + * An array of the optimization errors. |
|
44 | + * @var string[] |
|
45 | + */ |
|
46 | + public $optimization_errors = []; |
|
47 | + |
|
48 | + /** |
|
49 | + * Route Parameters. |
|
50 | + * @var RouteParameters |
|
51 | + */ |
|
52 | + public $parameters; |
|
53 | + |
|
54 | + /** |
|
55 | + * If true it means the solution was not returned (it is being computed in the background). |
|
56 | + * @var boolean |
|
57 | + */ |
|
58 | + public $sent_to_background; |
|
59 | + |
|
60 | + /** |
|
61 | + * When the optimization problem was created. |
|
62 | + * @var long |
|
63 | + */ |
|
64 | + public $created_timestamp; |
|
65 | + |
|
66 | + /** |
|
67 | + * An Unix Timestamp the Optimization Problem was scheduled for. |
|
68 | + * @var long |
|
69 | + */ |
|
70 | + public $scheduled_for; |
|
71 | + |
|
72 | + /** |
|
73 | + * When the optimization completed. |
|
74 | + * @var long |
|
75 | + */ |
|
76 | + public $optimization_completed_timestamp; |
|
77 | + |
|
78 | + /** |
|
79 | + * An array ot the Address type objects. |
|
80 | + * @var Address[] |
|
81 | + */ |
|
82 | + public $addresses = []; |
|
83 | + |
|
84 | + /** |
|
85 | + * An array ot the DataObjectRoute type objects.<br> |
|
86 | + * The routes included in the optimization problem. |
|
87 | + * @var Route[] |
|
88 | + */ |
|
89 | + public $routes = []; |
|
90 | + |
|
91 | + /** @var string[] $links |
|
92 | + * The links to the GET operations for the optimization problem. |
|
93 | + */ |
|
94 | + public $links = []; |
|
95 | + |
|
96 | + public function __construct() |
|
97 | + { |
|
98 | + Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
99 | + $this->parameters = new RouteParameters(); |
|
100 | + } |
|
101 | + |
|
102 | + public static function fromArray(array $params) |
|
103 | + { |
|
104 | + $problem = new self(); |
|
105 | + $problem->optimization_problem_id = Common::getValue($params, 'optimization_problem_id'); |
|
106 | + $problem->user_errors = Common::getValue($params, 'user_errors', []); |
|
107 | + $problem->state = Common::getValue($params, 'state', []); |
|
108 | + $problem->sent_to_background = Common::getValue($params, 'sent_to_background', []); |
|
109 | + $problem->links = Common::getValue($params, 'links', []); |
|
110 | + |
|
111 | + if (isset($params['parameters'])) { |
|
112 | + $problem->parameters = RouteParameters::fromArray($params['parameters']); |
|
113 | + } |
|
114 | + |
|
115 | + if (isset($params['addresses'])) { |
|
116 | + $addresses = []; |
|
117 | + |
|
118 | + foreach ($params['addresses'] as $address) { |
|
119 | + $addresses[] = Address::fromArray($address); |
|
120 | + } |
|
121 | + |
|
122 | + $problem->addresses = $addresses; |
|
123 | + } |
|
124 | + |
|
125 | + if (isset($params['routes'])) { |
|
126 | + $routes = []; |
|
127 | + |
|
128 | + foreach ($params['routes'] as $route) { |
|
129 | + $routes[] = Route::fromArray($route); |
|
130 | + } |
|
131 | + |
|
132 | + $problem->routes = $routes; |
|
133 | + } |
|
134 | + |
|
135 | + return $problem; |
|
136 | + } |
|
137 | + |
|
138 | + public static function optimize(OptimizationProblemParams $params) |
|
139 | + { |
|
140 | + $allQueryFields = ['redirect', 'directions', 'format', 'route_path_output', 'optimized_callback_url']; |
|
141 | + |
|
142 | + $optimize = Route4Me::makeRequst([ |
|
143 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
144 | + 'method' => 'POST', |
|
145 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
146 | + 'body' => [ |
|
147 | + 'addresses' => $params->getAddressesArray(), |
|
148 | + 'depots' => $params->getDepotsArray(), |
|
149 | + 'parameters' => $params->getParametersArray(), |
|
150 | + ], |
|
151 | + ]); |
|
152 | + |
|
153 | + return self::fromArray($optimize); |
|
154 | + } |
|
155 | + |
|
156 | + public static function get($params) |
|
157 | + { |
|
158 | + $allQueryFields = ['state', 'limit', 'format', 'offset', |
|
159 | + 'optimization_problem_id', 'wait_for_final_state','start_date','end_date', ]; |
|
160 | + |
|
161 | + $result = Route4Me::makeRequst([ |
|
162 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
163 | + 'method' => 'GET', |
|
164 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
165 | + ]); |
|
166 | + |
|
167 | + if (isset($result['optimizations'])) { |
|
168 | + $problems = []; |
|
169 | + |
|
170 | + foreach ($result['optimizations'] as $problem) { |
|
171 | + $problems[] = self::fromArray($problem); |
|
172 | + } |
|
173 | + |
|
174 | + return $problems; |
|
175 | + } else { |
|
176 | + return self::fromArray($result); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + public function reoptimize($params) |
|
181 | + { |
|
182 | + $param['reoptimize'] = 1; |
|
183 | + |
|
184 | + return self::update($params); |
|
185 | + } |
|
186 | + |
|
187 | + /* |
|
188 | 188 | * Updates an existing optimization problem.<br> |
189 | 189 | * @param array $params with items: |
190 | 190 | * - optimization_problem_id : query parameter. ID of an updated optimization; |
@@ -193,157 +193,157 @@ discard block |
||
193 | 193 | * - parameters : body parameter. Modified route parameters; |
194 | 194 | * @return Optimization problem |
195 | 195 | */ |
196 | - public static function update($params) |
|
197 | - { |
|
198 | - $allQueryFields = ['optimization_problem_id', 'reoptimize']; |
|
199 | - $allBodyFields = ['addresses', 'parameters']; |
|
200 | - $query = null; |
|
201 | - $body = null; |
|
202 | - |
|
203 | - if (is_array($params)) { |
|
204 | - if (isset($params['optimization_problem_id']) || isset($params['parameters'])) { |
|
205 | - $query = Route4Me::generateRequestParameters($allQueryFields, $params); |
|
206 | - } |
|
207 | - |
|
208 | - if ((isset($params['addresses']) && sizeof($params['addresses']) > 0) |
|
209 | - || (isset($params['parameters']) && sizeof($params['parameters']) > 0) |
|
210 | - ) { |
|
211 | - $body = Route4Me::generateRequestParameters($allBodyFields, $params); |
|
212 | - } |
|
213 | - } else { |
|
214 | - if (isset($params->optimization_problem_id) || isset($params->parameters)) { |
|
215 | - $query = Route4Me::generateRequestParameters($allQueryFields, $params); |
|
216 | - } |
|
217 | - |
|
218 | - if ((isset($params->addresses) && sizeof($params->addresses) > 0) |
|
219 | - || (isset($params->parameters) && sizeof($params->parameters) > 0) |
|
220 | - ) { |
|
221 | - $body = Route4Me::generateRequestParameters($allBodyFields, $params); |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - $optimize = Route4Me::makeRequst([ |
|
226 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
227 | - 'method' => 'PUT', |
|
228 | - 'query' => $query, |
|
229 | - 'body' => $body, |
|
230 | - ]); |
|
231 | - |
|
232 | - return $optimize; |
|
233 | - } |
|
234 | - |
|
235 | - public function getOptimizationId() |
|
236 | - { |
|
237 | - return $this->optimization_problem_id; |
|
238 | - } |
|
239 | - |
|
240 | - public function getRoutes() |
|
241 | - { |
|
242 | - return $this->routes; |
|
243 | - } |
|
244 | - |
|
245 | - public function getRandomOptimizationId($offset, $limit) |
|
246 | - { |
|
247 | - $optimizations = self::get(['offset' => $offset, 'limit' => $limit]); |
|
248 | - |
|
249 | - $rOptimization = $optimizations[rand(0, sizeof($optimizations) - 1)]; |
|
250 | - |
|
251 | - if (!isset($rOptimization->optimization_problem_id)) { |
|
252 | - if (sizeof($optimizations) > 9) { |
|
253 | - $this->getRandomOptimizationId($offset, $limit); |
|
254 | - } else { |
|
255 | - return null; |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - return $rOptimization->optimization_problem_id; |
|
260 | - } |
|
261 | - |
|
262 | - public function getAddresses($opt_id) |
|
263 | - { |
|
264 | - if (null == $opt_id) { |
|
265 | - return null; |
|
266 | - } |
|
267 | - |
|
268 | - $params = ['optimization_problem_id' => $opt_id]; |
|
269 | - |
|
270 | - $optimization = (array) $this->get($params); |
|
271 | - |
|
272 | - $addresses = $optimization['addresses']; |
|
273 | - |
|
274 | - return $addresses; |
|
275 | - } |
|
276 | - |
|
277 | - public function getRandomAddressFromOptimization($opt_id) |
|
278 | - { |
|
279 | - $addresses = (array) $this->getAddresses($opt_id); |
|
280 | - |
|
281 | - if (null == $addresses) { |
|
282 | - echo 'There are no addresses in this optimization!.. Try again.'; |
|
283 | - |
|
284 | - return null; |
|
285 | - } |
|
286 | - |
|
287 | - $num = rand(0, sizeof($addresses) - 1); |
|
288 | - |
|
289 | - $rAddress = $addresses[$num]; |
|
290 | - |
|
291 | - return $rAddress; |
|
292 | - } |
|
293 | - |
|
294 | - public function removeAddress($params) |
|
295 | - { |
|
296 | - $allQueryFields = ['optimization_problem_id', 'route_destination_id']; |
|
297 | - |
|
298 | - $response = Route4Me::makeRequst([ |
|
299 | - 'url' => Endpoint::ADDRESS_V4, |
|
300 | - 'method' => 'DELETE', |
|
301 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
302 | - ]); |
|
303 | - |
|
304 | - return $response; |
|
305 | - } |
|
306 | - |
|
307 | - public function removeOptimization($params) |
|
308 | - { |
|
309 | - $allQueryFields = ['redirect']; |
|
310 | - $allBodyFields = ['optimization_problem_ids']; |
|
311 | - |
|
312 | - $response = Route4Me::makeRequst([ |
|
313 | - 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
314 | - 'method' => 'DELETE', |
|
315 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
316 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
317 | - ]); |
|
318 | - |
|
319 | - return $response; |
|
320 | - } |
|
321 | - |
|
322 | - public function getHybridOptimization($params) |
|
323 | - { |
|
324 | - $allQueryFields = ['target_date_string', 'timezone_offset_minutes']; |
|
325 | - |
|
326 | - $optimize = Route4Me::makeRequst([ |
|
327 | - 'url' => Endpoint::HYBRID_DATE_OPTIMIZATION, |
|
328 | - 'method' => 'GET', |
|
329 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
330 | - ]); |
|
196 | + public static function update($params) |
|
197 | + { |
|
198 | + $allQueryFields = ['optimization_problem_id', 'reoptimize']; |
|
199 | + $allBodyFields = ['addresses', 'parameters']; |
|
200 | + $query = null; |
|
201 | + $body = null; |
|
202 | + |
|
203 | + if (is_array($params)) { |
|
204 | + if (isset($params['optimization_problem_id']) || isset($params['parameters'])) { |
|
205 | + $query = Route4Me::generateRequestParameters($allQueryFields, $params); |
|
206 | + } |
|
207 | + |
|
208 | + if ((isset($params['addresses']) && sizeof($params['addresses']) > 0) |
|
209 | + || (isset($params['parameters']) && sizeof($params['parameters']) > 0) |
|
210 | + ) { |
|
211 | + $body = Route4Me::generateRequestParameters($allBodyFields, $params); |
|
212 | + } |
|
213 | + } else { |
|
214 | + if (isset($params->optimization_problem_id) || isset($params->parameters)) { |
|
215 | + $query = Route4Me::generateRequestParameters($allQueryFields, $params); |
|
216 | + } |
|
217 | + |
|
218 | + if ((isset($params->addresses) && sizeof($params->addresses) > 0) |
|
219 | + || (isset($params->parameters) && sizeof($params->parameters) > 0) |
|
220 | + ) { |
|
221 | + $body = Route4Me::generateRequestParameters($allBodyFields, $params); |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + $optimize = Route4Me::makeRequst([ |
|
226 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
227 | + 'method' => 'PUT', |
|
228 | + 'query' => $query, |
|
229 | + 'body' => $body, |
|
230 | + ]); |
|
231 | + |
|
232 | + return $optimize; |
|
233 | + } |
|
234 | + |
|
235 | + public function getOptimizationId() |
|
236 | + { |
|
237 | + return $this->optimization_problem_id; |
|
238 | + } |
|
239 | + |
|
240 | + public function getRoutes() |
|
241 | + { |
|
242 | + return $this->routes; |
|
243 | + } |
|
244 | + |
|
245 | + public function getRandomOptimizationId($offset, $limit) |
|
246 | + { |
|
247 | + $optimizations = self::get(['offset' => $offset, 'limit' => $limit]); |
|
248 | + |
|
249 | + $rOptimization = $optimizations[rand(0, sizeof($optimizations) - 1)]; |
|
250 | + |
|
251 | + if (!isset($rOptimization->optimization_problem_id)) { |
|
252 | + if (sizeof($optimizations) > 9) { |
|
253 | + $this->getRandomOptimizationId($offset, $limit); |
|
254 | + } else { |
|
255 | + return null; |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + return $rOptimization->optimization_problem_id; |
|
260 | + } |
|
261 | + |
|
262 | + public function getAddresses($opt_id) |
|
263 | + { |
|
264 | + if (null == $opt_id) { |
|
265 | + return null; |
|
266 | + } |
|
267 | + |
|
268 | + $params = ['optimization_problem_id' => $opt_id]; |
|
269 | + |
|
270 | + $optimization = (array) $this->get($params); |
|
271 | + |
|
272 | + $addresses = $optimization['addresses']; |
|
273 | + |
|
274 | + return $addresses; |
|
275 | + } |
|
276 | + |
|
277 | + public function getRandomAddressFromOptimization($opt_id) |
|
278 | + { |
|
279 | + $addresses = (array) $this->getAddresses($opt_id); |
|
280 | + |
|
281 | + if (null == $addresses) { |
|
282 | + echo 'There are no addresses in this optimization!.. Try again.'; |
|
283 | + |
|
284 | + return null; |
|
285 | + } |
|
286 | + |
|
287 | + $num = rand(0, sizeof($addresses) - 1); |
|
288 | + |
|
289 | + $rAddress = $addresses[$num]; |
|
290 | + |
|
291 | + return $rAddress; |
|
292 | + } |
|
293 | + |
|
294 | + public function removeAddress($params) |
|
295 | + { |
|
296 | + $allQueryFields = ['optimization_problem_id', 'route_destination_id']; |
|
297 | + |
|
298 | + $response = Route4Me::makeRequst([ |
|
299 | + 'url' => Endpoint::ADDRESS_V4, |
|
300 | + 'method' => 'DELETE', |
|
301 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
302 | + ]); |
|
303 | + |
|
304 | + return $response; |
|
305 | + } |
|
306 | + |
|
307 | + public function removeOptimization($params) |
|
308 | + { |
|
309 | + $allQueryFields = ['redirect']; |
|
310 | + $allBodyFields = ['optimization_problem_ids']; |
|
311 | + |
|
312 | + $response = Route4Me::makeRequst([ |
|
313 | + 'url' => Endpoint::OPTIMIZATION_PROBLEM, |
|
314 | + 'method' => 'DELETE', |
|
315 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
316 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
317 | + ]); |
|
318 | + |
|
319 | + return $response; |
|
320 | + } |
|
321 | + |
|
322 | + public function getHybridOptimization($params) |
|
323 | + { |
|
324 | + $allQueryFields = ['target_date_string', 'timezone_offset_minutes']; |
|
325 | + |
|
326 | + $optimize = Route4Me::makeRequst([ |
|
327 | + 'url' => Endpoint::HYBRID_DATE_OPTIMIZATION, |
|
328 | + 'method' => 'GET', |
|
329 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
330 | + ]); |
|
331 | 331 | |
332 | - return $optimize; |
|
333 | - } |
|
332 | + return $optimize; |
|
333 | + } |
|
334 | 334 | |
335 | - public function addDepotsToHybrid($params) |
|
336 | - { |
|
337 | - $allQueryFields = ['optimization_problem_id']; |
|
338 | - $allBodyFields = ['optimization_problem_id', 'delete_old_depots', 'new_depots']; |
|
335 | + public function addDepotsToHybrid($params) |
|
336 | + { |
|
337 | + $allQueryFields = ['optimization_problem_id']; |
|
338 | + $allBodyFields = ['optimization_problem_id', 'delete_old_depots', 'new_depots']; |
|
339 | 339 | |
340 | - $depots = Route4Me::makeRequst([ |
|
341 | - 'url' => Endpoint::CHANGE_HYBRID_OPTIMIZATION_DEPOT, |
|
342 | - 'method' => 'POST', |
|
343 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
344 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
345 | - ]); |
|
340 | + $depots = Route4Me::makeRequst([ |
|
341 | + 'url' => Endpoint::CHANGE_HYBRID_OPTIMIZATION_DEPOT, |
|
342 | + 'method' => 'POST', |
|
343 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
344 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
345 | + ]); |
|
346 | 346 | |
347 | - return $depots; |
|
348 | - } |
|
347 | + return $depots; |
|
348 | + } |
|
349 | 349 | } |