@@ -19,499 +19,499 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Schedules extends Common |
| 21 | 21 | { |
| 22 | - public function __construct() |
|
| 23 | - { |
|
| 24 | - Route4Me::setBaseUrl(''); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Create a new Schedule by sending the corresponding data. |
|
| 29 | - * |
|
| 30 | - * @since 1.2.3 |
|
| 31 | - * |
|
| 32 | - * @param array $params |
|
| 33 | - * string schedule_uid - Schedule ID, |
|
| 34 | - * int root_member_id, |
|
| 35 | - * string name - Name of Schedule, |
|
| 36 | - * string[] schedule_blacklist - An array of blacklisted dates as 'YYYY-MM-DD', |
|
| 37 | - * int advance_interval, |
|
| 38 | - * int advance_schedule_interval_days, |
|
| 39 | - * string schedule - Schedule as JSON string e.g. '{"enabled":true,"mode":"daily", |
|
| 40 | - * "daily":{"every":2}, "from":"2019-06-05","timestamp":1558538737}', |
|
| 41 | - * string timezone - Timezone as 'America/New_York' |
|
| 42 | - * @return Schedule |
|
| 43 | - * @throws Exception\ApiError |
|
| 44 | - */ |
|
| 45 | - public function createSchedule(array $params) : Schedule |
|
| 46 | - { |
|
| 47 | - $allBodyFields = ['schedule_uid', 'root_member_id', 'name', 'schedule_blacklist', |
|
| 48 | - 'advance_interval', 'advance_schedule_interval_days', 'schedule', 'timezone']; |
|
| 49 | - |
|
| 50 | - return $this->toSchedule(Route4Me::makeRequst([ |
|
| 51 | - 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES, |
|
| 52 | - 'method' => 'POST', |
|
| 53 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 54 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 55 | - ])); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Get the Schedule by specifying the Schedule ID. |
|
| 60 | - * |
|
| 61 | - * @since 1.2.3 |
|
| 62 | - * |
|
| 63 | - * @param string $scheduleId Schedule ID. |
|
| 64 | - * @return Schedule |
|
| 65 | - * @throws Exception\ApiError |
|
| 66 | - */ |
|
| 67 | - public function getSchedule(string $scheduleId) : Schedule |
|
| 68 | - { |
|
| 69 | - return $this->toSchedule(Route4Me::makeRequst([ |
|
| 70 | - 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES . '/' . $scheduleId, |
|
| 71 | - 'method' => 'GET' |
|
| 72 | - ])); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Get the list of all Schedules. |
|
| 77 | - * |
|
| 78 | - * @since 1.2.3 |
|
| 79 | - * |
|
| 80 | - * @return Schedule[] |
|
| 81 | - * @throws Exception\ApiError |
|
| 82 | - */ |
|
| 83 | - public function getAllSchedules() : array |
|
| 84 | - { |
|
| 85 | - $result = Route4Me::makeRequst([ |
|
| 86 | - 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES, |
|
| 87 | - 'method' => 'GET' |
|
| 88 | - ]); |
|
| 89 | - |
|
| 90 | - if (is_array($result) && isset($result['data'])) { |
|
| 91 | - $data = $result['data']; |
|
| 92 | - if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 93 | - $arr = []; |
|
| 94 | - foreach ($data as $key => $value) { |
|
| 95 | - array_push($arr, new Schedule($value)); |
|
| 96 | - } |
|
| 97 | - return $arr; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - return null; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Get paginated list of Schedules. |
|
| 105 | - * |
|
| 106 | - * @since 1.2.3 |
|
| 107 | - * |
|
| 108 | - * @param int $page Requested page. |
|
| 109 | - * @param int $per_page Number of Schedules per page. |
|
| 110 | - * @return array |
|
| 111 | - * @throws Exception\ApiError |
|
| 112 | - */ |
|
| 113 | - public function getSchedules(int $page = 1, int $per_page = 15) : array |
|
| 114 | - { |
|
| 115 | - $result = Route4Me::makeRequst([ |
|
| 116 | - 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES_PAGINATION, |
|
| 117 | - 'method' => 'GET', |
|
| 118 | - 'query' => [ |
|
| 119 | - 'with_pagination' => true, |
|
| 120 | - 'page' => $page, |
|
| 121 | - 'per_page' => $per_page |
|
| 122 | - ] |
|
| 123 | - ]); |
|
| 124 | - |
|
| 125 | - if (is_array($result) && isset($result['data'])) { |
|
| 126 | - $data = $result['data']; |
|
| 127 | - $schedules = []; |
|
| 128 | - if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 129 | - foreach ($data as $key => $value) { |
|
| 130 | - array_push($schedules, new Schedule($value)); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - return [ |
|
| 134 | - 'schedules' => $schedules, |
|
| 135 | - 'page_info' => new PageInfo($result['links'], $result['meta']) |
|
| 136 | - ]; |
|
| 137 | - } |
|
| 138 | - return null; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Update the existing Schedule by sending the corresponding data. |
|
| 143 | - * |
|
| 144 | - * @since 1.2.3 |
|
| 145 | - * |
|
| 146 | - * @param string $schedule_uid Schedule ID |
|
| 147 | - * @param array $params |
|
| 148 | - * string schedule_uid - Schedule ID, |
|
| 149 | - * int root_member_id, |
|
| 150 | - * string name - Name of Schedule, |
|
| 151 | - * string[] schedule_blacklist - An array of blacklisted dates as 'YYYY-MM-DD', |
|
| 152 | - * int advance_interval, |
|
| 153 | - * int advance_schedule_interval_days, |
|
| 154 | - * string schedule - Schedule as JSON string e.g. '{"enabled":true,"mode":"daily", |
|
| 155 | - * "daily":{"every":2}, "from":"2019-06-05","timestamp":1558538737}', |
|
| 156 | - * string timezone - Timezone as 'America/New_York' |
|
| 157 | - * @return Schedule |
|
| 158 | - * @throws Exception\ApiError |
|
| 159 | - */ |
|
| 160 | - public function updateSchedule(string $scheduleId, array $params) : Schedule |
|
| 161 | - { |
|
| 162 | - $allBodyFields = ['root_member_id', 'name', 'schedule_blacklist', |
|
| 163 | - 'advance_interval', 'advance_schedule_interval_days', 'schedule', 'timezone']; |
|
| 164 | - |
|
| 165 | - return $this->toSchedule(Route4Me::makeRequst([ |
|
| 166 | - 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES . '/' . $scheduleId, |
|
| 167 | - 'method' => 'PUT', |
|
| 168 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 169 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 170 | - ])); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Delete the specified Schedule with the option to delete the associated route. |
|
| 175 | - * |
|
| 176 | - * @since 1.2.3 |
|
| 177 | - * |
|
| 178 | - * @param string $schedule_uid Schedule ID |
|
| 179 | - * @param bool $withRoutes Delete the Schedule that matches the specified Schedule ID. |
|
| 180 | - * If the deleted Schedule has one or multiple associated Routes, |
|
| 181 | - * these Routes are also deleted. |
|
| 182 | - * @return Schedule |
|
| 183 | - * @throws Exception\ApiError |
|
| 184 | - */ |
|
| 185 | - public function deleteSchedule(string $scheduleId, bool $withRoutes = false) : Schedule |
|
| 186 | - { |
|
| 187 | - return $this->toSchedule(Route4Me::makeRequst([ |
|
| 188 | - 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES . '/' . $scheduleId, |
|
| 189 | - 'method' => 'DELETE', |
|
| 190 | - 'query' => ['with_routes' => $withRoutes] |
|
| 191 | - ])); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Create a new Route Schedule by sending the corresponding data. |
|
| 196 | - * |
|
| 197 | - * @since 1.2.3 |
|
| 198 | - * |
|
| 199 | - * @param array $params |
|
| 200 | - * string route_id - Route ID, |
|
| 201 | - * string schedule_uid - Schedule ID, |
|
| 202 | - * int member_id - A unique ID of the root member, |
|
| 203 | - * string vehicle_id - Vehicle ID |
|
| 204 | - * @return RouteSchedule |
|
| 205 | - * @throws Exception\ApiError |
|
| 206 | - */ |
|
| 207 | - public function createRouteSchedule(array $params) : RouteSchedule |
|
| 208 | - { |
|
| 209 | - $allBodyFields = ['route_id', 'schedule_uid', 'member_id', 'vehicle_id']; |
|
| 210 | - |
|
| 211 | - return $this->toRouteSchedule(Route4Me::makeRequst([ |
|
| 212 | - 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES, |
|
| 213 | - 'method' => 'POST', |
|
| 214 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 215 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 216 | - ])); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Get the Route Schedule by specifying the Route ID. |
|
| 221 | - * |
|
| 222 | - * @since 1.2.3 |
|
| 223 | - * |
|
| 224 | - * @param string $routeId Route ID. |
|
| 225 | - * @return RouteSchedule |
|
| 226 | - * @throws Exception\ApiError |
|
| 227 | - */ |
|
| 228 | - public function getRouteSchedule(string $route_id) : RouteSchedule |
|
| 229 | - { |
|
| 230 | - return $this->toRouteSchedule(Route4Me::makeRequst([ |
|
| 231 | - 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES . '/' . $route_id, |
|
| 232 | - 'method' => 'GET' |
|
| 233 | - ])); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Get the list of all Route Schedules. |
|
| 238 | - * |
|
| 239 | - * @since 1.2.3 |
|
| 240 | - * |
|
| 241 | - * @return RouteSchedule[] |
|
| 242 | - * @throws Exception\ApiError |
|
| 243 | - */ |
|
| 244 | - public function getAllRouteSchedules() : array |
|
| 245 | - { |
|
| 246 | - $result = Route4Me::makeRequst([ |
|
| 247 | - 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES, |
|
| 248 | - 'method' => 'GET' |
|
| 249 | - ]); |
|
| 250 | - |
|
| 251 | - if (is_array($result) && isset($result['data'])) { |
|
| 252 | - $data = $result['data']; |
|
| 253 | - if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 254 | - $arr = []; |
|
| 255 | - foreach ($data as $key => $value) { |
|
| 256 | - array_push($arr, new RouteSchedule($value)); |
|
| 257 | - } |
|
| 258 | - return $arr; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - return null; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Get paginated list of Route Schedules. |
|
| 266 | - * |
|
| 267 | - * @since 1.2.3 |
|
| 268 | - * |
|
| 269 | - * @param int $page Requested page. |
|
| 270 | - * @param int $per_page Number of Route Schedules per page. |
|
| 271 | - * @return array |
|
| 272 | - * @throws Exception\ApiError |
|
| 273 | - */ |
|
| 274 | - public function getRouteSchedules(int $page = 1, int $per_page = 15) : array |
|
| 275 | - { |
|
| 276 | - $result = Route4Me::makeRequst([ |
|
| 277 | - 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES_PAGINATION, |
|
| 278 | - 'method' => 'GET', |
|
| 279 | - 'query' => [ |
|
| 280 | - 'with_pagination' => true, |
|
| 281 | - 'page' => $page, |
|
| 282 | - 'per_page' => $per_page |
|
| 283 | - ] |
|
| 284 | - ]); |
|
| 285 | - |
|
| 286 | - if (is_array($result) && isset($result['data'])) { |
|
| 287 | - $data = $result['data']; |
|
| 288 | - $route_schedules = []; |
|
| 289 | - if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 290 | - foreach ($data as $key => $value) { |
|
| 291 | - array_push($route_schedules, new RouteSchedule($value)); |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - return [ |
|
| 295 | - 'route_schedules' => $route_schedules, |
|
| 296 | - 'page_info' => new PageInfo($result['links'], $result['meta']) |
|
| 297 | - ]; |
|
| 298 | - } |
|
| 299 | - return null; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Update the existing Route Schedule by sending the corresponding data. |
|
| 304 | - * |
|
| 305 | - * @since 1.2.3 |
|
| 306 | - * |
|
| 307 | - * @param string $route_id Route ID |
|
| 308 | - * @param array $params |
|
| 309 | - * string schedule_uid - Schedule ID, |
|
| 310 | - * int member_id - A unique ID of the root member, |
|
| 311 | - * string vehicle_id - Vehicle ID |
|
| 312 | - * @return RouteSchedule |
|
| 313 | - * @throws Exception\ApiError |
|
| 314 | - */ |
|
| 315 | - public function updateRouteSchedule(string $route_id, array $params) : RouteSchedule |
|
| 316 | - { |
|
| 317 | - $allBodyFields = ['schedule_uid', 'member_id', 'vehicle_id']; |
|
| 318 | - |
|
| 319 | - return $this->toRouteSchedule(Route4Me::makeRequst([ |
|
| 320 | - 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES . '/' . $route_id, |
|
| 321 | - 'method' => 'PUT', |
|
| 322 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 323 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 324 | - ])); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Delete the Route Schedules. |
|
| 329 | - * @todo request return true instead of return json status |
|
| 330 | - * |
|
| 331 | - * @since 1.2.3 |
|
| 332 | - * |
|
| 333 | - * @param string $route_id Route ID |
|
| 334 | - * @return bool |
|
| 335 | - * @throws Exception\ApiError |
|
| 336 | - */ |
|
| 337 | - public function deleteRouteSchedules(string $route_id) : bool |
|
| 338 | - { |
|
| 339 | - $result = Route4Me::makeRequst([ |
|
| 340 | - 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES . '/' . $route_id, |
|
| 341 | - 'method' => 'DELETE' |
|
| 342 | - ]); |
|
| 343 | - return ($result == 1 ? true : false); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Delete the specified Route Schedule. |
|
| 348 | - * |
|
| 349 | - * @since 1.2.3 |
|
| 350 | - * |
|
| 351 | - * @param string $route_id Route ID |
|
| 352 | - * @return RouteSchedule |
|
| 353 | - * @throws Exception\ApiError |
|
| 354 | - */ |
|
| 355 | - public function deleteRouteSchedule(string $route_id) : RouteSchedule |
|
| 356 | - { |
|
| 357 | - return $this->toRouteSchedule(Route4Me::makeRequst([ |
|
| 358 | - 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES . '/' . $route_id . '/items', |
|
| 359 | - 'method' => 'DELETE' |
|
| 360 | - ])); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Replace the existing Route Schedule by sending the corresponding data. |
|
| 365 | - * |
|
| 366 | - * @since 1.2.3 |
|
| 367 | - * |
|
| 368 | - * @param string $route_id Route ID. |
|
| 369 | - * @param array $params |
|
| 370 | - * int member_id - A unique ID of the root member, |
|
| 371 | - * string vehicle_id - Vehicle ID, |
|
| 372 | - * string schedule_uid - Schedule ID, |
|
| 373 | - * string name, |
|
| 374 | - * string[] schedule_blacklist - Blacklisted dates as YYYY-MM-DD, |
|
| 375 | - * int advance_interval, |
|
| 376 | - * int advance_schedule_interval_days, |
|
| 377 | - * string schedule - Schedule as JSON string e.g. '{"enabled":true,"mode":"daily", |
|
| 378 | - * "daily":{"every":2}, "from":"2019-06-05","timestamp":1558538737}', |
|
| 379 | - * string timezone - Timezone as 'America/New_York' |
|
| 380 | - * @return RouteSchedule |
|
| 381 | - * @throws Exception\ApiError |
|
| 382 | - */ |
|
| 383 | - public function replaceRouteSchedule(string $route_id, array $params) |
|
| 384 | - { |
|
| 385 | - $allBodyFields = ['member_id', 'vehicle_id', 'schedule_uid', 'name', 'schedule_blacklist', |
|
| 386 | - 'advance_interval', 'advance_schedule_interval_days', 'schedule', 'timezone']; |
|
| 387 | - |
|
| 388 | - return $this->toRouteSchedule(Route4Me::makeRequst([ |
|
| 389 | - 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES_REPLACE . '/' . $route_id, |
|
| 390 | - 'method' => 'PUT', |
|
| 391 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 392 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 393 | - ])); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Get the Route Schedule preview by specifying the 'route_id'. |
|
| 398 | - * |
|
| 399 | - * @since 1.2.3 |
|
| 400 | - * |
|
| 401 | - * @param string $routeId Route ID. |
|
| 402 | - * @param string $start Start date as 'YYYY-MM-DD' |
|
| 403 | - * @param string $end End date as 'YYYY-MM-DD' |
|
| 404 | - * @return array |
|
| 405 | - * @throws Exception\ApiError |
|
| 406 | - */ |
|
| 407 | - public function getRouteSchedulePreview(string $route_id, string $start, string $end) : array |
|
| 408 | - { |
|
| 409 | - return Route4Me::makeRequst([ |
|
| 410 | - 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES . '/' . $route_id . '/preview', |
|
| 411 | - 'method' => 'GET', |
|
| 412 | - 'query' => ['start' => $start, 'end' => $end] |
|
| 413 | - ]); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * Check if the Scheduled Route was copied by specifying the 'route_id'. |
|
| 418 | - * @todo request return true instead of return json status |
|
| 419 | - * |
|
| 420 | - * @since 1.2.3 |
|
| 421 | - * |
|
| 422 | - * @param string $routeId Route ID. |
|
| 423 | - * @return bool |
|
| 424 | - * @throws Exception\ApiError |
|
| 425 | - */ |
|
| 426 | - public function isScheduledRouteCopy(string $route_id) : bool |
|
| 427 | - { |
|
| 428 | - return Route4Me::makeRequst([ |
|
| 429 | - 'url' => Endpoint::RECURRING_ROUTES_SCHEDULED_ROUTES_IS_COPY . '/' . $route_id, |
|
| 430 | - 'method' => 'GET' |
|
| 431 | - ]); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Get all routes copied from the specified Scheduled Route by sending |
|
| 436 | - * the corresponding data. |
|
| 437 | - * |
|
| 438 | - * @since 1.2.3 |
|
| 439 | - * |
|
| 440 | - * @param string $route_id Route ID. |
|
| 441 | - * @param string $schedule_uid Schedule ID. |
|
| 442 | - * @param string $route_date Route date as 'YYYY-MM-DD'. |
|
| 443 | - * @return array |
|
| 444 | - * @throws Exception\ApiError |
|
| 445 | - */ |
|
| 446 | - public function getScheduledRoutesCopies(string $route_id, string $schedule_uid, string $route_date) : array |
|
| 447 | - { |
|
| 448 | - return Route4Me::makeRequst([ |
|
| 449 | - 'url' => Endpoint::RECURRING_ROUTES_SCHEDULED_ROUTES_GET_COPIES, |
|
| 450 | - 'method' => 'POST', |
|
| 451 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 452 | - 'body' => [ |
|
| 453 | - 'route_id' => $route_id, |
|
| 454 | - 'schedule_uid' => $schedule_uid, |
|
| 455 | - 'route_date' => $route_date |
|
| 456 | - ] |
|
| 457 | - ]); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Create a new Master Route by sending the corresponding data. |
|
| 462 | - * @todo request return true instead of return json status |
|
| 463 | - * |
|
| 464 | - * @since 1.2.3 |
|
| 465 | - * |
|
| 466 | - * @param array $params |
|
| 467 | - * string route_id - Route ID, |
|
| 468 | - * string route_name, |
|
| 469 | - * int member_id - A unique ID of the root member, |
|
| 470 | - * string vehicle_id - Vehicle ID, |
|
| 471 | - * string schedule_uid - Schedule ID, |
|
| 472 | - * string name, |
|
| 473 | - * string[] schedule_blacklist - Blacklisted dates as YYYY-MM-DD, |
|
| 474 | - * int advance_interval, |
|
| 475 | - * int advance_schedule_interval_days, |
|
| 476 | - * string schedule - Schedule as JSON string e.g. '{"enabled":true,"mode":"daily", |
|
| 477 | - * "daily":{"every":2}, "from":"2019-06-05","timestamp":1558538737}', |
|
| 478 | - * bool sync - Type of result, synchronous or not |
|
| 479 | - * string timezone - Timezone as 'America/New_York' |
|
| 480 | - * @return bool |
|
| 481 | - * @throws Exception\ApiError |
|
| 482 | - */ |
|
| 483 | - public function createMasterRoute(array $params) : bool |
|
| 484 | - { |
|
| 485 | - $allBodyFields = ['route_id', 'route_name', 'member_id', 'schedule_uid', 'vehicle_id', 'name', |
|
| 486 | - 'schedule_blacklist', 'advance_schedule_interval_days', 'schedule', 'timezone', 'sync']; |
|
| 487 | - |
|
| 488 | - return Route4Me::makeRequst([ |
|
| 489 | - 'url' => Endpoint::RECURRING_ROUTES_MASTER_ROUTES, |
|
| 490 | - 'method' => 'POST', |
|
| 491 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 492 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 493 | - ]); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - private function toSchedule($result) : Schedule |
|
| 497 | - { |
|
| 498 | - if (is_array($result) && isset($result['data'])) { |
|
| 499 | - $data = $result['data']; |
|
| 500 | - if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 501 | - return new Schedule($data[0]); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - throw new ApiError('Can not convert result to Schedule object.'); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - private function toRouteSchedule($result) : RouteSchedule |
|
| 508 | - { |
|
| 509 | - if (is_array($result) && isset($result['data'])) { |
|
| 510 | - $data = $result['data']; |
|
| 511 | - if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 512 | - return new RouteSchedule($data[0]); |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - throw new ApiError('Can not convert result to RouteSchedule object.'); |
|
| 516 | - } |
|
| 22 | + public function __construct() |
|
| 23 | + { |
|
| 24 | + Route4Me::setBaseUrl(''); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Create a new Schedule by sending the corresponding data. |
|
| 29 | + * |
|
| 30 | + * @since 1.2.3 |
|
| 31 | + * |
|
| 32 | + * @param array $params |
|
| 33 | + * string schedule_uid - Schedule ID, |
|
| 34 | + * int root_member_id, |
|
| 35 | + * string name - Name of Schedule, |
|
| 36 | + * string[] schedule_blacklist - An array of blacklisted dates as 'YYYY-MM-DD', |
|
| 37 | + * int advance_interval, |
|
| 38 | + * int advance_schedule_interval_days, |
|
| 39 | + * string schedule - Schedule as JSON string e.g. '{"enabled":true,"mode":"daily", |
|
| 40 | + * "daily":{"every":2}, "from":"2019-06-05","timestamp":1558538737}', |
|
| 41 | + * string timezone - Timezone as 'America/New_York' |
|
| 42 | + * @return Schedule |
|
| 43 | + * @throws Exception\ApiError |
|
| 44 | + */ |
|
| 45 | + public function createSchedule(array $params) : Schedule |
|
| 46 | + { |
|
| 47 | + $allBodyFields = ['schedule_uid', 'root_member_id', 'name', 'schedule_blacklist', |
|
| 48 | + 'advance_interval', 'advance_schedule_interval_days', 'schedule', 'timezone']; |
|
| 49 | + |
|
| 50 | + return $this->toSchedule(Route4Me::makeRequst([ |
|
| 51 | + 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES, |
|
| 52 | + 'method' => 'POST', |
|
| 53 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 54 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 55 | + ])); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Get the Schedule by specifying the Schedule ID. |
|
| 60 | + * |
|
| 61 | + * @since 1.2.3 |
|
| 62 | + * |
|
| 63 | + * @param string $scheduleId Schedule ID. |
|
| 64 | + * @return Schedule |
|
| 65 | + * @throws Exception\ApiError |
|
| 66 | + */ |
|
| 67 | + public function getSchedule(string $scheduleId) : Schedule |
|
| 68 | + { |
|
| 69 | + return $this->toSchedule(Route4Me::makeRequst([ |
|
| 70 | + 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES . '/' . $scheduleId, |
|
| 71 | + 'method' => 'GET' |
|
| 72 | + ])); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Get the list of all Schedules. |
|
| 77 | + * |
|
| 78 | + * @since 1.2.3 |
|
| 79 | + * |
|
| 80 | + * @return Schedule[] |
|
| 81 | + * @throws Exception\ApiError |
|
| 82 | + */ |
|
| 83 | + public function getAllSchedules() : array |
|
| 84 | + { |
|
| 85 | + $result = Route4Me::makeRequst([ |
|
| 86 | + 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES, |
|
| 87 | + 'method' => 'GET' |
|
| 88 | + ]); |
|
| 89 | + |
|
| 90 | + if (is_array($result) && isset($result['data'])) { |
|
| 91 | + $data = $result['data']; |
|
| 92 | + if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 93 | + $arr = []; |
|
| 94 | + foreach ($data as $key => $value) { |
|
| 95 | + array_push($arr, new Schedule($value)); |
|
| 96 | + } |
|
| 97 | + return $arr; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + return null; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Get paginated list of Schedules. |
|
| 105 | + * |
|
| 106 | + * @since 1.2.3 |
|
| 107 | + * |
|
| 108 | + * @param int $page Requested page. |
|
| 109 | + * @param int $per_page Number of Schedules per page. |
|
| 110 | + * @return array |
|
| 111 | + * @throws Exception\ApiError |
|
| 112 | + */ |
|
| 113 | + public function getSchedules(int $page = 1, int $per_page = 15) : array |
|
| 114 | + { |
|
| 115 | + $result = Route4Me::makeRequst([ |
|
| 116 | + 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES_PAGINATION, |
|
| 117 | + 'method' => 'GET', |
|
| 118 | + 'query' => [ |
|
| 119 | + 'with_pagination' => true, |
|
| 120 | + 'page' => $page, |
|
| 121 | + 'per_page' => $per_page |
|
| 122 | + ] |
|
| 123 | + ]); |
|
| 124 | + |
|
| 125 | + if (is_array($result) && isset($result['data'])) { |
|
| 126 | + $data = $result['data']; |
|
| 127 | + $schedules = []; |
|
| 128 | + if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 129 | + foreach ($data as $key => $value) { |
|
| 130 | + array_push($schedules, new Schedule($value)); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + return [ |
|
| 134 | + 'schedules' => $schedules, |
|
| 135 | + 'page_info' => new PageInfo($result['links'], $result['meta']) |
|
| 136 | + ]; |
|
| 137 | + } |
|
| 138 | + return null; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Update the existing Schedule by sending the corresponding data. |
|
| 143 | + * |
|
| 144 | + * @since 1.2.3 |
|
| 145 | + * |
|
| 146 | + * @param string $schedule_uid Schedule ID |
|
| 147 | + * @param array $params |
|
| 148 | + * string schedule_uid - Schedule ID, |
|
| 149 | + * int root_member_id, |
|
| 150 | + * string name - Name of Schedule, |
|
| 151 | + * string[] schedule_blacklist - An array of blacklisted dates as 'YYYY-MM-DD', |
|
| 152 | + * int advance_interval, |
|
| 153 | + * int advance_schedule_interval_days, |
|
| 154 | + * string schedule - Schedule as JSON string e.g. '{"enabled":true,"mode":"daily", |
|
| 155 | + * "daily":{"every":2}, "from":"2019-06-05","timestamp":1558538737}', |
|
| 156 | + * string timezone - Timezone as 'America/New_York' |
|
| 157 | + * @return Schedule |
|
| 158 | + * @throws Exception\ApiError |
|
| 159 | + */ |
|
| 160 | + public function updateSchedule(string $scheduleId, array $params) : Schedule |
|
| 161 | + { |
|
| 162 | + $allBodyFields = ['root_member_id', 'name', 'schedule_blacklist', |
|
| 163 | + 'advance_interval', 'advance_schedule_interval_days', 'schedule', 'timezone']; |
|
| 164 | + |
|
| 165 | + return $this->toSchedule(Route4Me::makeRequst([ |
|
| 166 | + 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES . '/' . $scheduleId, |
|
| 167 | + 'method' => 'PUT', |
|
| 168 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 169 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 170 | + ])); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Delete the specified Schedule with the option to delete the associated route. |
|
| 175 | + * |
|
| 176 | + * @since 1.2.3 |
|
| 177 | + * |
|
| 178 | + * @param string $schedule_uid Schedule ID |
|
| 179 | + * @param bool $withRoutes Delete the Schedule that matches the specified Schedule ID. |
|
| 180 | + * If the deleted Schedule has one or multiple associated Routes, |
|
| 181 | + * these Routes are also deleted. |
|
| 182 | + * @return Schedule |
|
| 183 | + * @throws Exception\ApiError |
|
| 184 | + */ |
|
| 185 | + public function deleteSchedule(string $scheduleId, bool $withRoutes = false) : Schedule |
|
| 186 | + { |
|
| 187 | + return $this->toSchedule(Route4Me::makeRequst([ |
|
| 188 | + 'url' => Endpoint::RECURRING_ROUTES_SCHEDULES . '/' . $scheduleId, |
|
| 189 | + 'method' => 'DELETE', |
|
| 190 | + 'query' => ['with_routes' => $withRoutes] |
|
| 191 | + ])); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Create a new Route Schedule by sending the corresponding data. |
|
| 196 | + * |
|
| 197 | + * @since 1.2.3 |
|
| 198 | + * |
|
| 199 | + * @param array $params |
|
| 200 | + * string route_id - Route ID, |
|
| 201 | + * string schedule_uid - Schedule ID, |
|
| 202 | + * int member_id - A unique ID of the root member, |
|
| 203 | + * string vehicle_id - Vehicle ID |
|
| 204 | + * @return RouteSchedule |
|
| 205 | + * @throws Exception\ApiError |
|
| 206 | + */ |
|
| 207 | + public function createRouteSchedule(array $params) : RouteSchedule |
|
| 208 | + { |
|
| 209 | + $allBodyFields = ['route_id', 'schedule_uid', 'member_id', 'vehicle_id']; |
|
| 210 | + |
|
| 211 | + return $this->toRouteSchedule(Route4Me::makeRequst([ |
|
| 212 | + 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES, |
|
| 213 | + 'method' => 'POST', |
|
| 214 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 215 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 216 | + ])); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Get the Route Schedule by specifying the Route ID. |
|
| 221 | + * |
|
| 222 | + * @since 1.2.3 |
|
| 223 | + * |
|
| 224 | + * @param string $routeId Route ID. |
|
| 225 | + * @return RouteSchedule |
|
| 226 | + * @throws Exception\ApiError |
|
| 227 | + */ |
|
| 228 | + public function getRouteSchedule(string $route_id) : RouteSchedule |
|
| 229 | + { |
|
| 230 | + return $this->toRouteSchedule(Route4Me::makeRequst([ |
|
| 231 | + 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES . '/' . $route_id, |
|
| 232 | + 'method' => 'GET' |
|
| 233 | + ])); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Get the list of all Route Schedules. |
|
| 238 | + * |
|
| 239 | + * @since 1.2.3 |
|
| 240 | + * |
|
| 241 | + * @return RouteSchedule[] |
|
| 242 | + * @throws Exception\ApiError |
|
| 243 | + */ |
|
| 244 | + public function getAllRouteSchedules() : array |
|
| 245 | + { |
|
| 246 | + $result = Route4Me::makeRequst([ |
|
| 247 | + 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES, |
|
| 248 | + 'method' => 'GET' |
|
| 249 | + ]); |
|
| 250 | + |
|
| 251 | + if (is_array($result) && isset($result['data'])) { |
|
| 252 | + $data = $result['data']; |
|
| 253 | + if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 254 | + $arr = []; |
|
| 255 | + foreach ($data as $key => $value) { |
|
| 256 | + array_push($arr, new RouteSchedule($value)); |
|
| 257 | + } |
|
| 258 | + return $arr; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + return null; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Get paginated list of Route Schedules. |
|
| 266 | + * |
|
| 267 | + * @since 1.2.3 |
|
| 268 | + * |
|
| 269 | + * @param int $page Requested page. |
|
| 270 | + * @param int $per_page Number of Route Schedules per page. |
|
| 271 | + * @return array |
|
| 272 | + * @throws Exception\ApiError |
|
| 273 | + */ |
|
| 274 | + public function getRouteSchedules(int $page = 1, int $per_page = 15) : array |
|
| 275 | + { |
|
| 276 | + $result = Route4Me::makeRequst([ |
|
| 277 | + 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES_PAGINATION, |
|
| 278 | + 'method' => 'GET', |
|
| 279 | + 'query' => [ |
|
| 280 | + 'with_pagination' => true, |
|
| 281 | + 'page' => $page, |
|
| 282 | + 'per_page' => $per_page |
|
| 283 | + ] |
|
| 284 | + ]); |
|
| 285 | + |
|
| 286 | + if (is_array($result) && isset($result['data'])) { |
|
| 287 | + $data = $result['data']; |
|
| 288 | + $route_schedules = []; |
|
| 289 | + if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 290 | + foreach ($data as $key => $value) { |
|
| 291 | + array_push($route_schedules, new RouteSchedule($value)); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + return [ |
|
| 295 | + 'route_schedules' => $route_schedules, |
|
| 296 | + 'page_info' => new PageInfo($result['links'], $result['meta']) |
|
| 297 | + ]; |
|
| 298 | + } |
|
| 299 | + return null; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Update the existing Route Schedule by sending the corresponding data. |
|
| 304 | + * |
|
| 305 | + * @since 1.2.3 |
|
| 306 | + * |
|
| 307 | + * @param string $route_id Route ID |
|
| 308 | + * @param array $params |
|
| 309 | + * string schedule_uid - Schedule ID, |
|
| 310 | + * int member_id - A unique ID of the root member, |
|
| 311 | + * string vehicle_id - Vehicle ID |
|
| 312 | + * @return RouteSchedule |
|
| 313 | + * @throws Exception\ApiError |
|
| 314 | + */ |
|
| 315 | + public function updateRouteSchedule(string $route_id, array $params) : RouteSchedule |
|
| 316 | + { |
|
| 317 | + $allBodyFields = ['schedule_uid', 'member_id', 'vehicle_id']; |
|
| 318 | + |
|
| 319 | + return $this->toRouteSchedule(Route4Me::makeRequst([ |
|
| 320 | + 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES . '/' . $route_id, |
|
| 321 | + 'method' => 'PUT', |
|
| 322 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 323 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 324 | + ])); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Delete the Route Schedules. |
|
| 329 | + * @todo request return true instead of return json status |
|
| 330 | + * |
|
| 331 | + * @since 1.2.3 |
|
| 332 | + * |
|
| 333 | + * @param string $route_id Route ID |
|
| 334 | + * @return bool |
|
| 335 | + * @throws Exception\ApiError |
|
| 336 | + */ |
|
| 337 | + public function deleteRouteSchedules(string $route_id) : bool |
|
| 338 | + { |
|
| 339 | + $result = Route4Me::makeRequst([ |
|
| 340 | + 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES . '/' . $route_id, |
|
| 341 | + 'method' => 'DELETE' |
|
| 342 | + ]); |
|
| 343 | + return ($result == 1 ? true : false); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Delete the specified Route Schedule. |
|
| 348 | + * |
|
| 349 | + * @since 1.2.3 |
|
| 350 | + * |
|
| 351 | + * @param string $route_id Route ID |
|
| 352 | + * @return RouteSchedule |
|
| 353 | + * @throws Exception\ApiError |
|
| 354 | + */ |
|
| 355 | + public function deleteRouteSchedule(string $route_id) : RouteSchedule |
|
| 356 | + { |
|
| 357 | + return $this->toRouteSchedule(Route4Me::makeRequst([ |
|
| 358 | + 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES . '/' . $route_id . '/items', |
|
| 359 | + 'method' => 'DELETE' |
|
| 360 | + ])); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Replace the existing Route Schedule by sending the corresponding data. |
|
| 365 | + * |
|
| 366 | + * @since 1.2.3 |
|
| 367 | + * |
|
| 368 | + * @param string $route_id Route ID. |
|
| 369 | + * @param array $params |
|
| 370 | + * int member_id - A unique ID of the root member, |
|
| 371 | + * string vehicle_id - Vehicle ID, |
|
| 372 | + * string schedule_uid - Schedule ID, |
|
| 373 | + * string name, |
|
| 374 | + * string[] schedule_blacklist - Blacklisted dates as YYYY-MM-DD, |
|
| 375 | + * int advance_interval, |
|
| 376 | + * int advance_schedule_interval_days, |
|
| 377 | + * string schedule - Schedule as JSON string e.g. '{"enabled":true,"mode":"daily", |
|
| 378 | + * "daily":{"every":2}, "from":"2019-06-05","timestamp":1558538737}', |
|
| 379 | + * string timezone - Timezone as 'America/New_York' |
|
| 380 | + * @return RouteSchedule |
|
| 381 | + * @throws Exception\ApiError |
|
| 382 | + */ |
|
| 383 | + public function replaceRouteSchedule(string $route_id, array $params) |
|
| 384 | + { |
|
| 385 | + $allBodyFields = ['member_id', 'vehicle_id', 'schedule_uid', 'name', 'schedule_blacklist', |
|
| 386 | + 'advance_interval', 'advance_schedule_interval_days', 'schedule', 'timezone']; |
|
| 387 | + |
|
| 388 | + return $this->toRouteSchedule(Route4Me::makeRequst([ |
|
| 389 | + 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES_REPLACE . '/' . $route_id, |
|
| 390 | + 'method' => 'PUT', |
|
| 391 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 392 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 393 | + ])); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Get the Route Schedule preview by specifying the 'route_id'. |
|
| 398 | + * |
|
| 399 | + * @since 1.2.3 |
|
| 400 | + * |
|
| 401 | + * @param string $routeId Route ID. |
|
| 402 | + * @param string $start Start date as 'YYYY-MM-DD' |
|
| 403 | + * @param string $end End date as 'YYYY-MM-DD' |
|
| 404 | + * @return array |
|
| 405 | + * @throws Exception\ApiError |
|
| 406 | + */ |
|
| 407 | + public function getRouteSchedulePreview(string $route_id, string $start, string $end) : array |
|
| 408 | + { |
|
| 409 | + return Route4Me::makeRequst([ |
|
| 410 | + 'url' => Endpoint::RECURRING_ROUTES_ROUTE_SCHEDULES . '/' . $route_id . '/preview', |
|
| 411 | + 'method' => 'GET', |
|
| 412 | + 'query' => ['start' => $start, 'end' => $end] |
|
| 413 | + ]); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * Check if the Scheduled Route was copied by specifying the 'route_id'. |
|
| 418 | + * @todo request return true instead of return json status |
|
| 419 | + * |
|
| 420 | + * @since 1.2.3 |
|
| 421 | + * |
|
| 422 | + * @param string $routeId Route ID. |
|
| 423 | + * @return bool |
|
| 424 | + * @throws Exception\ApiError |
|
| 425 | + */ |
|
| 426 | + public function isScheduledRouteCopy(string $route_id) : bool |
|
| 427 | + { |
|
| 428 | + return Route4Me::makeRequst([ |
|
| 429 | + 'url' => Endpoint::RECURRING_ROUTES_SCHEDULED_ROUTES_IS_COPY . '/' . $route_id, |
|
| 430 | + 'method' => 'GET' |
|
| 431 | + ]); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Get all routes copied from the specified Scheduled Route by sending |
|
| 436 | + * the corresponding data. |
|
| 437 | + * |
|
| 438 | + * @since 1.2.3 |
|
| 439 | + * |
|
| 440 | + * @param string $route_id Route ID. |
|
| 441 | + * @param string $schedule_uid Schedule ID. |
|
| 442 | + * @param string $route_date Route date as 'YYYY-MM-DD'. |
|
| 443 | + * @return array |
|
| 444 | + * @throws Exception\ApiError |
|
| 445 | + */ |
|
| 446 | + public function getScheduledRoutesCopies(string $route_id, string $schedule_uid, string $route_date) : array |
|
| 447 | + { |
|
| 448 | + return Route4Me::makeRequst([ |
|
| 449 | + 'url' => Endpoint::RECURRING_ROUTES_SCHEDULED_ROUTES_GET_COPIES, |
|
| 450 | + 'method' => 'POST', |
|
| 451 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 452 | + 'body' => [ |
|
| 453 | + 'route_id' => $route_id, |
|
| 454 | + 'schedule_uid' => $schedule_uid, |
|
| 455 | + 'route_date' => $route_date |
|
| 456 | + ] |
|
| 457 | + ]); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Create a new Master Route by sending the corresponding data. |
|
| 462 | + * @todo request return true instead of return json status |
|
| 463 | + * |
|
| 464 | + * @since 1.2.3 |
|
| 465 | + * |
|
| 466 | + * @param array $params |
|
| 467 | + * string route_id - Route ID, |
|
| 468 | + * string route_name, |
|
| 469 | + * int member_id - A unique ID of the root member, |
|
| 470 | + * string vehicle_id - Vehicle ID, |
|
| 471 | + * string schedule_uid - Schedule ID, |
|
| 472 | + * string name, |
|
| 473 | + * string[] schedule_blacklist - Blacklisted dates as YYYY-MM-DD, |
|
| 474 | + * int advance_interval, |
|
| 475 | + * int advance_schedule_interval_days, |
|
| 476 | + * string schedule - Schedule as JSON string e.g. '{"enabled":true,"mode":"daily", |
|
| 477 | + * "daily":{"every":2}, "from":"2019-06-05","timestamp":1558538737}', |
|
| 478 | + * bool sync - Type of result, synchronous or not |
|
| 479 | + * string timezone - Timezone as 'America/New_York' |
|
| 480 | + * @return bool |
|
| 481 | + * @throws Exception\ApiError |
|
| 482 | + */ |
|
| 483 | + public function createMasterRoute(array $params) : bool |
|
| 484 | + { |
|
| 485 | + $allBodyFields = ['route_id', 'route_name', 'member_id', 'schedule_uid', 'vehicle_id', 'name', |
|
| 486 | + 'schedule_blacklist', 'advance_schedule_interval_days', 'schedule', 'timezone', 'sync']; |
|
| 487 | + |
|
| 488 | + return Route4Me::makeRequst([ |
|
| 489 | + 'url' => Endpoint::RECURRING_ROUTES_MASTER_ROUTES, |
|
| 490 | + 'method' => 'POST', |
|
| 491 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
| 492 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
| 493 | + ]); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + private function toSchedule($result) : Schedule |
|
| 497 | + { |
|
| 498 | + if (is_array($result) && isset($result['data'])) { |
|
| 499 | + $data = $result['data']; |
|
| 500 | + if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 501 | + return new Schedule($data[0]); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + throw new ApiError('Can not convert result to Schedule object.'); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + private function toRouteSchedule($result) : RouteSchedule |
|
| 508 | + { |
|
| 509 | + if (is_array($result) && isset($result['data'])) { |
|
| 510 | + $data = $result['data']; |
|
| 511 | + if (is_array($data) && isset($data[0]) && is_array($data[0])) { |
|
| 512 | + return new RouteSchedule($data[0]); |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + throw new ApiError('Can not convert result to RouteSchedule object.'); |
|
| 516 | + } |
|
| 517 | 517 | } |