@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | $addresses = []; |
| 23 | 23 | foreach ($json as $address) { |
| 24 | - $addresses[] = Address::fromArray($address); |
|
| 24 | + $addresses[] = Address::fromArray($address); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | $bundling = new AddressBundling(); |
@@ -32,15 +32,15 @@ discard block |
||
| 32 | 32 | $bundling->service_time_rules->additional_items_mode = Enum\AddressBundlingModes\AdditionalItemsMode::KEEP_ORIGINAL; |
| 33 | 33 | |
| 34 | 34 | $parameters = RouteParameters::fromArray([ |
| 35 | - 'algorithm_type' => Algorithmtype::TSP, |
|
| 36 | - 'route_name' => 'Single Driver Multiple TimeWindows 12 Stops', |
|
| 37 | - 'route_date' => time() + 24 * 60 * 60, |
|
| 38 | - 'route_time' => 5 * 3600 + 30 * 60, |
|
| 39 | - 'distance_unit' => DistanceUnit::MILES, |
|
| 40 | - 'device_type' => DeviceType::WEB, |
|
| 41 | - 'optimize' => OptimizationType::DISTANCE, |
|
| 42 | - 'metric' => Metric::GEODESIC, |
|
| 43 | - 'bundling' => $bundling, |
|
| 35 | + 'algorithm_type' => Algorithmtype::TSP, |
|
| 36 | + 'route_name' => 'Single Driver Multiple TimeWindows 12 Stops', |
|
| 37 | + 'route_date' => time() + 24 * 60 * 60, |
|
| 38 | + 'route_time' => 5 * 3600 + 30 * 60, |
|
| 39 | + 'distance_unit' => DistanceUnit::MILES, |
|
| 40 | + 'device_type' => DeviceType::WEB, |
|
| 41 | + 'optimize' => OptimizationType::DISTANCE, |
|
| 42 | + 'metric' => Metric::GEODESIC, |
|
| 43 | + 'bundling' => $bundling, |
|
| 44 | 44 | ]); |
| 45 | 45 | |
| 46 | 46 | $optimizationParams = new OptimizationProblemParams(); |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | $problem = OptimizationProblem::optimize($optimizationParams); |
| 51 | 51 | |
| 52 | 52 | foreach ((array) $problem as $key => $value) { |
| 53 | - if (is_string($value)) { |
|
| 54 | - echo $key.' --> '.$value.'<br>'; |
|
| 55 | - } else { |
|
| 56 | - echo "************ $key ************* <br>"; |
|
| 57 | - Route4Me::simplePrint((array) $value, true); |
|
| 58 | - echo '******************************* <br>'; |
|
| 59 | - } |
|
| 53 | + if (is_string($value)) { |
|
| 54 | + echo $key.' --> '.$value.'<br>'; |
|
| 55 | + } else { |
|
| 56 | + echo "************ $key ************* <br>"; |
|
| 57 | + Route4Me::simplePrint((array) $value, true); |
|
| 58 | + echo '******************************* <br>'; |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -47,12 +47,12 @@ |
||
| 47 | 47 | |
| 48 | 48 | $problem = OptimizationProblem::optimize($optimizationParams); |
| 49 | 49 | |
| 50 | -foreach ((array) $problem as $key => $value) { |
|
| 50 | +foreach ((array)$problem as $key => $value) { |
|
| 51 | 51 | if (is_string($value)) { |
| 52 | 52 | echo $key.' --> '.$value.'<br>'; |
| 53 | 53 | } else { |
| 54 | 54 | echo "************ $key ************* <br>"; |
| 55 | - Route4Me::simplePrint((array) $value, true); |
|
| 55 | + Route4Me::simplePrint((array)$value, true); |
|
| 56 | 56 | echo '******************************* <br>'; |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -9,31 +9,31 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class AddressBundling extends Common |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Address bundling mode |
|
| 14 | - */ |
|
| 15 | - public $mode = AddressBundlingModes\Mode::ADDRESS; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * Address bundling mode parameters: |
|
| 19 | - * - If Mode=3, contains an array of the field names of the Address object; |
|
| 20 | - * - If Mode=4, contains an array of the custom fields of the Address object. |
|
| 21 | - */ |
|
| 22 | - public $mode_params= []; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Address bundling merge mode |
|
| 26 | - */ |
|
| 27 | - public $merge_mode = AddressBundlingModes\MergeMode::KEEP_AS_SEPARATE_DESTINATIONS; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Service time rules of the address bundling |
|
| 31 | - */ |
|
| 32 | - public $service_time_rules; |
|
| 33 | - |
|
| 34 | - public function __construct() |
|
| 35 | - { |
|
| 36 | - $this->service_time_rules = new ServiceTimeRulesClass(); |
|
| 37 | - } |
|
| 12 | + /** |
|
| 13 | + * Address bundling mode |
|
| 14 | + */ |
|
| 15 | + public $mode = AddressBundlingModes\Mode::ADDRESS; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * Address bundling mode parameters: |
|
| 19 | + * - If Mode=3, contains an array of the field names of the Address object; |
|
| 20 | + * - If Mode=4, contains an array of the custom fields of the Address object. |
|
| 21 | + */ |
|
| 22 | + public $mode_params= []; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Address bundling merge mode |
|
| 26 | + */ |
|
| 27 | + public $merge_mode = AddressBundlingModes\MergeMode::KEEP_AS_SEPARATE_DESTINATIONS; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Service time rules of the address bundling |
|
| 31 | + */ |
|
| 32 | + public $service_time_rules; |
|
| 33 | + |
|
| 34 | + public function __construct() |
|
| 35 | + { |
|
| 36 | + $this->service_time_rules = new ServiceTimeRulesClass(); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | } |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | * - If Mode=3, contains an array of the field names of the Address object; |
| 20 | 20 | * - If Mode=4, contains an array of the custom fields of the Address object. |
| 21 | 21 | */ |
| 22 | - public $mode_params= []; |
|
| 22 | + public $mode_params = []; |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * Address bundling merge mode |
@@ -582,70 +582,70 @@ |
||
| 582 | 582 | |
| 583 | 583 | if ('daily' != $mode) { |
| 584 | 584 | switch ($mode) { |
| 585 | - case 'weekly': |
|
| 586 | - if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) { |
|
| 587 | - if ($this->validateScheduleWeekDays($rows[$locationsFieldsMapping['schedule_weekdays']])) { |
|
| 588 | - $curSchedule .= '"weekdays":['.$rows[$locationsFieldsMapping['schedule_weekdays']].']}'; |
|
| 589 | - } else { |
|
| 590 | - array_push($results['fail'], "$iRow --> Wrong weekdays"); |
|
| 591 | - } |
|
| 585 | + case 'weekly': |
|
| 586 | + if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) { |
|
| 587 | + if ($this->validateScheduleWeekDays($rows[$locationsFieldsMapping['schedule_weekdays']])) { |
|
| 588 | + $curSchedule .= '"weekdays":['.$rows[$locationsFieldsMapping['schedule_weekdays']].']}'; |
|
| 589 | + } else { |
|
| 590 | + array_push($results['fail'], "$iRow --> Wrong weekdays"); |
|
| 591 | + } |
|
| 592 | + } else { |
|
| 593 | + array_push($results['fail'], "$iRow --> The parameters sched_weekdays is not set"); |
|
| 594 | + } |
|
| 595 | + break; |
|
| 596 | + case 'monthly': |
|
| 597 | + $monthlyMode = ''; |
|
| 598 | + if (isset($rows[$locationsFieldsMapping['monthly_mode']])) { |
|
| 599 | + if ($this->validateScheduleMonthlyMode($rows[$locationsFieldsMapping['monthly_mode']])) { |
|
| 600 | + $monthlyMode = $rows[$locationsFieldsMapping['monthly_mode']]; |
|
| 601 | + $curSchedule .= '"mode": "'.$rows[$locationsFieldsMapping['monthly_mode']].'",'; |
|
| 592 | 602 | } else { |
| 593 | - array_push($results['fail'], "$iRow --> The parameters sched_weekdays is not set"); |
|
| 603 | + array_push($results['fail'], "$iRow --> Wrong monthly mode"); |
|
| 604 | + } |
|
| 605 | + } else { |
|
| 606 | + array_push($results['fail'], "$iRow --> The parameter sched_monthly_mode is not set"); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if ('' != $monthlyMode) { |
|
| 610 | + switch ($monthlyMode) { |
|
| 611 | + case 'dates': |
|
| 612 | + if (isset($rows[$locationsFieldsMapping['monthly_dates']])) { |
|
| 613 | + if ($this->validateScheduleMonthlyDates($rows[$locationsFieldsMapping['monthly_dates']])) { |
|
| 614 | + $curSchedule .= '"dates":['.$rows[$locationsFieldsMapping['monthly_dates']].']}'; |
|
| 615 | + } else { |
|
| 616 | + array_push($results['fail'], "$iRow --> Wrong monthly dates"); |
|
| 617 | + } |
|
| 594 | 618 | } |
| 595 | 619 | break; |
| 596 | - case 'monthly': |
|
| 597 | - $monthlyMode = ''; |
|
| 598 | - if (isset($rows[$locationsFieldsMapping['monthly_mode']])) { |
|
| 599 | - if ($this->validateScheduleMonthlyMode($rows[$locationsFieldsMapping['monthly_mode']])) { |
|
| 600 | - $monthlyMode = $rows[$locationsFieldsMapping['monthly_mode']]; |
|
| 601 | - $curSchedule .= '"mode": "'.$rows[$locationsFieldsMapping['monthly_mode']].'",'; |
|
| 602 | - } else { |
|
| 603 | - array_push($results['fail'], "$iRow --> Wrong monthly mode"); |
|
| 604 | - } |
|
| 620 | + case 'nth': |
|
| 621 | + if (isset($rows[$locationsFieldsMapping['monthly_nth_n']])) { |
|
| 622 | + if ($this->validateScheduleNthN($rows[$locationsFieldsMapping['monthly_nth_n']])) { |
|
| 623 | + $curSchedule .= '"nth":{"n":'.$rows[$locationsFieldsMapping['monthly_nth_n']].','; |
|
| 605 | 624 | } else { |
| 606 | - array_push($results['fail'], "$iRow --> The parameter sched_monthly_mode is not set"); |
|
| 625 | + array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_n"); |
|
| 626 | + } |
|
| 627 | + } else { |
|
| 628 | + array_push($results['fail'], "$iRow --> The parameter sched_nth_n is not set"); |
|
| 607 | 629 | } |
| 608 | 630 | |
| 609 | - if ('' != $monthlyMode) { |
|
| 610 | - switch ($monthlyMode) { |
|
| 611 | - case 'dates': |
|
| 612 | - if (isset($rows[$locationsFieldsMapping['monthly_dates']])) { |
|
| 613 | - if ($this->validateScheduleMonthlyDates($rows[$locationsFieldsMapping['monthly_dates']])) { |
|
| 614 | - $curSchedule .= '"dates":['.$rows[$locationsFieldsMapping['monthly_dates']].']}'; |
|
| 615 | - } else { |
|
| 616 | - array_push($results['fail'], "$iRow --> Wrong monthly dates"); |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - break; |
|
| 620 | - case 'nth': |
|
| 621 | - if (isset($rows[$locationsFieldsMapping['monthly_nth_n']])) { |
|
| 622 | - if ($this->validateScheduleNthN($rows[$locationsFieldsMapping['monthly_nth_n']])) { |
|
| 623 | - $curSchedule .= '"nth":{"n":'.$rows[$locationsFieldsMapping['monthly_nth_n']].','; |
|
| 624 | - } else { |
|
| 625 | - array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_n"); |
|
| 626 | - } |
|
| 627 | - } else { |
|
| 628 | - array_push($results['fail'], "$iRow --> The parameter sched_nth_n is not set"); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - if ('' != $curSchedule) { |
|
| 632 | - if (isset($rows[$locationsFieldsMapping['monthly_nth_what']])) { |
|
| 633 | - if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_what']])) { |
|
| 634 | - $curSchedule .= '"what":'.$rows[$locationsFieldsMapping['monthly_nth_what']].'}}'; |
|
| 635 | - } else { |
|
| 636 | - array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_what"); |
|
| 637 | - } |
|
| 638 | - } else { |
|
| 639 | - array_push($results['fail'], "$iRow --> The parameter sched_nth_what is not set"); |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - break; |
|
| 631 | + if ('' != $curSchedule) { |
|
| 632 | + if (isset($rows[$locationsFieldsMapping['monthly_nth_what']])) { |
|
| 633 | + if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_what']])) { |
|
| 634 | + $curSchedule .= '"what":'.$rows[$locationsFieldsMapping['monthly_nth_what']].'}}'; |
|
| 635 | + } else { |
|
| 636 | + array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_what"); |
|
| 643 | 637 | } |
| 638 | + } else { |
|
| 639 | + array_push($results['fail'], "$iRow --> The parameter sched_nth_what is not set"); |
|
| 640 | + } |
|
| 644 | 641 | } |
| 645 | 642 | break; |
| 646 | - default: |
|
| 647 | - $curSchedule = ''; |
|
| 643 | + } |
|
| 644 | + } |
|
| 648 | 645 | break; |
| 646 | + default: |
|
| 647 | + $curSchedule = ''; |
|
| 648 | + break; |
|
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | if (isset($ablocations['results'])) { |
| 325 | 325 | $locationsSize = sizeof($ablocations['results']); |
| 326 | 326 | |
| 327 | - if ($locationsSize > 0) { |
|
| 327 | + if ($locationsSize>0) { |
|
| 328 | 328 | $randomLocationIndex = rand(0, $locationsSize - 1); |
| 329 | 329 | |
| 330 | 330 | return $ablocations['results'][$randomLocationIndex]; |
@@ -394,9 +394,9 @@ discard block |
||
| 394 | 394 | if (strtolower($scheduleEnabled)=="false") $scheduleEnabled = false; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - $schedEnables = [true, false,]; |
|
| 397 | + $schedEnables = [true, false, ]; |
|
| 398 | 398 | |
| 399 | - if (in_array($scheduleEnabled, $schedEnables,true)) { |
|
| 399 | + if (in_array($scheduleEnabled, $schedEnables, true)) { |
|
| 400 | 400 | return true; |
| 401 | 401 | } else { |
| 402 | 402 | return false; |
@@ -423,18 +423,18 @@ discard block |
||
| 423 | 423 | $weekdays = explode(',', $scheduleWeekDays); |
| 424 | 424 | $weekdaysSize = sizeof($weekdays); |
| 425 | 425 | |
| 426 | - if ($weekdaysSize < 1) { |
|
| 426 | + if ($weekdaysSize<1) { |
|
| 427 | 427 | return false; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | $isValid = true; |
| 431 | 431 | |
| 432 | - for ($i = 0; $i < $weekdaysSize; ++$i) { |
|
| 432 | + for ($i = 0; $i<$weekdaysSize; ++$i) { |
|
| 433 | 433 | if (is_bool($weekdays[$i])) { |
| 434 | 434 | $isValid = false; |
| 435 | 435 | } elseif (is_numeric($weekdays[$i])) { |
| 436 | 436 | $wday = intval($weekdays[$i]); |
| 437 | - if ($wday < 1 || $wday > 7) { |
|
| 437 | + if ($wday<1 || $wday>7) { |
|
| 438 | 438 | $isValid = false; |
| 439 | 439 | } |
| 440 | 440 | } else { |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | { |
| 450 | 450 | $schedMonthlyMmodes = ['dates', 'nth']; |
| 451 | 451 | |
| 452 | - if (in_array($scheduleMonthlyMode, $schedMonthlyMmodes,true)) { |
|
| 452 | + if (in_array($scheduleMonthlyMode, $schedMonthlyMmodes, true)) { |
|
| 453 | 453 | return true; |
| 454 | 454 | } else { |
| 455 | 455 | return false; |
@@ -463,16 +463,16 @@ discard block |
||
| 463 | 463 | $monthlyDates = explode(',', $scheduleMonthlyDates); |
| 464 | 464 | $monthlyDatesSize = sizeof($monthlyDates); |
| 465 | 465 | |
| 466 | - if ($monthlyDatesSize < 1) { |
|
| 466 | + if ($monthlyDatesSize<1) { |
|
| 467 | 467 | return false; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | $isValid = true; |
| 471 | 471 | |
| 472 | - for ($i = 0; $i < $monthlyDatesSize; ++$i) { |
|
| 472 | + for ($i = 0; $i<$monthlyDatesSize; ++$i) { |
|
| 473 | 473 | if (is_numeric($monthlyDates[$i])) { |
| 474 | 474 | $mday = intval($monthlyDates[$i]); |
| 475 | - if ($mday < 1 || $mday > 31) { |
|
| 475 | + if ($mday<1 || $mday>31) { |
|
| 476 | 476 | $isValid = false; |
| 477 | 477 | } |
| 478 | 478 | } else { |
@@ -538,9 +538,9 @@ discard block |
||
| 538 | 538 | |
| 539 | 539 | $iRow = 1; |
| 540 | 540 | |
| 541 | - while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) { |
|
| 541 | + while (false!==($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) { |
|
| 542 | 542 | if (!isset($rows[$locationsFieldsMapping['cached_lat']]) || !isset($rows[$locationsFieldsMapping['cached_lng']]) |
| 543 | - || !isset($rows[$locationsFieldsMapping['address_1']]) || [null] == $rows) { |
|
| 543 | + || !isset($rows[$locationsFieldsMapping['address_1']]) || [null]==$rows) { |
|
| 544 | 544 | continue; |
| 545 | 545 | } |
| 546 | 546 | |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | if (isset($rows[$locationsFieldsMapping['schedule_every']])) { |
| 572 | 572 | if ($this->validateScheduleEvery($rows[$locationsFieldsMapping['schedule_every']])) { |
| 573 | 573 | $curSchedule .= '"'.$mode.'":{'.'"every":'.$rows[$locationsFieldsMapping['schedule_every']].','; |
| 574 | - if ('daily' == $mode) { |
|
| 574 | + if ('daily'==$mode) { |
|
| 575 | 575 | $curSchedule = trim($curSchedule, ','); |
| 576 | 576 | $curSchedule .= '}'; |
| 577 | 577 | } |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | } |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - if ('daily' != $mode) { |
|
| 583 | + if ('daily'!=$mode) { |
|
| 584 | 584 | switch ($mode) { |
| 585 | 585 | case 'weekly': |
| 586 | 586 | if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) { |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | array_push($results['fail'], "$iRow --> The parameter sched_monthly_mode is not set"); |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - if ('' != $monthlyMode) { |
|
| 609 | + if (''!=$monthlyMode) { |
|
| 610 | 610 | switch ($monthlyMode) { |
| 611 | 611 | case 'dates': |
| 612 | 612 | if (isset($rows[$locationsFieldsMapping['monthly_dates']])) { |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | array_push($results['fail'], "$iRow --> The parameter sched_nth_n is not set"); |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - if ('' != $curSchedule) { |
|
| 631 | + if (''!=$curSchedule) { |
|
| 632 | 632 | if (isset($rows[$locationsFieldsMapping['monthly_nth_what']])) { |
| 633 | 633 | if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_what']])) { |
| 634 | 634 | $curSchedule .= '"what":'.$rows[$locationsFieldsMapping['monthly_nth_what']].'}}'; |
@@ -649,11 +649,11 @@ discard block |
||
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - if (sizeof($results['fail']) > $failCount) { |
|
| 652 | + if (sizeof($results['fail'])>$failCount) { |
|
| 653 | 653 | $curSchedule = ''; |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | - if (('daily' == $mode || 'weekly' == $mode || 'monthy' == $mode) && '' == $curSchedule) { |
|
| 656 | + if (('daily'==$mode || 'weekly'==$mode || 'monthy'==$mode) && ''==$curSchedule) { |
|
| 657 | 657 | ++$iRow; |
| 658 | 658 | continue; |
| 659 | 659 | } |
@@ -390,8 +390,12 @@ discard block |
||
| 390 | 390 | public static function validateScheduleEnable($scheduleEnabled) |
| 391 | 391 | { |
| 392 | 392 | if (is_string($scheduleEnabled)) { |
| 393 | - if (strtolower($scheduleEnabled)=="true") $scheduleEnabled = true; |
|
| 394 | - if (strtolower($scheduleEnabled)=="false") $scheduleEnabled = false; |
|
| 393 | + if (strtolower($scheduleEnabled)=="true") { |
|
| 394 | + $scheduleEnabled = true; |
|
| 395 | + } |
|
| 396 | + if (strtolower($scheduleEnabled)=="false") { |
|
| 397 | + $scheduleEnabled = false; |
|
| 398 | + } |
|
| 395 | 399 | } |
| 396 | 400 | |
| 397 | 401 | $schedEnables = [true, false,]; |
@@ -418,7 +422,9 @@ discard block |
||
| 418 | 422 | |
| 419 | 423 | public static function validateScheduleWeekDays($scheduleWeekDays) |
| 420 | 424 | { |
| 421 | - if (is_bool($scheduleWeekDays)) return false; |
|
| 425 | + if (is_bool($scheduleWeekDays)) { |
|
| 426 | + return false; |
|
| 427 | + } |
|
| 422 | 428 | |
| 423 | 429 | $weekdays = explode(',', $scheduleWeekDays); |
| 424 | 430 | $weekdaysSize = sizeof($weekdays); |
@@ -458,7 +464,9 @@ discard block |
||
| 458 | 464 | |
| 459 | 465 | public static function validateScheduleMonthlyDates($scheduleMonthlyDates) |
| 460 | 466 | { |
| 461 | - if (is_bool($scheduleMonthlyDates)) return false; |
|
| 467 | + if (is_bool($scheduleMonthlyDates)) { |
|
| 468 | + return false; |
|
| 469 | + } |
|
| 462 | 470 | |
| 463 | 471 | $monthlyDates = explode(',', $scheduleMonthlyDates); |
| 464 | 472 | $monthlyDatesSize = sizeof($monthlyDates); |
@@ -14,687 +14,687 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class AddressBookLocation extends Common |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * A territory shape name the contact belongs. |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $address_id; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * A group the contact belongs. |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - public $address_group; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * The contact's alias. |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - public $address_alias; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * The geographic address of the contact. |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - public $address_1; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Second geographic address of the contact. |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - public $address_2; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * The first name of the contact person. |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - public $first_name; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * The last name of the contact person. |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 57 | - public $last_name; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * The contact's email. |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $address_email; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * The contact's phone number. |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - public $address_phone_number; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * A city the contact belongs. |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - public $address_city; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * The ID of the state the contact belongs. |
|
| 79 | - * @var string |
|
| 80 | - */ |
|
| 81 | - public $address_state_id; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * The ID of the country the contact belongs. |
|
| 85 | - * @var string |
|
| 86 | - */ |
|
| 87 | - public $address_country_id; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * The contact's ZIP code. |
|
| 91 | - * @var string |
|
| 92 | - */ |
|
| 93 | - public $address_zip; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * A latitude of the contact's cached position. |
|
| 97 | - * @var double |
|
| 98 | - */ |
|
| 99 | - public $cached_lat; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * A longitude of the contact's cached position. |
|
| 103 | - * @var double |
|
| 104 | - */ |
|
| 105 | - public $cached_lng; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * A latitude of the contact's curbside. |
|
| 109 | - * @var double |
|
| 110 | - */ |
|
| 111 | - public $curbside_lat; |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * A longitude of the contact's curbside. |
|
| 115 | - * @var double |
|
| 116 | - */ |
|
| 117 | - public $curbside_lng; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * The contact's color on the map. |
|
| 121 | - * @var string |
|
| 122 | - */ |
|
| 123 | - public $color; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * An array of the contact's custom field-value pairs. |
|
| 127 | - * @var array |
|
| 128 | - */ |
|
| 129 | - public $address_custom_data; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * An array of the contact's schedules. |
|
| 133 | - * @var Schedule[] |
|
| 134 | - */ |
|
| 135 | - public $schedule; |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Time when the contact was created. |
|
| 139 | - * @var long |
|
| 140 | - */ |
|
| 141 | - public $created_timestamp; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Unique ID of the member. |
|
| 145 | - * @var integer |
|
| 146 | - */ |
|
| 147 | - public $member_id; |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * The list of dates that should be omitted from the schedules. |
|
| 151 | - * @var string[] |
|
| 152 | - */ |
|
| 153 | - public $schedule_blacklist; |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Number of the routes containing the contact. |
|
| 157 | - * @var integer |
|
| 158 | - */ |
|
| 159 | - public $in_route_count; |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * When the contact was last visited. |
|
| 163 | - * @var long |
|
| 164 | - */ |
|
| 165 | - public $last_visited_timestamp; |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * When the contact was last routed. |
|
| 169 | - * @var long |
|
| 170 | - */ |
|
| 171 | - public $last_routed_timestamp; |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Start of the contact's local time window. |
|
| 175 | - * @var long |
|
| 176 | - */ |
|
| 177 | - public $local_time_window_start; |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * End of the contact's local time window. |
|
| 181 | - * @var long |
|
| 182 | - */ |
|
| 183 | - public $local_time_window_end; |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Start of the contact's second local time window. |
|
| 187 | - * @var long |
|
| 188 | - */ |
|
| 189 | - public $local_time_window_start_2; |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * End of the contact's second local time window. |
|
| 193 | - * @var long |
|
| 194 | - */ |
|
| 195 | - public $local_time_window_end_2; |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * The service time at the contact's address. |
|
| 199 | - * @var integer |
|
| 200 | - */ |
|
| 201 | - public $service_time; |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * The contact's local timezone. |
|
| 205 | - * @var string |
|
| 206 | - */ |
|
| 207 | - public $local_timezone_string; |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * The contact's icon on the map. |
|
| 211 | - * @var string |
|
| 212 | - */ |
|
| 213 | - public $address_icon; |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * The contact's stop type. |
|
| 217 | - * @var string |
|
| 218 | - */ |
|
| 219 | - public $address_stop_type; |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * The cubic volume of the contact's cargo. |
|
| 223 | - * @var double |
|
| 224 | - */ |
|
| 225 | - public $address_cube; |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * The number of pieces/pallets that this destination/order/line-item consumes/contains on a vehicle. |
|
| 229 | - * @var integer |
|
| 230 | - */ |
|
| 231 | - public $address_pieces; |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * The reference number of the address. |
|
| 235 | - * @var string |
|
| 236 | - */ |
|
| 237 | - public $address_reference_no; |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * The revenue from the contact. |
|
| 241 | - * @var double |
|
| 242 | - */ |
|
| 243 | - public $address_revenue; |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * The weight of the contact's cargo. |
|
| 247 | - * @var double |
|
| 248 | - */ |
|
| 249 | - public $address_weight; |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * If present, the priority will sequence addresses in all the optimal routes so that |
|
| 253 | - * higher priority addresses are general at the beginning of the route sequence.<br> |
|
| 254 | - * 1 is the highest priority, 100000 is the lowest. |
|
| 255 | - * @var integer |
|
| 256 | - */ |
|
| 257 | - public $address_priority; |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * The customer purchase order of the contact. |
|
| 261 | - * @var string |
|
| 262 | - */ |
|
| 263 | - public $address_customer_po; |
|
| 264 | - |
|
| 265 | - public function __construct() |
|
| 266 | - { |
|
| 267 | - Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * @deprecated 1.2.8 |
|
| 272 | - * @see \Route4Me\V5\AddressBook\AddressBook::getAddressById() |
|
| 273 | - */ |
|
| 274 | - public static function getAddressBookLocation($addressId) |
|
| 275 | - { |
|
| 276 | - $ablocations = Route4Me::makeRequst([ |
|
| 277 | - 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 278 | - 'method' => 'GET', |
|
| 279 | - 'query' => [ |
|
| 280 | - 'query' => $addressId, |
|
| 281 | - 'limit' => 30, |
|
| 282 | - ], |
|
| 283 | - ]); |
|
| 284 | - |
|
| 285 | - return $ablocations; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @deprecated 1.2.8 |
|
| 290 | - * @see \Route4Me\V5\AddressBook\AddressBook::getAddressesByBodyPayload() |
|
| 291 | - */ |
|
| 292 | - public static function searchAddressBookLocations($params) |
|
| 293 | - { |
|
| 294 | - $allQueryFields = ['display', 'query', 'fields', 'limit', 'offset']; |
|
| 295 | - |
|
| 296 | - $result = Route4Me::makeRequst([ |
|
| 297 | - 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 298 | - 'method' => 'GET', |
|
| 299 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 300 | - ]); |
|
| 301 | - |
|
| 302 | - return $result; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @deprecated 1.2.8 |
|
| 307 | - * @see \Route4Me\V5\AddressBook\AddressBook::getAddressesByIds() |
|
| 308 | - */ |
|
| 309 | - public static function getAddressBookLocations($params) |
|
| 310 | - { |
|
| 311 | - $allQueryFields = ['limit', 'offset', 'address_id']; |
|
| 312 | - |
|
| 313 | - $ablocations = Route4Me::makeRequst([ |
|
| 314 | - 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 315 | - 'method' => 'GET', |
|
| 316 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 317 | - ]); |
|
| 318 | - |
|
| 319 | - return $ablocations; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - public static function getRandomAddressBookLocation($params) |
|
| 323 | - { |
|
| 324 | - $ablocations = self::getAddressBookLocations($params); |
|
| 325 | - |
|
| 326 | - if (isset($ablocations['results'])) { |
|
| 327 | - $locationsSize = sizeof($ablocations['results']); |
|
| 328 | - |
|
| 329 | - if ($locationsSize > 0) { |
|
| 330 | - $randomLocationIndex = rand(0, $locationsSize - 1); |
|
| 331 | - |
|
| 332 | - return $ablocations['results'][$randomLocationIndex]; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - return null; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * @deprecated 1.2.8 |
|
| 341 | - * @see \Route4Me\V5\AddressBook\AddressBook::addAddress() |
|
| 342 | - * |
|
| 343 | - * @param AddressBookLocation $params |
|
| 344 | - */ |
|
| 345 | - public static function addAdressBookLocation($params) |
|
| 346 | - { |
|
| 347 | - $allBodyFields = Route4Me::getObjectProperties(new self(), ['address_id', 'in_route_count']); |
|
| 348 | - |
|
| 349 | - $response = Route4Me::makeRequst([ |
|
| 350 | - 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 351 | - 'method' => 'POST', |
|
| 352 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 353 | - ]); |
|
| 354 | - |
|
| 355 | - return $response; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @deprecated 1.2.8 |
|
| 360 | - * @see \Route4Me\V5\AddressBook\AddressBook::deleteAddressesByIds() |
|
| 361 | - */ |
|
| 362 | - public function deleteAdressBookLocation($address_ids) |
|
| 363 | - { |
|
| 364 | - $result = Route4Me::makeRequst([ |
|
| 365 | - 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 366 | - 'method' => 'DELETEARRAY', |
|
| 367 | - 'query' => [ |
|
| 368 | - 'address_ids' => $address_ids, |
|
| 369 | - ], |
|
| 370 | - ]); |
|
| 371 | - |
|
| 372 | - return $result; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * @deprecated 1.2.8 |
|
| 377 | - * @see \Route4Me\V5\AddressBook\AddressBook::updateAddressById() |
|
| 378 | - */ |
|
| 379 | - public function updateAddressBookLocation($params) |
|
| 380 | - { |
|
| 381 | - $allBodyFields = Route4Me::getObjectProperties(new self(), ['in_route_count']); |
|
| 382 | - |
|
| 383 | - $response = Route4Me::makeRequst([ |
|
| 384 | - 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 385 | - 'method' => 'PUT', |
|
| 386 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 387 | - ]); |
|
| 388 | - |
|
| 389 | - return $response; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - public static function validateScheduleMode($scheduleMode) |
|
| 393 | - { |
|
| 394 | - $schedModes = ['daily', 'weekly', 'monthly', 'annually']; |
|
| 395 | - |
|
| 396 | - if (in_array($scheduleMode, $schedModes)) { |
|
| 397 | - return true; |
|
| 398 | - } else { |
|
| 399 | - return false; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - public static function validateScheduleEnable($scheduleEnabled) |
|
| 404 | - { |
|
| 405 | - if (is_string($scheduleEnabled)) { |
|
| 406 | - if (strtolower($scheduleEnabled)=="true") $scheduleEnabled = true; |
|
| 407 | - if (strtolower($scheduleEnabled)=="false") $scheduleEnabled = false; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - $schedEnables = [true, false,]; |
|
| 411 | - |
|
| 412 | - if (in_array($scheduleEnabled, $schedEnables,true)) { |
|
| 413 | - return true; |
|
| 414 | - } else { |
|
| 415 | - return false; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - public static function validateScheduleEvery($scheduleEvery) |
|
| 420 | - { |
|
| 421 | - if (is_numeric($scheduleEvery)) { |
|
| 422 | - if ($scheduleEvery>0) { |
|
| 423 | - return true; |
|
| 424 | - } else { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - } else { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - public static function validateScheduleWeekDays($scheduleWeekDays) |
|
| 433 | - { |
|
| 434 | - if (is_bool($scheduleWeekDays)) return false; |
|
| 435 | - |
|
| 436 | - $weekdays = explode(',', $scheduleWeekDays); |
|
| 437 | - $weekdaysSize = sizeof($weekdays); |
|
| 438 | - |
|
| 439 | - if ($weekdaysSize < 1) { |
|
| 440 | - return false; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - $isValid = true; |
|
| 444 | - |
|
| 445 | - for ($i = 0; $i < $weekdaysSize; ++$i) { |
|
| 446 | - if (is_bool($weekdays[$i])) { |
|
| 447 | - $isValid = false; |
|
| 448 | - } elseif (is_numeric($weekdays[$i])) { |
|
| 449 | - $wday = intval($weekdays[$i]); |
|
| 450 | - if ($wday < 1 || $wday > 7) { |
|
| 451 | - $isValid = false; |
|
| 452 | - } |
|
| 453 | - } else { |
|
| 454 | - $isValid = false; |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - return $isValid; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - public static function validateScheduleMonthlyMode($scheduleMonthlyMode) |
|
| 462 | - { |
|
| 463 | - $schedMonthlyMmodes = ['dates', 'nth']; |
|
| 464 | - |
|
| 465 | - if (in_array($scheduleMonthlyMode, $schedMonthlyMmodes,true)) { |
|
| 466 | - return true; |
|
| 467 | - } else { |
|
| 468 | - return false; |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - public static function validateScheduleMonthlyDates($scheduleMonthlyDates) |
|
| 473 | - { |
|
| 474 | - if (is_bool($scheduleMonthlyDates)) return false; |
|
| 475 | - |
|
| 476 | - $monthlyDates = explode(',', $scheduleMonthlyDates); |
|
| 477 | - $monthlyDatesSize = sizeof($monthlyDates); |
|
| 478 | - |
|
| 479 | - if ($monthlyDatesSize < 1) { |
|
| 480 | - return false; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - $isValid = true; |
|
| 484 | - |
|
| 485 | - for ($i = 0; $i < $monthlyDatesSize; ++$i) { |
|
| 486 | - if (is_numeric($monthlyDates[$i])) { |
|
| 487 | - $mday = intval($monthlyDates[$i]); |
|
| 488 | - if ($mday < 1 || $mday > 31) { |
|
| 489 | - $isValid = false; |
|
| 490 | - } |
|
| 491 | - } else { |
|
| 492 | - $isValid = false; |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $isValid; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - public static function validateScheduleNthN($scheduleNthN) |
|
| 500 | - { |
|
| 501 | - if (!is_numeric($scheduleNthN)) { |
|
| 502 | - return false; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - $schedNthNs = [1, 2, 3, 4, 5, -1]; |
|
| 506 | - |
|
| 507 | - if (in_array($scheduleNthN, $schedNthNs)) { |
|
| 508 | - return true; |
|
| 509 | - } else { |
|
| 510 | - return false; |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - public static function validateScheduleNthWhat($scheduleNthWhat) |
|
| 515 | - { |
|
| 516 | - if (!is_numeric($scheduleNthWhat)) { |
|
| 517 | - return false; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - $schedNthWhats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
|
| 521 | - |
|
| 522 | - if (in_array($scheduleNthWhat, $schedNthWhats)) { |
|
| 523 | - return true; |
|
| 524 | - } else { |
|
| 525 | - return false; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** Function adds the locations (with/without schedule) from the CSV file. |
|
| 530 | - * $csvFileHandle - a file handler. |
|
| 531 | - * Returns array $results which contains two arrays: fail and succes. |
|
| 532 | - */ |
|
| 533 | - public function addLocationsFromCsvFile($csvFileHandle, $locationsFieldsMapping) |
|
| 534 | - { |
|
| 535 | - $max_line_length = 512; |
|
| 536 | - $delemietr = ','; |
|
| 537 | - |
|
| 538 | - $results = []; |
|
| 539 | - $results['fail'] = []; |
|
| 540 | - $results['success'] = []; |
|
| 541 | - |
|
| 542 | - $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr); |
|
| 543 | - |
|
| 544 | - $addressBookFields = Route4Me::getObjectProperties(new self(), ['address_id', 'in_route_count']); |
|
| 545 | - |
|
| 546 | - if (empty($columns)) { |
|
| 547 | - array_push($results['fail'], 'Empty CSV table'); |
|
| 548 | - |
|
| 549 | - return $results; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - $iRow = 1; |
|
| 553 | - |
|
| 554 | - while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) { |
|
| 555 | - if (!isset($rows[$locationsFieldsMapping['cached_lat']]) || !isset($rows[$locationsFieldsMapping['cached_lng']]) |
|
| 556 | - || !isset($rows[$locationsFieldsMapping['address_1']]) || [null] == $rows) { |
|
| 557 | - continue; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - $curSchedule = ''; |
|
| 561 | - $mode = ''; |
|
| 562 | - |
|
| 563 | - $failCount = sizeof($results['fail']); |
|
| 564 | - |
|
| 565 | - if (isset($rows[$locationsFieldsMapping['schedule_mode']])) { |
|
| 566 | - if ($this->validateScheduleMode($rows[$locationsFieldsMapping['schedule_mode']])) { |
|
| 567 | - $curSchedule = '"mode":"'.$rows[$locationsFieldsMapping['schedule_mode']].'",'; |
|
| 568 | - $mode = $rows[$locationsFieldsMapping['schedule_mode']]; |
|
| 569 | - } else { |
|
| 570 | - array_push($results['fail'], "$iRow --> Wrong schedule mode parameter"); |
|
| 571 | - } |
|
| 572 | - } else { |
|
| 573 | - array_push($results['fail'], "$iRow --> The schedule mode parameter is not set"); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - if (isset($rows[$locationsFieldsMapping['schedule_enabled']])) { |
|
| 577 | - if ($this->validateScheduleEnable($rows[$locationsFieldsMapping['schedule_enabled']])) { |
|
| 578 | - $curSchedule .= '"enabled":'.$rows[$locationsFieldsMapping['schedule_enabled']].','; |
|
| 579 | - } else { |
|
| 580 | - array_push($results['fail'], "$iRow --> The schedule enabled parameter is not set "); |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - if (isset($rows[$locationsFieldsMapping['schedule_every']])) { |
|
| 585 | - if ($this->validateScheduleEvery($rows[$locationsFieldsMapping['schedule_every']])) { |
|
| 586 | - $curSchedule .= '"'.$mode.'":{'.'"every":'.$rows[$locationsFieldsMapping['schedule_every']].','; |
|
| 587 | - if ('daily' == $mode) { |
|
| 588 | - $curSchedule = trim($curSchedule, ','); |
|
| 589 | - $curSchedule .= '}'; |
|
| 590 | - } |
|
| 591 | - } else { |
|
| 592 | - array_push($results['fail'], "$iRow --> The parameter sched_every is not set"); |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if ('daily' != $mode) { |
|
| 597 | - switch ($mode) { |
|
| 598 | - case 'weekly': |
|
| 599 | - if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) { |
|
| 600 | - if ($this->validateScheduleWeekDays($rows[$locationsFieldsMapping['schedule_weekdays']])) { |
|
| 601 | - $curSchedule .= '"weekdays":['.$rows[$locationsFieldsMapping['schedule_weekdays']].']}'; |
|
| 602 | - } else { |
|
| 603 | - array_push($results['fail'], "$iRow --> Wrong weekdays"); |
|
| 604 | - } |
|
| 605 | - } else { |
|
| 606 | - array_push($results['fail'], "$iRow --> The parameters sched_weekdays is not set"); |
|
| 607 | - } |
|
| 608 | - break; |
|
| 609 | - case 'monthly': |
|
| 610 | - $monthlyMode = ''; |
|
| 611 | - if (isset($rows[$locationsFieldsMapping['monthly_mode']])) { |
|
| 612 | - if ($this->validateScheduleMonthlyMode($rows[$locationsFieldsMapping['monthly_mode']])) { |
|
| 613 | - $monthlyMode = $rows[$locationsFieldsMapping['monthly_mode']]; |
|
| 614 | - $curSchedule .= '"mode": "'.$rows[$locationsFieldsMapping['monthly_mode']].'",'; |
|
| 615 | - } else { |
|
| 616 | - array_push($results['fail'], "$iRow --> Wrong monthly mode"); |
|
| 617 | - } |
|
| 618 | - } else { |
|
| 619 | - array_push($results['fail'], "$iRow --> The parameter sched_monthly_mode is not set"); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - if ('' != $monthlyMode) { |
|
| 623 | - switch ($monthlyMode) { |
|
| 624 | - case 'dates': |
|
| 625 | - if (isset($rows[$locationsFieldsMapping['monthly_dates']])) { |
|
| 626 | - if ($this->validateScheduleMonthlyDates($rows[$locationsFieldsMapping['monthly_dates']])) { |
|
| 627 | - $curSchedule .= '"dates":['.$rows[$locationsFieldsMapping['monthly_dates']].']}'; |
|
| 628 | - } else { |
|
| 629 | - array_push($results['fail'], "$iRow --> Wrong monthly dates"); |
|
| 630 | - } |
|
| 631 | - } |
|
| 632 | - break; |
|
| 633 | - case 'nth': |
|
| 634 | - if (isset($rows[$locationsFieldsMapping['monthly_nth_n']])) { |
|
| 635 | - if ($this->validateScheduleNthN($rows[$locationsFieldsMapping['monthly_nth_n']])) { |
|
| 636 | - $curSchedule .= '"nth":{"n":'.$rows[$locationsFieldsMapping['monthly_nth_n']].','; |
|
| 637 | - } else { |
|
| 638 | - array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_n"); |
|
| 639 | - } |
|
| 640 | - } else { |
|
| 641 | - array_push($results['fail'], "$iRow --> The parameter sched_nth_n is not set"); |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - if ('' != $curSchedule) { |
|
| 645 | - if (isset($rows[$locationsFieldsMapping['monthly_nth_what']])) { |
|
| 646 | - if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_what']])) { |
|
| 647 | - $curSchedule .= '"what":'.$rows[$locationsFieldsMapping['monthly_nth_what']].'}}'; |
|
| 648 | - } else { |
|
| 649 | - array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_what"); |
|
| 650 | - } |
|
| 651 | - } else { |
|
| 652 | - array_push($results['fail'], "$iRow --> The parameter sched_nth_what is not set"); |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - break; |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - break; |
|
| 659 | - default: |
|
| 660 | - $curSchedule = ''; |
|
| 661 | - break; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - if (sizeof($results['fail']) > $failCount) { |
|
| 666 | - $curSchedule = ''; |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - if (('daily' == $mode || 'weekly' == $mode || 'monthy' == $mode) && '' == $curSchedule) { |
|
| 670 | - ++$iRow; |
|
| 671 | - continue; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - $curSchedule = strtolower($curSchedule); |
|
| 675 | - |
|
| 676 | - $curSchedule = '[{'.$curSchedule.'}]'; |
|
| 677 | - |
|
| 678 | - $parametersArray = []; |
|
| 679 | - |
|
| 680 | - foreach ($addressBookFields as $addressBookField) { |
|
| 681 | - if (isset($locationsFieldsMapping[$addressBookField])) { |
|
| 682 | - $parametersArray[$addressBookField] = $rows[$locationsFieldsMapping[$addressBookField]]; |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - $AdressBookLocationParameters = self::fromArray($parametersArray); |
|
| 687 | - |
|
| 688 | - $abContacts = new self(); |
|
| 689 | - |
|
| 690 | - $abcResults = $abContacts->addAdressBookLocation($AdressBookLocationParameters); //temporarry |
|
| 691 | - |
|
| 692 | - array_push( |
|
| 693 | - $results['success'], |
|
| 694 | - 'The schedule location with address_id = '.strval($abcResults['address_id']).' added successfuly.' |
|
| 695 | - ); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - return $results; |
|
| 699 | - } |
|
| 17 | + /** |
|
| 18 | + * A territory shape name the contact belongs. |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $address_id; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * A group the contact belongs. |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + public $address_group; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * The contact's alias. |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + public $address_alias; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * The geographic address of the contact. |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + public $address_1; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Second geographic address of the contact. |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + public $address_2; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * The first name of the contact person. |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + public $first_name; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * The last name of the contact person. |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | + public $last_name; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * The contact's email. |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $address_email; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * The contact's phone number. |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + public $address_phone_number; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * A city the contact belongs. |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + public $address_city; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * The ID of the state the contact belongs. |
|
| 79 | + * @var string |
|
| 80 | + */ |
|
| 81 | + public $address_state_id; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * The ID of the country the contact belongs. |
|
| 85 | + * @var string |
|
| 86 | + */ |
|
| 87 | + public $address_country_id; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * The contact's ZIP code. |
|
| 91 | + * @var string |
|
| 92 | + */ |
|
| 93 | + public $address_zip; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * A latitude of the contact's cached position. |
|
| 97 | + * @var double |
|
| 98 | + */ |
|
| 99 | + public $cached_lat; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * A longitude of the contact's cached position. |
|
| 103 | + * @var double |
|
| 104 | + */ |
|
| 105 | + public $cached_lng; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * A latitude of the contact's curbside. |
|
| 109 | + * @var double |
|
| 110 | + */ |
|
| 111 | + public $curbside_lat; |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * A longitude of the contact's curbside. |
|
| 115 | + * @var double |
|
| 116 | + */ |
|
| 117 | + public $curbside_lng; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * The contact's color on the map. |
|
| 121 | + * @var string |
|
| 122 | + */ |
|
| 123 | + public $color; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * An array of the contact's custom field-value pairs. |
|
| 127 | + * @var array |
|
| 128 | + */ |
|
| 129 | + public $address_custom_data; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * An array of the contact's schedules. |
|
| 133 | + * @var Schedule[] |
|
| 134 | + */ |
|
| 135 | + public $schedule; |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Time when the contact was created. |
|
| 139 | + * @var long |
|
| 140 | + */ |
|
| 141 | + public $created_timestamp; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Unique ID of the member. |
|
| 145 | + * @var integer |
|
| 146 | + */ |
|
| 147 | + public $member_id; |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * The list of dates that should be omitted from the schedules. |
|
| 151 | + * @var string[] |
|
| 152 | + */ |
|
| 153 | + public $schedule_blacklist; |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Number of the routes containing the contact. |
|
| 157 | + * @var integer |
|
| 158 | + */ |
|
| 159 | + public $in_route_count; |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * When the contact was last visited. |
|
| 163 | + * @var long |
|
| 164 | + */ |
|
| 165 | + public $last_visited_timestamp; |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * When the contact was last routed. |
|
| 169 | + * @var long |
|
| 170 | + */ |
|
| 171 | + public $last_routed_timestamp; |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Start of the contact's local time window. |
|
| 175 | + * @var long |
|
| 176 | + */ |
|
| 177 | + public $local_time_window_start; |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * End of the contact's local time window. |
|
| 181 | + * @var long |
|
| 182 | + */ |
|
| 183 | + public $local_time_window_end; |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Start of the contact's second local time window. |
|
| 187 | + * @var long |
|
| 188 | + */ |
|
| 189 | + public $local_time_window_start_2; |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * End of the contact's second local time window. |
|
| 193 | + * @var long |
|
| 194 | + */ |
|
| 195 | + public $local_time_window_end_2; |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * The service time at the contact's address. |
|
| 199 | + * @var integer |
|
| 200 | + */ |
|
| 201 | + public $service_time; |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * The contact's local timezone. |
|
| 205 | + * @var string |
|
| 206 | + */ |
|
| 207 | + public $local_timezone_string; |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * The contact's icon on the map. |
|
| 211 | + * @var string |
|
| 212 | + */ |
|
| 213 | + public $address_icon; |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * The contact's stop type. |
|
| 217 | + * @var string |
|
| 218 | + */ |
|
| 219 | + public $address_stop_type; |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * The cubic volume of the contact's cargo. |
|
| 223 | + * @var double |
|
| 224 | + */ |
|
| 225 | + public $address_cube; |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * The number of pieces/pallets that this destination/order/line-item consumes/contains on a vehicle. |
|
| 229 | + * @var integer |
|
| 230 | + */ |
|
| 231 | + public $address_pieces; |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * The reference number of the address. |
|
| 235 | + * @var string |
|
| 236 | + */ |
|
| 237 | + public $address_reference_no; |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * The revenue from the contact. |
|
| 241 | + * @var double |
|
| 242 | + */ |
|
| 243 | + public $address_revenue; |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * The weight of the contact's cargo. |
|
| 247 | + * @var double |
|
| 248 | + */ |
|
| 249 | + public $address_weight; |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * If present, the priority will sequence addresses in all the optimal routes so that |
|
| 253 | + * higher priority addresses are general at the beginning of the route sequence.<br> |
|
| 254 | + * 1 is the highest priority, 100000 is the lowest. |
|
| 255 | + * @var integer |
|
| 256 | + */ |
|
| 257 | + public $address_priority; |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * The customer purchase order of the contact. |
|
| 261 | + * @var string |
|
| 262 | + */ |
|
| 263 | + public $address_customer_po; |
|
| 264 | + |
|
| 265 | + public function __construct() |
|
| 266 | + { |
|
| 267 | + Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * @deprecated 1.2.8 |
|
| 272 | + * @see \Route4Me\V5\AddressBook\AddressBook::getAddressById() |
|
| 273 | + */ |
|
| 274 | + public static function getAddressBookLocation($addressId) |
|
| 275 | + { |
|
| 276 | + $ablocations = Route4Me::makeRequst([ |
|
| 277 | + 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 278 | + 'method' => 'GET', |
|
| 279 | + 'query' => [ |
|
| 280 | + 'query' => $addressId, |
|
| 281 | + 'limit' => 30, |
|
| 282 | + ], |
|
| 283 | + ]); |
|
| 284 | + |
|
| 285 | + return $ablocations; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @deprecated 1.2.8 |
|
| 290 | + * @see \Route4Me\V5\AddressBook\AddressBook::getAddressesByBodyPayload() |
|
| 291 | + */ |
|
| 292 | + public static function searchAddressBookLocations($params) |
|
| 293 | + { |
|
| 294 | + $allQueryFields = ['display', 'query', 'fields', 'limit', 'offset']; |
|
| 295 | + |
|
| 296 | + $result = Route4Me::makeRequst([ |
|
| 297 | + 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 298 | + 'method' => 'GET', |
|
| 299 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 300 | + ]); |
|
| 301 | + |
|
| 302 | + return $result; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @deprecated 1.2.8 |
|
| 307 | + * @see \Route4Me\V5\AddressBook\AddressBook::getAddressesByIds() |
|
| 308 | + */ |
|
| 309 | + public static function getAddressBookLocations($params) |
|
| 310 | + { |
|
| 311 | + $allQueryFields = ['limit', 'offset', 'address_id']; |
|
| 312 | + |
|
| 313 | + $ablocations = Route4Me::makeRequst([ |
|
| 314 | + 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 315 | + 'method' => 'GET', |
|
| 316 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 317 | + ]); |
|
| 318 | + |
|
| 319 | + return $ablocations; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + public static function getRandomAddressBookLocation($params) |
|
| 323 | + { |
|
| 324 | + $ablocations = self::getAddressBookLocations($params); |
|
| 325 | + |
|
| 326 | + if (isset($ablocations['results'])) { |
|
| 327 | + $locationsSize = sizeof($ablocations['results']); |
|
| 328 | + |
|
| 329 | + if ($locationsSize > 0) { |
|
| 330 | + $randomLocationIndex = rand(0, $locationsSize - 1); |
|
| 331 | + |
|
| 332 | + return $ablocations['results'][$randomLocationIndex]; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + return null; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @deprecated 1.2.8 |
|
| 341 | + * @see \Route4Me\V5\AddressBook\AddressBook::addAddress() |
|
| 342 | + * |
|
| 343 | + * @param AddressBookLocation $params |
|
| 344 | + */ |
|
| 345 | + public static function addAdressBookLocation($params) |
|
| 346 | + { |
|
| 347 | + $allBodyFields = Route4Me::getObjectProperties(new self(), ['address_id', 'in_route_count']); |
|
| 348 | + |
|
| 349 | + $response = Route4Me::makeRequst([ |
|
| 350 | + 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 351 | + 'method' => 'POST', |
|
| 352 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 353 | + ]); |
|
| 354 | + |
|
| 355 | + return $response; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @deprecated 1.2.8 |
|
| 360 | + * @see \Route4Me\V5\AddressBook\AddressBook::deleteAddressesByIds() |
|
| 361 | + */ |
|
| 362 | + public function deleteAdressBookLocation($address_ids) |
|
| 363 | + { |
|
| 364 | + $result = Route4Me::makeRequst([ |
|
| 365 | + 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 366 | + 'method' => 'DELETEARRAY', |
|
| 367 | + 'query' => [ |
|
| 368 | + 'address_ids' => $address_ids, |
|
| 369 | + ], |
|
| 370 | + ]); |
|
| 371 | + |
|
| 372 | + return $result; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * @deprecated 1.2.8 |
|
| 377 | + * @see \Route4Me\V5\AddressBook\AddressBook::updateAddressById() |
|
| 378 | + */ |
|
| 379 | + public function updateAddressBookLocation($params) |
|
| 380 | + { |
|
| 381 | + $allBodyFields = Route4Me::getObjectProperties(new self(), ['in_route_count']); |
|
| 382 | + |
|
| 383 | + $response = Route4Me::makeRequst([ |
|
| 384 | + 'url' => Endpoint::ADDRESS_BOOK_V4, |
|
| 385 | + 'method' => 'PUT', |
|
| 386 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 387 | + ]); |
|
| 388 | + |
|
| 389 | + return $response; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + public static function validateScheduleMode($scheduleMode) |
|
| 393 | + { |
|
| 394 | + $schedModes = ['daily', 'weekly', 'monthly', 'annually']; |
|
| 395 | + |
|
| 396 | + if (in_array($scheduleMode, $schedModes)) { |
|
| 397 | + return true; |
|
| 398 | + } else { |
|
| 399 | + return false; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + public static function validateScheduleEnable($scheduleEnabled) |
|
| 404 | + { |
|
| 405 | + if (is_string($scheduleEnabled)) { |
|
| 406 | + if (strtolower($scheduleEnabled)=="true") $scheduleEnabled = true; |
|
| 407 | + if (strtolower($scheduleEnabled)=="false") $scheduleEnabled = false; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + $schedEnables = [true, false,]; |
|
| 411 | + |
|
| 412 | + if (in_array($scheduleEnabled, $schedEnables,true)) { |
|
| 413 | + return true; |
|
| 414 | + } else { |
|
| 415 | + return false; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + public static function validateScheduleEvery($scheduleEvery) |
|
| 420 | + { |
|
| 421 | + if (is_numeric($scheduleEvery)) { |
|
| 422 | + if ($scheduleEvery>0) { |
|
| 423 | + return true; |
|
| 424 | + } else { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + } else { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + public static function validateScheduleWeekDays($scheduleWeekDays) |
|
| 433 | + { |
|
| 434 | + if (is_bool($scheduleWeekDays)) return false; |
|
| 435 | + |
|
| 436 | + $weekdays = explode(',', $scheduleWeekDays); |
|
| 437 | + $weekdaysSize = sizeof($weekdays); |
|
| 438 | + |
|
| 439 | + if ($weekdaysSize < 1) { |
|
| 440 | + return false; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + $isValid = true; |
|
| 444 | + |
|
| 445 | + for ($i = 0; $i < $weekdaysSize; ++$i) { |
|
| 446 | + if (is_bool($weekdays[$i])) { |
|
| 447 | + $isValid = false; |
|
| 448 | + } elseif (is_numeric($weekdays[$i])) { |
|
| 449 | + $wday = intval($weekdays[$i]); |
|
| 450 | + if ($wday < 1 || $wday > 7) { |
|
| 451 | + $isValid = false; |
|
| 452 | + } |
|
| 453 | + } else { |
|
| 454 | + $isValid = false; |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + return $isValid; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + public static function validateScheduleMonthlyMode($scheduleMonthlyMode) |
|
| 462 | + { |
|
| 463 | + $schedMonthlyMmodes = ['dates', 'nth']; |
|
| 464 | + |
|
| 465 | + if (in_array($scheduleMonthlyMode, $schedMonthlyMmodes,true)) { |
|
| 466 | + return true; |
|
| 467 | + } else { |
|
| 468 | + return false; |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + public static function validateScheduleMonthlyDates($scheduleMonthlyDates) |
|
| 473 | + { |
|
| 474 | + if (is_bool($scheduleMonthlyDates)) return false; |
|
| 475 | + |
|
| 476 | + $monthlyDates = explode(',', $scheduleMonthlyDates); |
|
| 477 | + $monthlyDatesSize = sizeof($monthlyDates); |
|
| 478 | + |
|
| 479 | + if ($monthlyDatesSize < 1) { |
|
| 480 | + return false; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + $isValid = true; |
|
| 484 | + |
|
| 485 | + for ($i = 0; $i < $monthlyDatesSize; ++$i) { |
|
| 486 | + if (is_numeric($monthlyDates[$i])) { |
|
| 487 | + $mday = intval($monthlyDates[$i]); |
|
| 488 | + if ($mday < 1 || $mday > 31) { |
|
| 489 | + $isValid = false; |
|
| 490 | + } |
|
| 491 | + } else { |
|
| 492 | + $isValid = false; |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $isValid; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + public static function validateScheduleNthN($scheduleNthN) |
|
| 500 | + { |
|
| 501 | + if (!is_numeric($scheduleNthN)) { |
|
| 502 | + return false; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + $schedNthNs = [1, 2, 3, 4, 5, -1]; |
|
| 506 | + |
|
| 507 | + if (in_array($scheduleNthN, $schedNthNs)) { |
|
| 508 | + return true; |
|
| 509 | + } else { |
|
| 510 | + return false; |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + public static function validateScheduleNthWhat($scheduleNthWhat) |
|
| 515 | + { |
|
| 516 | + if (!is_numeric($scheduleNthWhat)) { |
|
| 517 | + return false; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + $schedNthWhats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
|
| 521 | + |
|
| 522 | + if (in_array($scheduleNthWhat, $schedNthWhats)) { |
|
| 523 | + return true; |
|
| 524 | + } else { |
|
| 525 | + return false; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** Function adds the locations (with/without schedule) from the CSV file. |
|
| 530 | + * $csvFileHandle - a file handler. |
|
| 531 | + * Returns array $results which contains two arrays: fail and succes. |
|
| 532 | + */ |
|
| 533 | + public function addLocationsFromCsvFile($csvFileHandle, $locationsFieldsMapping) |
|
| 534 | + { |
|
| 535 | + $max_line_length = 512; |
|
| 536 | + $delemietr = ','; |
|
| 537 | + |
|
| 538 | + $results = []; |
|
| 539 | + $results['fail'] = []; |
|
| 540 | + $results['success'] = []; |
|
| 541 | + |
|
| 542 | + $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr); |
|
| 543 | + |
|
| 544 | + $addressBookFields = Route4Me::getObjectProperties(new self(), ['address_id', 'in_route_count']); |
|
| 545 | + |
|
| 546 | + if (empty($columns)) { |
|
| 547 | + array_push($results['fail'], 'Empty CSV table'); |
|
| 548 | + |
|
| 549 | + return $results; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + $iRow = 1; |
|
| 553 | + |
|
| 554 | + while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) { |
|
| 555 | + if (!isset($rows[$locationsFieldsMapping['cached_lat']]) || !isset($rows[$locationsFieldsMapping['cached_lng']]) |
|
| 556 | + || !isset($rows[$locationsFieldsMapping['address_1']]) || [null] == $rows) { |
|
| 557 | + continue; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + $curSchedule = ''; |
|
| 561 | + $mode = ''; |
|
| 562 | + |
|
| 563 | + $failCount = sizeof($results['fail']); |
|
| 564 | + |
|
| 565 | + if (isset($rows[$locationsFieldsMapping['schedule_mode']])) { |
|
| 566 | + if ($this->validateScheduleMode($rows[$locationsFieldsMapping['schedule_mode']])) { |
|
| 567 | + $curSchedule = '"mode":"'.$rows[$locationsFieldsMapping['schedule_mode']].'",'; |
|
| 568 | + $mode = $rows[$locationsFieldsMapping['schedule_mode']]; |
|
| 569 | + } else { |
|
| 570 | + array_push($results['fail'], "$iRow --> Wrong schedule mode parameter"); |
|
| 571 | + } |
|
| 572 | + } else { |
|
| 573 | + array_push($results['fail'], "$iRow --> The schedule mode parameter is not set"); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + if (isset($rows[$locationsFieldsMapping['schedule_enabled']])) { |
|
| 577 | + if ($this->validateScheduleEnable($rows[$locationsFieldsMapping['schedule_enabled']])) { |
|
| 578 | + $curSchedule .= '"enabled":'.$rows[$locationsFieldsMapping['schedule_enabled']].','; |
|
| 579 | + } else { |
|
| 580 | + array_push($results['fail'], "$iRow --> The schedule enabled parameter is not set "); |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + if (isset($rows[$locationsFieldsMapping['schedule_every']])) { |
|
| 585 | + if ($this->validateScheduleEvery($rows[$locationsFieldsMapping['schedule_every']])) { |
|
| 586 | + $curSchedule .= '"'.$mode.'":{'.'"every":'.$rows[$locationsFieldsMapping['schedule_every']].','; |
|
| 587 | + if ('daily' == $mode) { |
|
| 588 | + $curSchedule = trim($curSchedule, ','); |
|
| 589 | + $curSchedule .= '}'; |
|
| 590 | + } |
|
| 591 | + } else { |
|
| 592 | + array_push($results['fail'], "$iRow --> The parameter sched_every is not set"); |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if ('daily' != $mode) { |
|
| 597 | + switch ($mode) { |
|
| 598 | + case 'weekly': |
|
| 599 | + if (isset($rows[$locationsFieldsMapping['schedule_weekdays']])) { |
|
| 600 | + if ($this->validateScheduleWeekDays($rows[$locationsFieldsMapping['schedule_weekdays']])) { |
|
| 601 | + $curSchedule .= '"weekdays":['.$rows[$locationsFieldsMapping['schedule_weekdays']].']}'; |
|
| 602 | + } else { |
|
| 603 | + array_push($results['fail'], "$iRow --> Wrong weekdays"); |
|
| 604 | + } |
|
| 605 | + } else { |
|
| 606 | + array_push($results['fail'], "$iRow --> The parameters sched_weekdays is not set"); |
|
| 607 | + } |
|
| 608 | + break; |
|
| 609 | + case 'monthly': |
|
| 610 | + $monthlyMode = ''; |
|
| 611 | + if (isset($rows[$locationsFieldsMapping['monthly_mode']])) { |
|
| 612 | + if ($this->validateScheduleMonthlyMode($rows[$locationsFieldsMapping['monthly_mode']])) { |
|
| 613 | + $monthlyMode = $rows[$locationsFieldsMapping['monthly_mode']]; |
|
| 614 | + $curSchedule .= '"mode": "'.$rows[$locationsFieldsMapping['monthly_mode']].'",'; |
|
| 615 | + } else { |
|
| 616 | + array_push($results['fail'], "$iRow --> Wrong monthly mode"); |
|
| 617 | + } |
|
| 618 | + } else { |
|
| 619 | + array_push($results['fail'], "$iRow --> The parameter sched_monthly_mode is not set"); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + if ('' != $monthlyMode) { |
|
| 623 | + switch ($monthlyMode) { |
|
| 624 | + case 'dates': |
|
| 625 | + if (isset($rows[$locationsFieldsMapping['monthly_dates']])) { |
|
| 626 | + if ($this->validateScheduleMonthlyDates($rows[$locationsFieldsMapping['monthly_dates']])) { |
|
| 627 | + $curSchedule .= '"dates":['.$rows[$locationsFieldsMapping['monthly_dates']].']}'; |
|
| 628 | + } else { |
|
| 629 | + array_push($results['fail'], "$iRow --> Wrong monthly dates"); |
|
| 630 | + } |
|
| 631 | + } |
|
| 632 | + break; |
|
| 633 | + case 'nth': |
|
| 634 | + if (isset($rows[$locationsFieldsMapping['monthly_nth_n']])) { |
|
| 635 | + if ($this->validateScheduleNthN($rows[$locationsFieldsMapping['monthly_nth_n']])) { |
|
| 636 | + $curSchedule .= '"nth":{"n":'.$rows[$locationsFieldsMapping['monthly_nth_n']].','; |
|
| 637 | + } else { |
|
| 638 | + array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_n"); |
|
| 639 | + } |
|
| 640 | + } else { |
|
| 641 | + array_push($results['fail'], "$iRow --> The parameter sched_nth_n is not set"); |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + if ('' != $curSchedule) { |
|
| 645 | + if (isset($rows[$locationsFieldsMapping['monthly_nth_what']])) { |
|
| 646 | + if ($this->validateScheduleNthWhat($rows[$locationsFieldsMapping['monthly_nth_what']])) { |
|
| 647 | + $curSchedule .= '"what":'.$rows[$locationsFieldsMapping['monthly_nth_what']].'}}'; |
|
| 648 | + } else { |
|
| 649 | + array_push($results['fail'], "$iRow --> Wrong parameter sched_nth_what"); |
|
| 650 | + } |
|
| 651 | + } else { |
|
| 652 | + array_push($results['fail'], "$iRow --> The parameter sched_nth_what is not set"); |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + break; |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + break; |
|
| 659 | + default: |
|
| 660 | + $curSchedule = ''; |
|
| 661 | + break; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + if (sizeof($results['fail']) > $failCount) { |
|
| 666 | + $curSchedule = ''; |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + if (('daily' == $mode || 'weekly' == $mode || 'monthy' == $mode) && '' == $curSchedule) { |
|
| 670 | + ++$iRow; |
|
| 671 | + continue; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + $curSchedule = strtolower($curSchedule); |
|
| 675 | + |
|
| 676 | + $curSchedule = '[{'.$curSchedule.'}]'; |
|
| 677 | + |
|
| 678 | + $parametersArray = []; |
|
| 679 | + |
|
| 680 | + foreach ($addressBookFields as $addressBookField) { |
|
| 681 | + if (isset($locationsFieldsMapping[$addressBookField])) { |
|
| 682 | + $parametersArray[$addressBookField] = $rows[$locationsFieldsMapping[$addressBookField]]; |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + $AdressBookLocationParameters = self::fromArray($parametersArray); |
|
| 687 | + |
|
| 688 | + $abContacts = new self(); |
|
| 689 | + |
|
| 690 | + $abcResults = $abContacts->addAdressBookLocation($AdressBookLocationParameters); //temporarry |
|
| 691 | + |
|
| 692 | + array_push( |
|
| 693 | + $results['success'], |
|
| 694 | + 'The schedule location with address_id = '.strval($abcResults['address_id']).' added successfuly.' |
|
| 695 | + ); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + return $results; |
|
| 699 | + } |
|
| 700 | 700 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | if (is_null($result) || !is_array($result)) return null; |
| 182 | 182 | |
| 183 | 183 | foreach ($result as $custNoteType) { |
| 184 | - if (isset($custNoteType["note_custom_type"]) && $custNoteType["note_custom_type"] == $params) { |
|
| 184 | + if (isset($custNoteType["note_custom_type"]) && $custNoteType["note_custom_type"]==$params) { |
|
| 185 | 185 | return $custNoteType; |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $customArray = []; |
| 228 | 228 | |
| 229 | 229 | foreach ($params as $key => $value) { |
| 230 | - if (false !== strpos($key, 'custom_note_type')) { |
|
| 230 | + if (false!==strpos($key, 'custom_note_type')) { |
|
| 231 | 231 | $customArray[$key] = $value; |
| 232 | 232 | } |
| 233 | 233 | } |
@@ -178,7 +178,9 @@ |
||
| 178 | 178 | 'method' => 'GET', |
| 179 | 179 | ]); |
| 180 | 180 | |
| 181 | - if (is_null($result) || !is_array($result)) return null; |
|
| 181 | + if (is_null($result) || !is_array($result)) { |
|
| 182 | + return null; |
|
| 183 | + } |
|
| 182 | 184 | |
| 183 | 185 | foreach ($result as $custNoteType) { |
| 184 | 186 | if (isset($custNoteType["note_custom_type"]) && $custNoteType["note_custom_type"] == $params) { |
@@ -11,222 +11,222 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class AddressNote extends Common |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * An unique ID of a note |
|
| 16 | - * @var integer |
|
| 17 | - */ |
|
| 18 | - public $note_id; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * The route ID |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - public $route_id; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * The route destination ID |
|
| 28 | - * @var integer |
|
| 29 | - */ |
|
| 30 | - public $route_destination_id; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * An unique ID of an uploaded file |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - public $upload_id; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * When the note was added |
|
| 40 | - * @var integer |
|
| 41 | - */ |
|
| 42 | - public $ts_added; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * The position latitude where the address note was added |
|
| 46 | - * @var double |
|
| 47 | - */ |
|
| 48 | - public $lat; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * The position longitude where the address note was added |
|
| 52 | - * @var double |
|
| 53 | - */ |
|
| 54 | - public $lng; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * The activity type |
|
| 58 | - * @var string |
|
| 59 | - */ |
|
| 60 | - public $activity_type; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * The note text contents |
|
| 64 | - * @var string |
|
| 65 | - */ |
|
| 66 | - public $contents; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * An upload type of the note |
|
| 70 | - * @var string |
|
| 71 | - */ |
|
| 72 | - public $upload_type; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * An upload url - where a file-note was uploaded. |
|
| 76 | - * @var string |
|
| 77 | - */ |
|
| 78 | - public $upload_url; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * An extension of the uploaded file. |
|
| 82 | - * @var string |
|
| 83 | - */ |
|
| 84 | - public $upload_extension; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * The device a note was uploaded from. |
|
| 88 | - * @var string |
|
| 89 | - */ |
|
| 90 | - public $device_type; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Array of the custom type notes. |
|
| 94 | - * @var CustomNoteType[] |
|
| 95 | - */ |
|
| 96 | - public $custom_types; |
|
| 97 | - |
|
| 98 | - public function __construct() |
|
| 99 | - { |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Get notes from the specified route destination.<br> |
|
| 104 | - * Returns an address object with notes, if an address exists, otherwise - return null. |
|
| 105 | - */ |
|
| 106 | - public static function GetAddressesNotes($noteParams) |
|
| 107 | - { |
|
| 108 | - $address = Route4Me::makeRequst([ |
|
| 109 | - 'url' => Endpoint::ADDRESS_V4, |
|
| 110 | - 'method' => 'GET', |
|
| 111 | - 'query' => [ |
|
| 112 | - 'route_id' => isset($noteParams['route_id']) ? $noteParams['route_id'] : null, |
|
| 113 | - 'route_destination_id' => isset($noteParams['route_destination_id']) |
|
| 114 | - ? $noteParams['route_destination_id'] : null, |
|
| 115 | - 'notes' => 1, |
|
| 116 | - ], |
|
| 117 | - ]); |
|
| 118 | - |
|
| 119 | - return $address; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - public function createCustomNoteType($params) |
|
| 123 | - { |
|
| 124 | - $allBodyFields = ['type', 'values']; |
|
| 125 | - |
|
| 126 | - $result = Route4Me::makeRequst([ |
|
| 127 | - 'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
|
| 128 | - 'method' => 'POST', |
|
| 129 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 130 | - ]); |
|
| 131 | - |
|
| 132 | - return $result; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - public function removeCustomNoteType($params) |
|
| 136 | - { |
|
| 137 | - $result = Route4Me::makeRequst([ |
|
| 138 | - 'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
|
| 139 | - 'method' => 'DELETE', |
|
| 140 | - 'body' => [ |
|
| 141 | - 'id' => isset($params['id']) ? $params['id'] : null, |
|
| 142 | - ], |
|
| 143 | - ]); |
|
| 144 | - |
|
| 145 | - return $result; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function getAllCustomNoteTypes() |
|
| 149 | - { |
|
| 150 | - $result = Route4Me::makeRequst([ |
|
| 151 | - 'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
|
| 152 | - 'method' => 'GET', |
|
| 153 | - ]); |
|
| 154 | - |
|
| 155 | - return $result; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function getCustomNoteTypeByKey($params) |
|
| 159 | - { |
|
| 160 | - $result = Route4Me::makeRequst([ |
|
| 161 | - 'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
|
| 162 | - 'method' => 'GET', |
|
| 163 | - ]); |
|
| 164 | - |
|
| 165 | - if (is_null($result) || !is_array($result)) return null; |
|
| 166 | - |
|
| 167 | - foreach ($result as $custNoteType) { |
|
| 168 | - if (isset($custNoteType["note_custom_type"]) && $custNoteType["note_custom_type"] == $params) { |
|
| 169 | - return $custNoteType; |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - public function AddAddressNote($params) |
|
| 175 | - { |
|
| 176 | - $allQueryFields = ['route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type']; |
|
| 177 | - $allBodyFields = ['strNoteContents', 'strUpdateType']; |
|
| 178 | - |
|
| 179 | - $result = Route4Me::makeRequst([ |
|
| 180 | - 'url' => Endpoint::ROUTE_NOTES_ADD, |
|
| 181 | - 'method' => 'POST', |
|
| 182 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 183 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 184 | - 'HTTPHEADER' => 'Content-Type: multipart/form-data', |
|
| 185 | - ]); |
|
| 186 | - |
|
| 187 | - return $result; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - public function AddNoteFile($params) |
|
| 191 | - { |
|
| 192 | - $fname = isset($params['strFilename']) ? $params['strFilename'] : null; |
|
| 193 | - |
|
| 194 | - $allQueryFields = ['route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type']; |
|
| 195 | - $allBodyFields = ['strFilename', 'strUpdateType', 'strNoteContents']; |
|
| 196 | - |
|
| 197 | - $result = Route4Me::makeRequst([ |
|
| 198 | - 'url' => Endpoint::ROUTE_NOTES_ADD, |
|
| 199 | - 'method' => 'POST', |
|
| 200 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 201 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 202 | - 'FILE' => $fname, |
|
| 203 | - 'HTTPHEADER' => 'Content-Type: multipart/form-data' |
|
| 204 | - ]); |
|
| 205 | - |
|
| 206 | - return $result; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - public function addCustomNoteToRoute($params) |
|
| 210 | - { |
|
| 211 | - $customArray = []; |
|
| 212 | - |
|
| 213 | - foreach ($params as $key => $value) { |
|
| 214 | - if (false !== strpos($key, 'custom_note_type')) { |
|
| 215 | - $customArray[$key] = $value; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $allQueryFields = ['route_id', 'address_id', 'format', 'dev_lat', 'dev_lng']; |
|
| 220 | - $allBodyFields = ['strUpdateType', 'strUpdateType', 'strNoteContents']; |
|
| 221 | - |
|
| 222 | - $result = Route4Me::makeRequst([ |
|
| 223 | - 'url' => Endpoint::ROUTE_NOTES_ADD, |
|
| 224 | - 'method' => 'POST', |
|
| 225 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 226 | - 'body' => array_merge(Route4Me::generateRequestParameters($allBodyFields, $params), $customArray), |
|
| 227 | - 'HTTPHEADER' => 'Content-Type: multipart/form-data', |
|
| 228 | - ]); |
|
| 229 | - |
|
| 230 | - return $result; |
|
| 231 | - } |
|
| 14 | + /** |
|
| 15 | + * An unique ID of a note |
|
| 16 | + * @var integer |
|
| 17 | + */ |
|
| 18 | + public $note_id; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * The route ID |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + public $route_id; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * The route destination ID |
|
| 28 | + * @var integer |
|
| 29 | + */ |
|
| 30 | + public $route_destination_id; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * An unique ID of an uploaded file |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + public $upload_id; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * When the note was added |
|
| 40 | + * @var integer |
|
| 41 | + */ |
|
| 42 | + public $ts_added; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * The position latitude where the address note was added |
|
| 46 | + * @var double |
|
| 47 | + */ |
|
| 48 | + public $lat; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * The position longitude where the address note was added |
|
| 52 | + * @var double |
|
| 53 | + */ |
|
| 54 | + public $lng; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * The activity type |
|
| 58 | + * @var string |
|
| 59 | + */ |
|
| 60 | + public $activity_type; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * The note text contents |
|
| 64 | + * @var string |
|
| 65 | + */ |
|
| 66 | + public $contents; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * An upload type of the note |
|
| 70 | + * @var string |
|
| 71 | + */ |
|
| 72 | + public $upload_type; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * An upload url - where a file-note was uploaded. |
|
| 76 | + * @var string |
|
| 77 | + */ |
|
| 78 | + public $upload_url; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * An extension of the uploaded file. |
|
| 82 | + * @var string |
|
| 83 | + */ |
|
| 84 | + public $upload_extension; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * The device a note was uploaded from. |
|
| 88 | + * @var string |
|
| 89 | + */ |
|
| 90 | + public $device_type; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Array of the custom type notes. |
|
| 94 | + * @var CustomNoteType[] |
|
| 95 | + */ |
|
| 96 | + public $custom_types; |
|
| 97 | + |
|
| 98 | + public function __construct() |
|
| 99 | + { |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Get notes from the specified route destination.<br> |
|
| 104 | + * Returns an address object with notes, if an address exists, otherwise - return null. |
|
| 105 | + */ |
|
| 106 | + public static function GetAddressesNotes($noteParams) |
|
| 107 | + { |
|
| 108 | + $address = Route4Me::makeRequst([ |
|
| 109 | + 'url' => Endpoint::ADDRESS_V4, |
|
| 110 | + 'method' => 'GET', |
|
| 111 | + 'query' => [ |
|
| 112 | + 'route_id' => isset($noteParams['route_id']) ? $noteParams['route_id'] : null, |
|
| 113 | + 'route_destination_id' => isset($noteParams['route_destination_id']) |
|
| 114 | + ? $noteParams['route_destination_id'] : null, |
|
| 115 | + 'notes' => 1, |
|
| 116 | + ], |
|
| 117 | + ]); |
|
| 118 | + |
|
| 119 | + return $address; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + public function createCustomNoteType($params) |
|
| 123 | + { |
|
| 124 | + $allBodyFields = ['type', 'values']; |
|
| 125 | + |
|
| 126 | + $result = Route4Me::makeRequst([ |
|
| 127 | + 'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
|
| 128 | + 'method' => 'POST', |
|
| 129 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 130 | + ]); |
|
| 131 | + |
|
| 132 | + return $result; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + public function removeCustomNoteType($params) |
|
| 136 | + { |
|
| 137 | + $result = Route4Me::makeRequst([ |
|
| 138 | + 'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
|
| 139 | + 'method' => 'DELETE', |
|
| 140 | + 'body' => [ |
|
| 141 | + 'id' => isset($params['id']) ? $params['id'] : null, |
|
| 142 | + ], |
|
| 143 | + ]); |
|
| 144 | + |
|
| 145 | + return $result; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function getAllCustomNoteTypes() |
|
| 149 | + { |
|
| 150 | + $result = Route4Me::makeRequst([ |
|
| 151 | + 'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
|
| 152 | + 'method' => 'GET', |
|
| 153 | + ]); |
|
| 154 | + |
|
| 155 | + return $result; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function getCustomNoteTypeByKey($params) |
|
| 159 | + { |
|
| 160 | + $result = Route4Me::makeRequst([ |
|
| 161 | + 'url' => Endpoint::NOTE_CUSTOM_TYPES_V4, |
|
| 162 | + 'method' => 'GET', |
|
| 163 | + ]); |
|
| 164 | + |
|
| 165 | + if (is_null($result) || !is_array($result)) return null; |
|
| 166 | + |
|
| 167 | + foreach ($result as $custNoteType) { |
|
| 168 | + if (isset($custNoteType["note_custom_type"]) && $custNoteType["note_custom_type"] == $params) { |
|
| 169 | + return $custNoteType; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + public function AddAddressNote($params) |
|
| 175 | + { |
|
| 176 | + $allQueryFields = ['route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type']; |
|
| 177 | + $allBodyFields = ['strNoteContents', 'strUpdateType']; |
|
| 178 | + |
|
| 179 | + $result = Route4Me::makeRequst([ |
|
| 180 | + 'url' => Endpoint::ROUTE_NOTES_ADD, |
|
| 181 | + 'method' => 'POST', |
|
| 182 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 183 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 184 | + 'HTTPHEADER' => 'Content-Type: multipart/form-data', |
|
| 185 | + ]); |
|
| 186 | + |
|
| 187 | + return $result; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + public function AddNoteFile($params) |
|
| 191 | + { |
|
| 192 | + $fname = isset($params['strFilename']) ? $params['strFilename'] : null; |
|
| 193 | + |
|
| 194 | + $allQueryFields = ['route_id', 'address_id', 'dev_lat', 'dev_lng', 'device_type']; |
|
| 195 | + $allBodyFields = ['strFilename', 'strUpdateType', 'strNoteContents']; |
|
| 196 | + |
|
| 197 | + $result = Route4Me::makeRequst([ |
|
| 198 | + 'url' => Endpoint::ROUTE_NOTES_ADD, |
|
| 199 | + 'method' => 'POST', |
|
| 200 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 201 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 202 | + 'FILE' => $fname, |
|
| 203 | + 'HTTPHEADER' => 'Content-Type: multipart/form-data' |
|
| 204 | + ]); |
|
| 205 | + |
|
| 206 | + return $result; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + public function addCustomNoteToRoute($params) |
|
| 210 | + { |
|
| 211 | + $customArray = []; |
|
| 212 | + |
|
| 213 | + foreach ($params as $key => $value) { |
|
| 214 | + if (false !== strpos($key, 'custom_note_type')) { |
|
| 215 | + $customArray[$key] = $value; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $allQueryFields = ['route_id', 'address_id', 'format', 'dev_lat', 'dev_lng']; |
|
| 220 | + $allBodyFields = ['strUpdateType', 'strUpdateType', 'strNoteContents']; |
|
| 221 | + |
|
| 222 | + $result = Route4Me::makeRequst([ |
|
| 223 | + 'url' => Endpoint::ROUTE_NOTES_ADD, |
|
| 224 | + 'method' => 'POST', |
|
| 225 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 226 | + 'body' => array_merge(Route4Me::generateRequestParameters($allBodyFields, $params), $customArray), |
|
| 227 | + 'HTTPHEADER' => 'Content-Type: multipart/form-data', |
|
| 228 | + ]); |
|
| 229 | + |
|
| 230 | + return $result; |
|
| 231 | + } |
|
| 232 | 232 | } |
@@ -13,214 +13,214 @@ |
||
| 13 | 13 | |
| 14 | 14 | class MyQ |
| 15 | 15 | { |
| 16 | - /** @var string|null $username contains the username used to authenticate with the MyQ API */ |
|
| 17 | - protected $username = null; |
|
| 18 | - /** @var string|null $password contains the password used to authenticate with the MyQ API */ |
|
| 19 | - protected $password = null; |
|
| 20 | - /** @var string|null $appId is the application ID used to register with the MyQ API */ |
|
| 21 | - protected $appId = 'NWknvuBd7LoFHfXmKNMBcgajXtZEgKUh4V7WNzMidrpUUluDpVYVZx+xT4PCM5Kx'; |
|
| 22 | - //protected $appId = 'Vj8pQggXLhLy0WHahglCD4N1nAkkXQtGYpq2HrHD7H1nvmbT55KqtN6RSF4ILB%2fi'; |
|
| 23 | - /** @var string|null $securityToken is the auth token returned after a successful login */ |
|
| 24 | - protected $securityToken = null; |
|
| 25 | - /** @var string|null $userAgent is the User-Agent header value sent with each API request */ |
|
| 26 | - protected $userAgent = 'Chamberlain/3.4.1'; |
|
| 27 | - /** @var string|null $culture is the API culture code for the API */ |
|
| 28 | - protected $culture = 'en'; |
|
| 29 | - /** @var string|null $contentType is the content type used for all cURL requests */ |
|
| 30 | - protected $contentType = 'application/json'; |
|
| 31 | - /** @var array $headers contain HTTP headers for cURL requests */ |
|
| 32 | - protected $_headers = []; |
|
| 33 | - protected $_deviceId = null; |
|
| 34 | - protected $_locationName = null; |
|
| 35 | - protected $_doorName = null; |
|
| 36 | - protected $_loginUrl = 'https://myqexternal.myqdevice.com/api/v4/User/Validate'; |
|
| 37 | - protected $_getDeviceDetailUrl = 'https://myqexternal.myqdevice.com/api/v4/userdevicedetails/get?&filterOn=true'; |
|
| 38 | - protected $_putDeviceStateUrl = '/api/v4/DeviceAttribute/PutDeviceAttribute'; |
|
| 39 | - /** @var resource|null $_conn is the web connection to the MyQ API */ |
|
| 40 | - protected $_conn = null; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Initializes class. Optionally allows user to override variables. |
|
| 44 | - * |
|
| 45 | - * @param array $params A associative array for overwriting class variables |
|
| 46 | - * |
|
| 47 | - * @return MyQ |
|
| 48 | - */ |
|
| 49 | - public function __construct($params = []) |
|
| 50 | - { |
|
| 51 | - // Overwrite class variables |
|
| 52 | - foreach ($params as $k => $v) { |
|
| 53 | - $this->$k = $v; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Initialize cURL request headers |
|
| 57 | - if (0 == sizeof($this->_headers)) { |
|
| 58 | - $this->_headers = [ |
|
| 59 | - 'MyQApplicationId' => $this->appId, |
|
| 60 | - 'Culture' => $this->culture, |
|
| 61 | - 'Content-Type' => $this->contentType, |
|
| 62 | - 'User-Agent' => $this->userAgent, |
|
| 63 | - ]; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // Initialize cURL connection |
|
| 67 | - $this->_init(); |
|
| 68 | - |
|
| 69 | - return $this; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Perform a login request. |
|
| 74 | - * |
|
| 75 | - * @param string|null $username Username to use when logging in |
|
| 76 | - * @param string|null $password Password to use for logging in |
|
| 77 | - * |
|
| 78 | - * @return MyQ |
|
| 79 | - */ |
|
| 80 | - public function login($username = null, $password = null) |
|
| 81 | - { |
|
| 82 | - // Set username/password if not null |
|
| 83 | - if (!is_null($username)) { |
|
| 84 | - $this->username = $username; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if (!is_null($password)) { |
|
| 88 | - $this->password = $password; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // confirm that we have a valid username/password |
|
| 92 | - $error = []; |
|
| 93 | - if (is_null($this->username)) { |
|
| 94 | - $error[] = 'username'; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (is_null($this->password)) { |
|
| 98 | - $error[] = 'password'; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if (sizeof($error) > 0) { |
|
| 102 | - throw new MyQException('Missing required auth credential: '.implode(',', $error)); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $this->_login(); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function getState() |
|
| 109 | - { |
|
| 110 | - $this->_getDetails(); |
|
| 111 | - $timeInState = time() - $this->_doorStateTime; |
|
| 112 | - echo implode(',', [ |
|
| 113 | - $this->_locationName, |
|
| 114 | - $this->_doorName, |
|
| 115 | - $this->_doorState, |
|
| 116 | - (int) $timeInState, |
|
| 117 | - ]); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - public function getDetails() |
|
| 121 | - { |
|
| 122 | - return $this->_getDetails(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - private function _init() |
|
| 126 | - { |
|
| 127 | - if (!isset($this->_conn)) { |
|
| 128 | - $this->_conn = curl_init(); |
|
| 129 | - |
|
| 130 | - curl_setopt_array($this->_conn, [ |
|
| 131 | - CURLOPT_RETURNTRANSFER => true, |
|
| 132 | - CURLOPT_ENCODING => '', |
|
| 133 | - CURLOPT_MAXREDIRS => 10, |
|
| 134 | - CURLOPT_TIMEOUT => 30, |
|
| 135 | - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
| 136 | - CURLOPT_FAILONERROR => true, |
|
| 137 | - CURLOPT_FOLLOWLOCATION => true, |
|
| 138 | - CURLOPT_FRESH_CONNECT => true, |
|
| 139 | - CURLOPT_FORBID_REUSE => true, |
|
| 140 | - CURLOPT_USERAGENT => $this->userAgent, |
|
| 141 | - ]); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $this->_setHeaders(); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - private function _setHeaders() |
|
| 148 | - { |
|
| 149 | - $headers = []; |
|
| 150 | - |
|
| 151 | - foreach ($this->_headers as $k => $v) { |
|
| 152 | - $headers[] = "$k: $v"; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - curl_setopt($this->_conn, CURLOPT_HTTPHEADER, $headers); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - private function _login() |
|
| 159 | - { |
|
| 160 | - $this->_init(); |
|
| 161 | - |
|
| 162 | - curl_setopt($this->_conn, CURLOPT_CUSTOMREQUEST, 'POST'); |
|
| 163 | - curl_setopt($this->_conn, CURLOPT_URL, $this->_loginUrl); |
|
| 164 | - |
|
| 165 | - $post = json_encode(['username' => $this->username, 'password' => $this->password]); |
|
| 166 | - |
|
| 167 | - curl_setopt($this->_conn, CURLOPT_POSTFIELDS, $post); |
|
| 168 | - |
|
| 169 | - $output = curl_exec($this->_conn); |
|
| 170 | - |
|
| 171 | - $data = json_decode($output); |
|
| 172 | - |
|
| 173 | - if (false == $data || !isset($data->SecurityToken)) { |
|
| 174 | - throw new MyQException("Error processing login request: $output"); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $this->_headers['SecurityToken'] = $data->SecurityToken; |
|
| 178 | - |
|
| 179 | - return $this; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - private function _getDetails() |
|
| 183 | - { |
|
| 184 | - $this->_init(); |
|
| 185 | - |
|
| 186 | - curl_setopt($this->_conn, CURLOPT_CUSTOMREQUEST, 'GET'); |
|
| 187 | - curl_setopt($this->_conn, CURLOPT_URL, $this->_getDeviceDetailUrl); |
|
| 188 | - |
|
| 189 | - $output = curl_exec($this->_conn); |
|
| 190 | - |
|
| 191 | - $data = json_decode($output); |
|
| 192 | - |
|
| 193 | - if (false == $data || !isset($data->Devices)) { |
|
| 194 | - throw new MyQException("Error fetching device details: $output"); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // Find our door device ID |
|
| 198 | - foreach ($data->Devices as $device) { |
|
| 199 | - if (false !== stripos($device->MyQDeviceTypeName, 'Gateway')) { |
|
| 200 | - // Find location name |
|
| 201 | - foreach ($device->Attributes as $attr) { |
|
| 202 | - if ('desc' == $attr->AttributeDisplayName) { |
|
| 203 | - $this->_locationName = $attr->Value; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $this->_deviceId = $device->MyQDeviceId; |
|
| 209 | - |
|
| 210 | - foreach ($device->Attributes as $attr) { |
|
| 211 | - switch ($attr->AttributeDisplayName) { |
|
| 212 | - case 'desc': |
|
| 213 | - $this->_doorName = $attr->Value; |
|
| 214 | - break; |
|
| 215 | - case 'doorstate': |
|
| 216 | - $this->_doorState = $attr->Value; |
|
| 217 | - // UpdatedTime is a timestamp in ms, so we truncate |
|
| 218 | - $this->_doorStateTime = (int) $attr->UpdatedTime / 1000; |
|
| 219 | - break; |
|
| 220 | - default: |
|
| 221 | - continue; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 16 | + /** @var string|null $username contains the username used to authenticate with the MyQ API */ |
|
| 17 | + protected $username = null; |
|
| 18 | + /** @var string|null $password contains the password used to authenticate with the MyQ API */ |
|
| 19 | + protected $password = null; |
|
| 20 | + /** @var string|null $appId is the application ID used to register with the MyQ API */ |
|
| 21 | + protected $appId = 'NWknvuBd7LoFHfXmKNMBcgajXtZEgKUh4V7WNzMidrpUUluDpVYVZx+xT4PCM5Kx'; |
|
| 22 | + //protected $appId = 'Vj8pQggXLhLy0WHahglCD4N1nAkkXQtGYpq2HrHD7H1nvmbT55KqtN6RSF4ILB%2fi'; |
|
| 23 | + /** @var string|null $securityToken is the auth token returned after a successful login */ |
|
| 24 | + protected $securityToken = null; |
|
| 25 | + /** @var string|null $userAgent is the User-Agent header value sent with each API request */ |
|
| 26 | + protected $userAgent = 'Chamberlain/3.4.1'; |
|
| 27 | + /** @var string|null $culture is the API culture code for the API */ |
|
| 28 | + protected $culture = 'en'; |
|
| 29 | + /** @var string|null $contentType is the content type used for all cURL requests */ |
|
| 30 | + protected $contentType = 'application/json'; |
|
| 31 | + /** @var array $headers contain HTTP headers for cURL requests */ |
|
| 32 | + protected $_headers = []; |
|
| 33 | + protected $_deviceId = null; |
|
| 34 | + protected $_locationName = null; |
|
| 35 | + protected $_doorName = null; |
|
| 36 | + protected $_loginUrl = 'https://myqexternal.myqdevice.com/api/v4/User/Validate'; |
|
| 37 | + protected $_getDeviceDetailUrl = 'https://myqexternal.myqdevice.com/api/v4/userdevicedetails/get?&filterOn=true'; |
|
| 38 | + protected $_putDeviceStateUrl = '/api/v4/DeviceAttribute/PutDeviceAttribute'; |
|
| 39 | + /** @var resource|null $_conn is the web connection to the MyQ API */ |
|
| 40 | + protected $_conn = null; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Initializes class. Optionally allows user to override variables. |
|
| 44 | + * |
|
| 45 | + * @param array $params A associative array for overwriting class variables |
|
| 46 | + * |
|
| 47 | + * @return MyQ |
|
| 48 | + */ |
|
| 49 | + public function __construct($params = []) |
|
| 50 | + { |
|
| 51 | + // Overwrite class variables |
|
| 52 | + foreach ($params as $k => $v) { |
|
| 53 | + $this->$k = $v; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Initialize cURL request headers |
|
| 57 | + if (0 == sizeof($this->_headers)) { |
|
| 58 | + $this->_headers = [ |
|
| 59 | + 'MyQApplicationId' => $this->appId, |
|
| 60 | + 'Culture' => $this->culture, |
|
| 61 | + 'Content-Type' => $this->contentType, |
|
| 62 | + 'User-Agent' => $this->userAgent, |
|
| 63 | + ]; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // Initialize cURL connection |
|
| 67 | + $this->_init(); |
|
| 68 | + |
|
| 69 | + return $this; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Perform a login request. |
|
| 74 | + * |
|
| 75 | + * @param string|null $username Username to use when logging in |
|
| 76 | + * @param string|null $password Password to use for logging in |
|
| 77 | + * |
|
| 78 | + * @return MyQ |
|
| 79 | + */ |
|
| 80 | + public function login($username = null, $password = null) |
|
| 81 | + { |
|
| 82 | + // Set username/password if not null |
|
| 83 | + if (!is_null($username)) { |
|
| 84 | + $this->username = $username; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if (!is_null($password)) { |
|
| 88 | + $this->password = $password; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // confirm that we have a valid username/password |
|
| 92 | + $error = []; |
|
| 93 | + if (is_null($this->username)) { |
|
| 94 | + $error[] = 'username'; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (is_null($this->password)) { |
|
| 98 | + $error[] = 'password'; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if (sizeof($error) > 0) { |
|
| 102 | + throw new MyQException('Missing required auth credential: '.implode(',', $error)); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $this->_login(); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function getState() |
|
| 109 | + { |
|
| 110 | + $this->_getDetails(); |
|
| 111 | + $timeInState = time() - $this->_doorStateTime; |
|
| 112 | + echo implode(',', [ |
|
| 113 | + $this->_locationName, |
|
| 114 | + $this->_doorName, |
|
| 115 | + $this->_doorState, |
|
| 116 | + (int) $timeInState, |
|
| 117 | + ]); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + public function getDetails() |
|
| 121 | + { |
|
| 122 | + return $this->_getDetails(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + private function _init() |
|
| 126 | + { |
|
| 127 | + if (!isset($this->_conn)) { |
|
| 128 | + $this->_conn = curl_init(); |
|
| 129 | + |
|
| 130 | + curl_setopt_array($this->_conn, [ |
|
| 131 | + CURLOPT_RETURNTRANSFER => true, |
|
| 132 | + CURLOPT_ENCODING => '', |
|
| 133 | + CURLOPT_MAXREDIRS => 10, |
|
| 134 | + CURLOPT_TIMEOUT => 30, |
|
| 135 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
| 136 | + CURLOPT_FAILONERROR => true, |
|
| 137 | + CURLOPT_FOLLOWLOCATION => true, |
|
| 138 | + CURLOPT_FRESH_CONNECT => true, |
|
| 139 | + CURLOPT_FORBID_REUSE => true, |
|
| 140 | + CURLOPT_USERAGENT => $this->userAgent, |
|
| 141 | + ]); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $this->_setHeaders(); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + private function _setHeaders() |
|
| 148 | + { |
|
| 149 | + $headers = []; |
|
| 150 | + |
|
| 151 | + foreach ($this->_headers as $k => $v) { |
|
| 152 | + $headers[] = "$k: $v"; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + curl_setopt($this->_conn, CURLOPT_HTTPHEADER, $headers); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + private function _login() |
|
| 159 | + { |
|
| 160 | + $this->_init(); |
|
| 161 | + |
|
| 162 | + curl_setopt($this->_conn, CURLOPT_CUSTOMREQUEST, 'POST'); |
|
| 163 | + curl_setopt($this->_conn, CURLOPT_URL, $this->_loginUrl); |
|
| 164 | + |
|
| 165 | + $post = json_encode(['username' => $this->username, 'password' => $this->password]); |
|
| 166 | + |
|
| 167 | + curl_setopt($this->_conn, CURLOPT_POSTFIELDS, $post); |
|
| 168 | + |
|
| 169 | + $output = curl_exec($this->_conn); |
|
| 170 | + |
|
| 171 | + $data = json_decode($output); |
|
| 172 | + |
|
| 173 | + if (false == $data || !isset($data->SecurityToken)) { |
|
| 174 | + throw new MyQException("Error processing login request: $output"); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $this->_headers['SecurityToken'] = $data->SecurityToken; |
|
| 178 | + |
|
| 179 | + return $this; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + private function _getDetails() |
|
| 183 | + { |
|
| 184 | + $this->_init(); |
|
| 185 | + |
|
| 186 | + curl_setopt($this->_conn, CURLOPT_CUSTOMREQUEST, 'GET'); |
|
| 187 | + curl_setopt($this->_conn, CURLOPT_URL, $this->_getDeviceDetailUrl); |
|
| 188 | + |
|
| 189 | + $output = curl_exec($this->_conn); |
|
| 190 | + |
|
| 191 | + $data = json_decode($output); |
|
| 192 | + |
|
| 193 | + if (false == $data || !isset($data->Devices)) { |
|
| 194 | + throw new MyQException("Error fetching device details: $output"); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // Find our door device ID |
|
| 198 | + foreach ($data->Devices as $device) { |
|
| 199 | + if (false !== stripos($device->MyQDeviceTypeName, 'Gateway')) { |
|
| 200 | + // Find location name |
|
| 201 | + foreach ($device->Attributes as $attr) { |
|
| 202 | + if ('desc' == $attr->AttributeDisplayName) { |
|
| 203 | + $this->_locationName = $attr->Value; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $this->_deviceId = $device->MyQDeviceId; |
|
| 209 | + |
|
| 210 | + foreach ($device->Attributes as $attr) { |
|
| 211 | + switch ($attr->AttributeDisplayName) { |
|
| 212 | + case 'desc': |
|
| 213 | + $this->_doorName = $attr->Value; |
|
| 214 | + break; |
|
| 215 | + case 'doorstate': |
|
| 216 | + $this->_doorState = $attr->Value; |
|
| 217 | + // UpdatedTime is a timestamp in ms, so we truncate |
|
| 218 | + $this->_doorStateTime = (int) $attr->UpdatedTime / 1000; |
|
| 219 | + break; |
|
| 220 | + default: |
|
| 221 | + continue; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | 226 | } |
@@ -209,16 +209,16 @@ |
||
| 209 | 209 | |
| 210 | 210 | foreach ($device->Attributes as $attr) { |
| 211 | 211 | switch ($attr->AttributeDisplayName) { |
| 212 | - case 'desc': |
|
| 213 | - $this->_doorName = $attr->Value; |
|
| 214 | - break; |
|
| 215 | - case 'doorstate': |
|
| 216 | - $this->_doorState = $attr->Value; |
|
| 217 | - // UpdatedTime is a timestamp in ms, so we truncate |
|
| 218 | - $this->_doorStateTime = (int) $attr->UpdatedTime / 1000; |
|
| 219 | - break; |
|
| 220 | - default: |
|
| 221 | - continue; |
|
| 212 | + case 'desc': |
|
| 213 | + $this->_doorName = $attr->Value; |
|
| 214 | + break; |
|
| 215 | + case 'doorstate': |
|
| 216 | + $this->_doorState = $attr->Value; |
|
| 217 | + // UpdatedTime is a timestamp in ms, so we truncate |
|
| 218 | + $this->_doorStateTime = (int) $attr->UpdatedTime / 1000; |
|
| 219 | + break; |
|
| 220 | + default: |
|
| 221 | + continue; |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // Initialize cURL request headers |
| 57 | - if (0 == sizeof($this->_headers)) { |
|
| 57 | + if (0==sizeof($this->_headers)) { |
|
| 58 | 58 | $this->_headers = [ |
| 59 | 59 | 'MyQApplicationId' => $this->appId, |
| 60 | 60 | 'Culture' => $this->culture, |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $error[] = 'password'; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - if (sizeof($error) > 0) { |
|
| 101 | + if (sizeof($error)>0) { |
|
| 102 | 102 | throw new MyQException('Missing required auth credential: '.implode(',', $error)); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $this->_locationName, |
| 114 | 114 | $this->_doorName, |
| 115 | 115 | $this->_doorState, |
| 116 | - (int) $timeInState, |
|
| 116 | + (int)$timeInState, |
|
| 117 | 117 | ]); |
| 118 | 118 | } |
| 119 | 119 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | $data = json_decode($output); |
| 172 | 172 | |
| 173 | - if (false == $data || !isset($data->SecurityToken)) { |
|
| 173 | + if (false==$data || !isset($data->SecurityToken)) { |
|
| 174 | 174 | throw new MyQException("Error processing login request: $output"); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -190,16 +190,16 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | $data = json_decode($output); |
| 192 | 192 | |
| 193 | - if (false == $data || !isset($data->Devices)) { |
|
| 193 | + if (false==$data || !isset($data->Devices)) { |
|
| 194 | 194 | throw new MyQException("Error fetching device details: $output"); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | // Find our door device ID |
| 198 | 198 | foreach ($data->Devices as $device) { |
| 199 | - if (false !== stripos($device->MyQDeviceTypeName, 'Gateway')) { |
|
| 199 | + if (false!==stripos($device->MyQDeviceTypeName, 'Gateway')) { |
|
| 200 | 200 | // Find location name |
| 201 | 201 | foreach ($device->Attributes as $attr) { |
| 202 | - if ('desc' == $attr->AttributeDisplayName) { |
|
| 202 | + if ('desc'==$attr->AttributeDisplayName) { |
|
| 203 | 203 | $this->_locationName = $attr->Value; |
| 204 | 204 | } |
| 205 | 205 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | case 'doorstate': |
| 216 | 216 | $this->_doorState = $attr->Value; |
| 217 | 217 | // UpdatedTime is a timestamp in ms, so we truncate |
| 218 | - $this->_doorStateTime = (int) $attr->UpdatedTime / 1000; |
|
| 218 | + $this->_doorStateTime = (int)$attr->UpdatedTime / 1000; |
|
| 219 | 219 | break; |
| 220 | 220 | default: |
| 221 | 221 | continue; |
@@ -4,380 +4,380 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class CurlHttpClient |
| 6 | 6 | { |
| 7 | - public $ch; |
|
| 8 | - public $debug = false; |
|
| 9 | - public $error_msg; |
|
| 10 | - |
|
| 11 | - public function CurlHttpClient($debug = false) |
|
| 12 | - { |
|
| 13 | - $this->debug = $debug; |
|
| 14 | - $this->init(); |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - public function init() |
|
| 18 | - { |
|
| 19 | - // initialize curl handle |
|
| 20 | - $this->ch = curl_init(); |
|
| 21 | - //set various options |
|
| 22 | - //set error in case http return code bigger than 300 |
|
| 23 | - curl_setopt($this->ch, CURLOPT_FAILONERROR, true); |
|
| 24 | - // use gzip if possible |
|
| 25 | - curl_setopt($this->ch, CURLOPT_ENCODING, 'gzip, deflate'); |
|
| 26 | - // do not veryfy ssl |
|
| 27 | - // this is important for windows |
|
| 28 | - // as well for being able to access pages with non valid cert |
|
| 29 | - curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Set username/pass for basic http auth. |
|
| 34 | - * |
|
| 35 | - * @param string user |
|
| 36 | - * @param string pass |
|
| 37 | - */ |
|
| 38 | - public function setCredentials($username, $password) |
|
| 39 | - { |
|
| 40 | - curl_setopt($this->ch, CURLOPT_USERPWD, "$username:$password"); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Set referrer. |
|
| 45 | - * |
|
| 46 | - * @param string referrer url |
|
| 47 | - */ |
|
| 48 | - public function setReferrer($referrer_url) |
|
| 49 | - { |
|
| 50 | - curl_setopt($this->ch, CURLOPT_REFERER, $referrer_url); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Set client's userAgent. |
|
| 55 | - * |
|
| 56 | - * @param string user agent |
|
| 57 | - */ |
|
| 58 | - public function setUserAgent($userAgent) |
|
| 59 | - { |
|
| 60 | - curl_setopt($this->ch, CURLOPT_USERAGENT, $userAgent); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Set to receive output headers in all output functions. |
|
| 65 | - * |
|
| 66 | - * @param bool true to include all response headers with output, false otherwise |
|
| 67 | - */ |
|
| 68 | - public function includeResponseHeaders($value) |
|
| 69 | - { |
|
| 70 | - curl_setopt($this->ch, CURLOPT_HEADER, $value); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Set proxy to use for each curl request. |
|
| 75 | - * |
|
| 76 | - * @param string proxy |
|
| 77 | - */ |
|
| 78 | - public function setProxy($proxy) |
|
| 79 | - { |
|
| 80 | - curl_setopt($this->ch, CURLOPT_PROXY, $proxy); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Send post data to target URL |
|
| 85 | - * return data returned from url or false if error occured. |
|
| 86 | - * |
|
| 87 | - * @param string url |
|
| 88 | - * @param mixed post data (assoc array ie. $foo['post_var_name'] = $value or as string like var=val1&var2=val2) |
|
| 89 | - * @param string ip address to bind (default null) |
|
| 90 | - * @param int timeout in sec for complete curl operation (default 10) |
|
| 91 | - * |
|
| 92 | - * @return string data |
|
| 93 | - */ |
|
| 94 | - public function sendPostData($url, $postdata, $ip = null, $timeout = 10) |
|
| 95 | - { |
|
| 96 | - //set various curl options first |
|
| 97 | - // set url to post to |
|
| 98 | - curl_setopt($this->ch, CURLOPT_URL, $url); |
|
| 99 | - // return into a variable rather than displaying it |
|
| 100 | - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
| 101 | - |
|
| 102 | - //bind to specific ip address if it is sent trough arguments |
|
| 103 | - if ($ip) { |
|
| 104 | - if ($this->debug) { |
|
| 105 | - echo "Binding to ip $ip\n"; |
|
| 106 | - } |
|
| 107 | - curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - //set curl function timeout to $timeout |
|
| 111 | - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 112 | - |
|
| 113 | - //set method to post |
|
| 114 | - curl_setopt($this->ch, CURLOPT_POST, true); |
|
| 115 | - // set post string |
|
| 116 | - curl_setopt($this->ch, CURLOPT_POSTFIELDS, $postdata); |
|
| 117 | - |
|
| 118 | - //and finally send curl request |
|
| 119 | - $result = curl_exec_redir($this->ch); |
|
| 120 | - if (curl_errno($this->ch)) { |
|
| 121 | - if ($this->debug) { |
|
| 122 | - echo "Error Occured in Curl\n"; |
|
| 123 | - echo 'Error number: '.curl_errno($this->ch)."\n"; |
|
| 124 | - echo 'Error message: '.curl_error($this->ch)."\n"; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return false; |
|
| 128 | - } else { |
|
| 129 | - return $result; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * fetch data from target URL |
|
| 135 | - * return data returned from url or false if error occured. |
|
| 136 | - * |
|
| 137 | - * @param string url |
|
| 138 | - * @param string ip address to bind (default null) |
|
| 139 | - * @param int timeout in sec for complete curl operation (default 5) |
|
| 140 | - * |
|
| 141 | - * @return string data |
|
| 142 | - */ |
|
| 143 | - public function fetchUrl($url, $ip = null, $timeout = 5) |
|
| 144 | - { |
|
| 145 | - // set url to post to |
|
| 146 | - curl_setopt($this->ch, CURLOPT_URL, $url); |
|
| 147 | - |
|
| 148 | - //set method to get |
|
| 149 | - curl_setopt($this->ch, CURLOPT_HTTPGET, true); |
|
| 150 | - // return into a variable rather than displaying it |
|
| 151 | - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
| 152 | - |
|
| 153 | - //bind to specific ip address if it is sent trough arguments |
|
| 154 | - if ($ip) { |
|
| 155 | - if ($this->debug) { |
|
| 156 | - echo "Binding to ip $ip\n"; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - //set curl function timeout to $timeout |
|
| 163 | - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 164 | - |
|
| 165 | - //and finally send curl request |
|
| 166 | - $result = curl_exec_redir($this->ch); |
|
| 167 | - if (curl_errno($this->ch)) { |
|
| 168 | - if ($this->debug) { |
|
| 169 | - echo "Error Occured in Curl\n"; |
|
| 170 | - echo 'Error number: '.curl_errno($this->ch)."\n"; |
|
| 171 | - echo 'Error message: '.curl_error($this->ch)."\n"; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return false; |
|
| 175 | - } else { |
|
| 176 | - return $result; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Fetch data from target URL |
|
| 182 | - * and store it directly to file. |
|
| 183 | - * |
|
| 184 | - * @param string url |
|
| 185 | - * @param resource value stream resource(ie. fopen) |
|
| 186 | - * @param string ip address to bind (default null) |
|
| 187 | - * @param int timeout in sec for complete curl operation (default 5) |
|
| 188 | - * |
|
| 189 | - * @return bool true on success false othervise |
|
| 190 | - */ |
|
| 191 | - public function fetchIntoFile($url, $fp, $ip = null, $timeout = 5) |
|
| 192 | - { |
|
| 193 | - // set url to post to |
|
| 194 | - curl_setopt($this->ch, CURLOPT_URL, $url); |
|
| 195 | - //set method to get |
|
| 196 | - curl_setopt($this->ch, CURLOPT_HTTPGET, true); |
|
| 197 | - // store data into file rather than displaying it |
|
| 198 | - curl_setopt($this->ch, CURLOPT_FILE, $fp); |
|
| 199 | - |
|
| 200 | - //bind to specific ip address if it is sent trough arguments |
|
| 201 | - if ($ip) { |
|
| 202 | - if ($this->debug) { |
|
| 203 | - echo "Binding to ip $ip\n"; |
|
| 204 | - } |
|
| 205 | - curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - //set curl function timeout to $timeout |
|
| 209 | - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 210 | - |
|
| 211 | - //and finally send curl request |
|
| 212 | - $result = curl_exec_redir($this->ch); |
|
| 213 | - if (curl_errno($this->ch)) { |
|
| 214 | - if ($this->debug) { |
|
| 215 | - echo "Error Occured in Curl\n"; |
|
| 216 | - echo 'Error number: '.curl_errno($this->ch)."\n"; |
|
| 217 | - echo 'Error message: '.curl_error($this->ch)."\n"; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return false; |
|
| 221 | - } else { |
|
| 222 | - return true; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Send multipart post data to the target URL |
|
| 228 | - * return data returned from url or false if error occured |
|
| 229 | - * (contribution by vule nikolic, [email protected]). |
|
| 230 | - * |
|
| 231 | - * @param string url |
|
| 232 | - * @param array assoc post data array ie. $foo['post_var_name'] = $value |
|
| 233 | - * @param array assoc $file_field_array, contains file_field name = value - path pairs |
|
| 234 | - * @param string ip address to bind (default null) |
|
| 235 | - * @param int timeout in sec for complete curl operation (default 30 sec) |
|
| 236 | - * |
|
| 237 | - * @return string data |
|
| 238 | - */ |
|
| 239 | - public function sendMultipartPostData($url, $postdata, $file_field_array = [], $ip = null, $timeout = 30) |
|
| 240 | - { |
|
| 241 | - //set various curl options first |
|
| 242 | - // set url to post to |
|
| 243 | - curl_setopt($this->ch, CURLOPT_URL, $url); |
|
| 244 | - // return into a variable rather than displaying it |
|
| 245 | - curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
| 246 | - |
|
| 247 | - //bind to specific ip address if it is sent trough arguments |
|
| 248 | - if ($ip) { |
|
| 249 | - if ($this->debug) { |
|
| 250 | - echo "Binding to ip $ip\n"; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - //set curl function timeout to $timeout |
|
| 257 | - curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 258 | - //set method to post |
|
| 259 | - curl_setopt($this->ch, CURLOPT_POST, true); |
|
| 260 | - // disable Expect header |
|
| 261 | - // hack to make it working |
|
| 262 | - $headers = ['Expect: ']; |
|
| 263 | - curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers); |
|
| 264 | - // initialize result post array |
|
| 265 | - $result_post = []; |
|
| 266 | - //generate post string |
|
| 267 | - $post_array = []; |
|
| 268 | - $post_string_array = []; |
|
| 269 | - |
|
| 270 | - if (!is_array($postdata)) { |
|
| 271 | - return false; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - foreach ($postdata as $key => $value) { |
|
| 275 | - $post_array[$key] = $value; |
|
| 276 | - $post_string_array[] = urlencode($key).'='.urlencode($value); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $post_string = implode('&', $post_string_array); |
|
| 280 | - if ($this->debug) { |
|
| 281 | - echo "Post String: $post_string\n"; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - // set post string |
|
| 285 | - //curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_string); |
|
| 286 | - // set multipart form data - file array field-value pairs |
|
| 287 | - if (!empty($file_field_array)) { |
|
| 288 | - foreach ($file_field_array as $var_name => $var_value) { |
|
| 289 | - if (false !== strpos(PHP_OS, 'WIN')) { |
|
| 290 | - $var_value = str_replace('/', '\\', $var_value); |
|
| 291 | - } // win hack |
|
| 292 | - $file_field_array[$var_name] = '@'.$var_value; |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - // set post data |
|
| 297 | - $result_post = array_merge($post_array, $file_field_array); |
|
| 298 | - curl_setopt($this->ch, CURLOPT_POSTFIELDS, $result_post); |
|
| 299 | - |
|
| 300 | - //and finally send curl request |
|
| 301 | - $result = curl_exec_redir($this->ch); |
|
| 302 | - if (curl_errno($this->ch)) { |
|
| 303 | - if ($this->debug) { |
|
| 304 | - echo "Error Occured in Curl\n"; |
|
| 305 | - echo 'Error number: '.curl_errno($this->ch)."\n"; |
|
| 306 | - echo 'Error message: '.curl_error($this->ch)."\n"; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - return false; |
|
| 310 | - } else { |
|
| 311 | - return $result; |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Set file location where cookie data will be stored and send on each new request. |
|
| 317 | - * |
|
| 318 | - * @param string absolute path to cookie file (must be in writable dir) |
|
| 319 | - */ |
|
| 320 | - public function storeCookies($cookie_file) |
|
| 321 | - { |
|
| 322 | - // use cookies on each request (cookies stored in $cookie_file) |
|
| 323 | - curl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookie_file); |
|
| 324 | - curl_setopt($this->ch, CURLOPT_COOKIEFILE, $cookie_file); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Set custom cookie. |
|
| 329 | - * |
|
| 330 | - * @param string cookie |
|
| 331 | - */ |
|
| 332 | - public function setCookie($cookie) |
|
| 333 | - { |
|
| 334 | - curl_setopt($this->ch, CURLOPT_COOKIE, $cookie); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Get last URL info |
|
| 339 | - * usefull when original url was redirected to other location. |
|
| 340 | - * |
|
| 341 | - * @return string url |
|
| 342 | - */ |
|
| 343 | - public function getEffectiveUrl() |
|
| 344 | - { |
|
| 345 | - return curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Get http response code. |
|
| 350 | - * |
|
| 351 | - * @return int |
|
| 352 | - */ |
|
| 353 | - public function getHttpResponseCode() |
|
| 354 | - { |
|
| 355 | - return curl_getinfo($this->ch, CURLINFO_HTTP_CODE); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Return last error message and error number. |
|
| 360 | - * |
|
| 361 | - * @return string error msg |
|
| 362 | - */ |
|
| 363 | - public function getErrorMsg() |
|
| 364 | - { |
|
| 365 | - $err = 'Error number: '.curl_errno($this->ch)."\n"; |
|
| 366 | - $err .= 'Error message: '.curl_error($this->ch)."\n"; |
|
| 367 | - |
|
| 368 | - return $err; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Close curl session and free resource |
|
| 373 | - * Usually no need to call this function directly |
|
| 374 | - * in case you do you have to call init() to recreate curl. |
|
| 375 | - */ |
|
| 376 | - public function close() |
|
| 377 | - { |
|
| 378 | - //close curl session and free up resources |
|
| 379 | - curl_close($this->ch); |
|
| 380 | - } |
|
| 7 | + public $ch; |
|
| 8 | + public $debug = false; |
|
| 9 | + public $error_msg; |
|
| 10 | + |
|
| 11 | + public function CurlHttpClient($debug = false) |
|
| 12 | + { |
|
| 13 | + $this->debug = $debug; |
|
| 14 | + $this->init(); |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + public function init() |
|
| 18 | + { |
|
| 19 | + // initialize curl handle |
|
| 20 | + $this->ch = curl_init(); |
|
| 21 | + //set various options |
|
| 22 | + //set error in case http return code bigger than 300 |
|
| 23 | + curl_setopt($this->ch, CURLOPT_FAILONERROR, true); |
|
| 24 | + // use gzip if possible |
|
| 25 | + curl_setopt($this->ch, CURLOPT_ENCODING, 'gzip, deflate'); |
|
| 26 | + // do not veryfy ssl |
|
| 27 | + // this is important for windows |
|
| 28 | + // as well for being able to access pages with non valid cert |
|
| 29 | + curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Set username/pass for basic http auth. |
|
| 34 | + * |
|
| 35 | + * @param string user |
|
| 36 | + * @param string pass |
|
| 37 | + */ |
|
| 38 | + public function setCredentials($username, $password) |
|
| 39 | + { |
|
| 40 | + curl_setopt($this->ch, CURLOPT_USERPWD, "$username:$password"); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Set referrer. |
|
| 45 | + * |
|
| 46 | + * @param string referrer url |
|
| 47 | + */ |
|
| 48 | + public function setReferrer($referrer_url) |
|
| 49 | + { |
|
| 50 | + curl_setopt($this->ch, CURLOPT_REFERER, $referrer_url); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Set client's userAgent. |
|
| 55 | + * |
|
| 56 | + * @param string user agent |
|
| 57 | + */ |
|
| 58 | + public function setUserAgent($userAgent) |
|
| 59 | + { |
|
| 60 | + curl_setopt($this->ch, CURLOPT_USERAGENT, $userAgent); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Set to receive output headers in all output functions. |
|
| 65 | + * |
|
| 66 | + * @param bool true to include all response headers with output, false otherwise |
|
| 67 | + */ |
|
| 68 | + public function includeResponseHeaders($value) |
|
| 69 | + { |
|
| 70 | + curl_setopt($this->ch, CURLOPT_HEADER, $value); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Set proxy to use for each curl request. |
|
| 75 | + * |
|
| 76 | + * @param string proxy |
|
| 77 | + */ |
|
| 78 | + public function setProxy($proxy) |
|
| 79 | + { |
|
| 80 | + curl_setopt($this->ch, CURLOPT_PROXY, $proxy); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Send post data to target URL |
|
| 85 | + * return data returned from url or false if error occured. |
|
| 86 | + * |
|
| 87 | + * @param string url |
|
| 88 | + * @param mixed post data (assoc array ie. $foo['post_var_name'] = $value or as string like var=val1&var2=val2) |
|
| 89 | + * @param string ip address to bind (default null) |
|
| 90 | + * @param int timeout in sec for complete curl operation (default 10) |
|
| 91 | + * |
|
| 92 | + * @return string data |
|
| 93 | + */ |
|
| 94 | + public function sendPostData($url, $postdata, $ip = null, $timeout = 10) |
|
| 95 | + { |
|
| 96 | + //set various curl options first |
|
| 97 | + // set url to post to |
|
| 98 | + curl_setopt($this->ch, CURLOPT_URL, $url); |
|
| 99 | + // return into a variable rather than displaying it |
|
| 100 | + curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
| 101 | + |
|
| 102 | + //bind to specific ip address if it is sent trough arguments |
|
| 103 | + if ($ip) { |
|
| 104 | + if ($this->debug) { |
|
| 105 | + echo "Binding to ip $ip\n"; |
|
| 106 | + } |
|
| 107 | + curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + //set curl function timeout to $timeout |
|
| 111 | + curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 112 | + |
|
| 113 | + //set method to post |
|
| 114 | + curl_setopt($this->ch, CURLOPT_POST, true); |
|
| 115 | + // set post string |
|
| 116 | + curl_setopt($this->ch, CURLOPT_POSTFIELDS, $postdata); |
|
| 117 | + |
|
| 118 | + //and finally send curl request |
|
| 119 | + $result = curl_exec_redir($this->ch); |
|
| 120 | + if (curl_errno($this->ch)) { |
|
| 121 | + if ($this->debug) { |
|
| 122 | + echo "Error Occured in Curl\n"; |
|
| 123 | + echo 'Error number: '.curl_errno($this->ch)."\n"; |
|
| 124 | + echo 'Error message: '.curl_error($this->ch)."\n"; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return false; |
|
| 128 | + } else { |
|
| 129 | + return $result; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * fetch data from target URL |
|
| 135 | + * return data returned from url or false if error occured. |
|
| 136 | + * |
|
| 137 | + * @param string url |
|
| 138 | + * @param string ip address to bind (default null) |
|
| 139 | + * @param int timeout in sec for complete curl operation (default 5) |
|
| 140 | + * |
|
| 141 | + * @return string data |
|
| 142 | + */ |
|
| 143 | + public function fetchUrl($url, $ip = null, $timeout = 5) |
|
| 144 | + { |
|
| 145 | + // set url to post to |
|
| 146 | + curl_setopt($this->ch, CURLOPT_URL, $url); |
|
| 147 | + |
|
| 148 | + //set method to get |
|
| 149 | + curl_setopt($this->ch, CURLOPT_HTTPGET, true); |
|
| 150 | + // return into a variable rather than displaying it |
|
| 151 | + curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
| 152 | + |
|
| 153 | + //bind to specific ip address if it is sent trough arguments |
|
| 154 | + if ($ip) { |
|
| 155 | + if ($this->debug) { |
|
| 156 | + echo "Binding to ip $ip\n"; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + //set curl function timeout to $timeout |
|
| 163 | + curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 164 | + |
|
| 165 | + //and finally send curl request |
|
| 166 | + $result = curl_exec_redir($this->ch); |
|
| 167 | + if (curl_errno($this->ch)) { |
|
| 168 | + if ($this->debug) { |
|
| 169 | + echo "Error Occured in Curl\n"; |
|
| 170 | + echo 'Error number: '.curl_errno($this->ch)."\n"; |
|
| 171 | + echo 'Error message: '.curl_error($this->ch)."\n"; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return false; |
|
| 175 | + } else { |
|
| 176 | + return $result; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Fetch data from target URL |
|
| 182 | + * and store it directly to file. |
|
| 183 | + * |
|
| 184 | + * @param string url |
|
| 185 | + * @param resource value stream resource(ie. fopen) |
|
| 186 | + * @param string ip address to bind (default null) |
|
| 187 | + * @param int timeout in sec for complete curl operation (default 5) |
|
| 188 | + * |
|
| 189 | + * @return bool true on success false othervise |
|
| 190 | + */ |
|
| 191 | + public function fetchIntoFile($url, $fp, $ip = null, $timeout = 5) |
|
| 192 | + { |
|
| 193 | + // set url to post to |
|
| 194 | + curl_setopt($this->ch, CURLOPT_URL, $url); |
|
| 195 | + //set method to get |
|
| 196 | + curl_setopt($this->ch, CURLOPT_HTTPGET, true); |
|
| 197 | + // store data into file rather than displaying it |
|
| 198 | + curl_setopt($this->ch, CURLOPT_FILE, $fp); |
|
| 199 | + |
|
| 200 | + //bind to specific ip address if it is sent trough arguments |
|
| 201 | + if ($ip) { |
|
| 202 | + if ($this->debug) { |
|
| 203 | + echo "Binding to ip $ip\n"; |
|
| 204 | + } |
|
| 205 | + curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + //set curl function timeout to $timeout |
|
| 209 | + curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 210 | + |
|
| 211 | + //and finally send curl request |
|
| 212 | + $result = curl_exec_redir($this->ch); |
|
| 213 | + if (curl_errno($this->ch)) { |
|
| 214 | + if ($this->debug) { |
|
| 215 | + echo "Error Occured in Curl\n"; |
|
| 216 | + echo 'Error number: '.curl_errno($this->ch)."\n"; |
|
| 217 | + echo 'Error message: '.curl_error($this->ch)."\n"; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return false; |
|
| 221 | + } else { |
|
| 222 | + return true; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Send multipart post data to the target URL |
|
| 228 | + * return data returned from url or false if error occured |
|
| 229 | + * (contribution by vule nikolic, [email protected]). |
|
| 230 | + * |
|
| 231 | + * @param string url |
|
| 232 | + * @param array assoc post data array ie. $foo['post_var_name'] = $value |
|
| 233 | + * @param array assoc $file_field_array, contains file_field name = value - path pairs |
|
| 234 | + * @param string ip address to bind (default null) |
|
| 235 | + * @param int timeout in sec for complete curl operation (default 30 sec) |
|
| 236 | + * |
|
| 237 | + * @return string data |
|
| 238 | + */ |
|
| 239 | + public function sendMultipartPostData($url, $postdata, $file_field_array = [], $ip = null, $timeout = 30) |
|
| 240 | + { |
|
| 241 | + //set various curl options first |
|
| 242 | + // set url to post to |
|
| 243 | + curl_setopt($this->ch, CURLOPT_URL, $url); |
|
| 244 | + // return into a variable rather than displaying it |
|
| 245 | + curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
| 246 | + |
|
| 247 | + //bind to specific ip address if it is sent trough arguments |
|
| 248 | + if ($ip) { |
|
| 249 | + if ($this->debug) { |
|
| 250 | + echo "Binding to ip $ip\n"; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + curl_setopt($this->ch, CURLOPT_INTERFACE, $ip); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + //set curl function timeout to $timeout |
|
| 257 | + curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout); |
|
| 258 | + //set method to post |
|
| 259 | + curl_setopt($this->ch, CURLOPT_POST, true); |
|
| 260 | + // disable Expect header |
|
| 261 | + // hack to make it working |
|
| 262 | + $headers = ['Expect: ']; |
|
| 263 | + curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers); |
|
| 264 | + // initialize result post array |
|
| 265 | + $result_post = []; |
|
| 266 | + //generate post string |
|
| 267 | + $post_array = []; |
|
| 268 | + $post_string_array = []; |
|
| 269 | + |
|
| 270 | + if (!is_array($postdata)) { |
|
| 271 | + return false; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + foreach ($postdata as $key => $value) { |
|
| 275 | + $post_array[$key] = $value; |
|
| 276 | + $post_string_array[] = urlencode($key).'='.urlencode($value); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $post_string = implode('&', $post_string_array); |
|
| 280 | + if ($this->debug) { |
|
| 281 | + echo "Post String: $post_string\n"; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + // set post string |
|
| 285 | + //curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_string); |
|
| 286 | + // set multipart form data - file array field-value pairs |
|
| 287 | + if (!empty($file_field_array)) { |
|
| 288 | + foreach ($file_field_array as $var_name => $var_value) { |
|
| 289 | + if (false !== strpos(PHP_OS, 'WIN')) { |
|
| 290 | + $var_value = str_replace('/', '\\', $var_value); |
|
| 291 | + } // win hack |
|
| 292 | + $file_field_array[$var_name] = '@'.$var_value; |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + // set post data |
|
| 297 | + $result_post = array_merge($post_array, $file_field_array); |
|
| 298 | + curl_setopt($this->ch, CURLOPT_POSTFIELDS, $result_post); |
|
| 299 | + |
|
| 300 | + //and finally send curl request |
|
| 301 | + $result = curl_exec_redir($this->ch); |
|
| 302 | + if (curl_errno($this->ch)) { |
|
| 303 | + if ($this->debug) { |
|
| 304 | + echo "Error Occured in Curl\n"; |
|
| 305 | + echo 'Error number: '.curl_errno($this->ch)."\n"; |
|
| 306 | + echo 'Error message: '.curl_error($this->ch)."\n"; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + return false; |
|
| 310 | + } else { |
|
| 311 | + return $result; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Set file location where cookie data will be stored and send on each new request. |
|
| 317 | + * |
|
| 318 | + * @param string absolute path to cookie file (must be in writable dir) |
|
| 319 | + */ |
|
| 320 | + public function storeCookies($cookie_file) |
|
| 321 | + { |
|
| 322 | + // use cookies on each request (cookies stored in $cookie_file) |
|
| 323 | + curl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookie_file); |
|
| 324 | + curl_setopt($this->ch, CURLOPT_COOKIEFILE, $cookie_file); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Set custom cookie. |
|
| 329 | + * |
|
| 330 | + * @param string cookie |
|
| 331 | + */ |
|
| 332 | + public function setCookie($cookie) |
|
| 333 | + { |
|
| 334 | + curl_setopt($this->ch, CURLOPT_COOKIE, $cookie); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Get last URL info |
|
| 339 | + * usefull when original url was redirected to other location. |
|
| 340 | + * |
|
| 341 | + * @return string url |
|
| 342 | + */ |
|
| 343 | + public function getEffectiveUrl() |
|
| 344 | + { |
|
| 345 | + return curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Get http response code. |
|
| 350 | + * |
|
| 351 | + * @return int |
|
| 352 | + */ |
|
| 353 | + public function getHttpResponseCode() |
|
| 354 | + { |
|
| 355 | + return curl_getinfo($this->ch, CURLINFO_HTTP_CODE); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * Return last error message and error number. |
|
| 360 | + * |
|
| 361 | + * @return string error msg |
|
| 362 | + */ |
|
| 363 | + public function getErrorMsg() |
|
| 364 | + { |
|
| 365 | + $err = 'Error number: '.curl_errno($this->ch)."\n"; |
|
| 366 | + $err .= 'Error message: '.curl_error($this->ch)."\n"; |
|
| 367 | + |
|
| 368 | + return $err; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Close curl session and free resource |
|
| 373 | + * Usually no need to call this function directly |
|
| 374 | + * in case you do you have to call init() to recreate curl. |
|
| 375 | + */ |
|
| 376 | + public function close() |
|
| 377 | + { |
|
| 378 | + //close curl session and free up resources |
|
| 379 | + curl_close($this->ch); |
|
| 380 | + } |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -386,63 +386,63 @@ discard block |
||
| 386 | 386 | */ |
| 387 | 387 | function curlExecRedir($ch) |
| 388 | 388 | { |
| 389 | - static $curl_loops = 0; |
|
| 390 | - static $curl_max_loops = 20; |
|
| 389 | + static $curl_loops = 0; |
|
| 390 | + static $curl_max_loops = 20; |
|
| 391 | 391 | |
| 392 | - if ($curl_loops++ >= $curl_max_loops) { |
|
| 393 | - $curl_loops = 0; |
|
| 392 | + if ($curl_loops++ >= $curl_max_loops) { |
|
| 393 | + $curl_loops = 0; |
|
| 394 | 394 | |
| 395 | - return false; |
|
| 396 | - } |
|
| 395 | + return false; |
|
| 396 | + } |
|
| 397 | 397 | |
| 398 | - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']); |
|
| 399 | - curl_setopt($ch, CURLOPT_HEADER, true); |
|
| 400 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 401 | - curl_setopt($ch, CURLOPT_VERBOSE, false); |
|
| 402 | - $data = curl_exec($ch); |
|
| 403 | - $data = str_replace("\r", "\n", str_replace("\r\n", "\n", $data)); |
|
| 404 | - list($header, $data) = explode("\n\n", $data, 2); |
|
| 405 | - $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 398 | + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']); |
|
| 399 | + curl_setopt($ch, CURLOPT_HEADER, true); |
|
| 400 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 401 | + curl_setopt($ch, CURLOPT_VERBOSE, false); |
|
| 402 | + $data = curl_exec($ch); |
|
| 403 | + $data = str_replace("\r", "\n", str_replace("\r\n", "\n", $data)); |
|
| 404 | + list($header, $data) = explode("\n\n", $data, 2); |
|
| 405 | + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 406 | 406 | |
| 407 | - //echo "*** Got HTTP code: $http_code ***\n"; |
|
| 408 | - //echo "** Got headers: \n$header\n\n"; |
|
| 407 | + //echo "*** Got HTTP code: $http_code ***\n"; |
|
| 408 | + //echo "** Got headers: \n$header\n\n"; |
|
| 409 | 409 | |
| 410 | - if (301 == $http_code || 302 == $http_code) { |
|
| 411 | - // If we're redirected, we should revert to GET |
|
| 412 | - curl_setopt($ch, CURLOPT_HTTPGET, true); |
|
| 410 | + if (301 == $http_code || 302 == $http_code) { |
|
| 411 | + // If we're redirected, we should revert to GET |
|
| 412 | + curl_setopt($ch, CURLOPT_HTTPGET, true); |
|
| 413 | 413 | |
| 414 | - $matches = []; |
|
| 415 | - preg_match('/Location:\s*(.*?)(\n|$)/i', $header, $matches); |
|
| 416 | - $url = @parse_url(trim($matches[1])); |
|
| 414 | + $matches = []; |
|
| 415 | + preg_match('/Location:\s*(.*?)(\n|$)/i', $header, $matches); |
|
| 416 | + $url = @parse_url(trim($matches[1])); |
|
| 417 | 417 | |
| 418 | - if (!$url) { |
|
| 419 | - //couldn't process the url to redirect to |
|
| 420 | - $curl_loops = 0; |
|
| 418 | + if (!$url) { |
|
| 419 | + //couldn't process the url to redirect to |
|
| 420 | + $curl_loops = 0; |
|
| 421 | 421 | |
| 422 | - return $data; |
|
| 423 | - } |
|
| 422 | + return $data; |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | - $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); |
|
| 426 | - if (empty($url['scheme'])) { |
|
| 427 | - $url['scheme'] = $last_url['scheme']; |
|
| 428 | - } |
|
| 425 | + $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); |
|
| 426 | + if (empty($url['scheme'])) { |
|
| 427 | + $url['scheme'] = $last_url['scheme']; |
|
| 428 | + } |
|
| 429 | 429 | |
| 430 | - if (empty($url['host'])) { |
|
| 431 | - $url['host'] = $last_url['host']; |
|
| 432 | - } |
|
| 430 | + if (empty($url['host'])) { |
|
| 431 | + $url['host'] = $last_url['host']; |
|
| 432 | + } |
|
| 433 | 433 | |
| 434 | - if (empty($url['path'])) { |
|
| 435 | - $url['path'] = $last_url['path']; |
|
| 436 | - } |
|
| 434 | + if (empty($url['path'])) { |
|
| 435 | + $url['path'] = $last_url['path']; |
|
| 436 | + } |
|
| 437 | 437 | |
| 438 | - $new_url = $url['scheme'].'://'.$url['host'].$url['path'].(!empty($url['query']) ? '?'.$url['query'] : ''); |
|
| 439 | - //echo "Being redirected to $new_url\n"; |
|
| 440 | - curl_setopt($ch, CURLOPT_URL, $new_url); |
|
| 438 | + $new_url = $url['scheme'].'://'.$url['host'].$url['path'].(!empty($url['query']) ? '?'.$url['query'] : ''); |
|
| 439 | + //echo "Being redirected to $new_url\n"; |
|
| 440 | + curl_setopt($ch, CURLOPT_URL, $new_url); |
|
| 441 | 441 | |
| 442 | - return curl_exec_redir($ch); |
|
| 443 | - } else { |
|
| 444 | - $curl_loops = 0; |
|
| 442 | + return curl_exec_redir($ch); |
|
| 443 | + } else { |
|
| 444 | + $curl_loops = 0; |
|
| 445 | 445 | |
| 446 | - return $data; |
|
| 447 | - } |
|
| 446 | + return $data; |
|
| 447 | + } |
|
| 448 | 448 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | // set multipart form data - file array field-value pairs |
| 287 | 287 | if (!empty($file_field_array)) { |
| 288 | 288 | foreach ($file_field_array as $var_name => $var_value) { |
| 289 | - if (false !== strpos(PHP_OS, 'WIN')) { |
|
| 289 | + if (false!==strpos(PHP_OS, 'WIN')) { |
|
| 290 | 290 | $var_value = str_replace('/', '\\', $var_value); |
| 291 | 291 | } // win hack |
| 292 | 292 | $file_field_array[$var_name] = '@'.$var_value; |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | static $curl_loops = 0; |
| 390 | 390 | static $curl_max_loops = 20; |
| 391 | 391 | |
| 392 | - if ($curl_loops++ >= $curl_max_loops) { |
|
| 392 | + if ($curl_loops++>=$curl_max_loops) { |
|
| 393 | 393 | $curl_loops = 0; |
| 394 | 394 | |
| 395 | 395 | return false; |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | //echo "*** Got HTTP code: $http_code ***\n"; |
| 408 | 408 | //echo "** Got headers: \n$header\n\n"; |
| 409 | 409 | |
| 410 | - if (301 == $http_code || 302 == $http_code) { |
|
| 410 | + if (301==$http_code || 302==$http_code) { |
|
| 411 | 411 | // If we're redirected, we should revert to GET |
| 412 | 412 | curl_setopt($ch, CURLOPT_HTTPGET, true); |
| 413 | 413 | |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | /** @var string $geofence_polygon_shape |
| 54 | 54 | * Geofence polygon shape. ENUM('circle', 'poly', 'rect'). |
| 55 | 55 | */ |
| 56 | - public $geofence_polygon_shape ; |
|
| 56 | + public $geofence_polygon_shape; |
|
| 57 | 57 | |
| 58 | 58 | /** @var int $geofence_polygon_size |
| 59 | 59 | * Geofence polygon size |
@@ -10,181 +10,181 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class MemberAuthenticationResponse extends \Route4Me\Common |
| 12 | 12 | { |
| 13 | - /** @var boolean $status |
|
| 14 | - * True, if authentication process was finished successfuly. |
|
| 15 | - */ |
|
| 16 | - public $status; |
|
| 17 | - |
|
| 18 | - /** @var string $geocoding_service |
|
| 19 | - * Geocoding service |
|
| 20 | - */ |
|
| 21 | - public $geocoding_service; |
|
| 22 | - |
|
| 23 | - /** @var int $session_id |
|
| 24 | - * Session ID |
|
| 25 | - */ |
|
| 26 | - public $session_id; |
|
| 27 | - |
|
| 28 | - /** @var string $session_guid |
|
| 29 | - * Session guid |
|
| 30 | - */ |
|
| 31 | - public $session_guid; |
|
| 32 | - |
|
| 33 | - /** @var int $member_id |
|
| 34 | - * Member ID |
|
| 35 | - */ |
|
| 36 | - public $member_id; |
|
| 37 | - |
|
| 38 | - /** @var string $api_key |
|
| 39 | - * API key of an user |
|
| 40 | - */ |
|
| 41 | - public $api_key; |
|
| 42 | - |
|
| 43 | - /** @var int $tracking_ttl |
|
| 44 | - * Tracking TTL |
|
| 45 | - */ |
|
| 46 | - public $tracking_ttl; |
|
| 47 | - |
|
| 48 | - /** @var string $update_channel_name |
|
| 49 | - * Update channel name |
|
| 50 | - */ |
|
| 51 | - public $update_channel_name; |
|
| 52 | - |
|
| 53 | - /** @var string $geofence_polygon_shape |
|
| 54 | - * Geofence polygon shape. ENUM('circle', 'poly', 'rect'). |
|
| 55 | - */ |
|
| 56 | - public $geofence_polygon_shape ; |
|
| 57 | - |
|
| 58 | - /** @var int $geofence_polygon_size |
|
| 59 | - * Geofence polygon size |
|
| 60 | - */ |
|
| 61 | - public $geofence_polygon_size; |
|
| 62 | - |
|
| 63 | - /** @var int $geofence_time_onsite_trigger_secs |
|
| 64 | - * Geofence time onsite trigger in seconds. |
|
| 65 | - */ |
|
| 66 | - public $geofence_time_onsite_trigger_secs; |
|
| 67 | - |
|
| 68 | - /** @var int $geofence_minimum_trigger_speed |
|
| 69 | - * Geofence minimum trigger speed. |
|
| 70 | - */ |
|
| 71 | - public $geofence_minimum_trigger_speed; |
|
| 72 | - |
|
| 73 | - /** @var boolean $is_subscription_past_due |
|
| 74 | - * If true, subscription is past due. |
|
| 75 | - */ |
|
| 76 | - public $is_subscription_past_due; |
|
| 77 | - |
|
| 78 | - /** @var string $visited_departed_enabled |
|
| 79 | - * if true, triggering of the visited and departed activities is enabled. |
|
| 80 | - */ |
|
| 81 | - public $visited_departed_enabled; |
|
| 82 | - |
|
| 83 | - /** @var string $long_press_enabled |
|
| 84 | - * if true, long press is enabled. |
|
| 85 | - */ |
|
| 86 | - public $long_press_enabled; |
|
| 87 | - |
|
| 88 | - /** @var string $account_type_id |
|
| 89 | - * The account type ID |
|
| 90 | - */ |
|
| 91 | - public $account_type_id; |
|
| 92 | - |
|
| 93 | - /** @var string $account_type_alias |
|
| 94 | - * Account type alias. |
|
| 95 | - */ |
|
| 96 | - public $account_type_alias; |
|
| 97 | - |
|
| 98 | - /** @var string $member_type |
|
| 99 | - * A type of the member. |
|
| 100 | - * Available values: |
|
| 101 | - * 'PRIMARY_ACCOUNT', |
|
| 102 | - * 'SUB_ACCOUNT_ADMIN', |
|
| 103 | - * 'SUB_ACCOUNT_REGIONAL_MANAGER', |
|
| 104 | - * 'SUB_ACCOUNT_DISPATCHER', |
|
| 105 | - * 'SUB_ACCOUNT_PLANNER', |
|
| 106 | - * 'SUB_ACCOUNT_DRIVER', |
|
| 107 | - * 'SUB_ACCOUNT_ANALYST', |
|
| 108 | - * 'SUB_ACCOUNT_VENDOR', |
|
| 109 | - * 'SUB_ACCOUNT_CUSTOMER_SERVICE' |
|
| 110 | - */ |
|
| 111 | - public $member_type; |
|
| 112 | - |
|
| 113 | - /** @var string $max_stops_per_route |
|
| 114 | - * Maximum stops per route. |
|
| 115 | - */ |
|
| 116 | - public $max_stops_per_route; |
|
| 117 | - |
|
| 118 | - /** @var string $max_routes |
|
| 119 | - * Maximum number of the routes. |
|
| 120 | - */ |
|
| 121 | - public $max_routes; |
|
| 122 | - |
|
| 123 | - /** @var int $routes_planned |
|
| 124 | - * Number of the planned routes by an user. |
|
| 125 | - */ |
|
| 126 | - public $routes_planned; |
|
| 127 | - |
|
| 128 | - /** @var string $preferred_units |
|
| 129 | - * Preferred units. Enum('km', 'mi'). |
|
| 130 | - */ |
|
| 131 | - public $preferred_units; |
|
| 132 | - |
|
| 133 | - /** @var string $preferred_language |
|
| 134 | - * Preferred language. Enum('en', 'fr'). |
|
| 135 | - */ |
|
| 136 | - public $preferred_language; |
|
| 137 | - |
|
| 138 | - /** @var string $HIDE_ROUTED_ADDRESSES |
|
| 139 | - * If true, routed addresses will be hidden. |
|
| 140 | - */ |
|
| 141 | - public $HIDE_ROUTED_ADDRESSES; |
|
| 142 | - |
|
| 143 | - /** @var string $HIDE_VISITED_ADDRESSES |
|
| 144 | - * If true, visited addresses will be hidden. |
|
| 145 | - */ |
|
| 146 | - public $HIDE_VISITED_ADDRESSES; |
|
| 147 | - |
|
| 148 | - /** @var string $HIDE_NONFUTURE_ROUTES |
|
| 149 | - * If equal to true, nonfuture addresses will be hidden. |
|
| 150 | - */ |
|
| 151 | - public $HIDE_NONFUTURE_ROUTES; |
|
| 152 | - |
|
| 153 | - /** @var string $READONLY_USER |
|
| 154 | - * If equal to true, user can only read data. |
|
| 155 | - */ |
|
| 156 | - public $READONLY_USER; |
|
| 157 | - |
|
| 158 | - /** @var int $auto_logout_ts |
|
| 159 | - * Time in seconds. If a user is inactive during this period, he will be logout. |
|
| 160 | - */ |
|
| 161 | - public $auto_logout_ts; |
|
| 162 | - |
|
| 163 | - /** @var string $last_known_member_payment_device |
|
| 164 | - * Last known member payment device (e.g. 'web') |
|
| 165 | - */ |
|
| 166 | - public $last_known_member_payment_device; |
|
| 167 | - |
|
| 168 | - /** @var int $account_expires_timestamp |
|
| 169 | - * Account expire date |
|
| 170 | - */ |
|
| 171 | - public $account_expires_timestamp; |
|
| 172 | - |
|
| 173 | - /** @var boolean $account_past_due |
|
| 174 | - * Account past due |
|
| 175 | - */ |
|
| 176 | - public $account_past_due; |
|
| 177 | - |
|
| 178 | - /** @var array $licensed_modules |
|
| 179 | - * Licensed module. e.g.: |
|
| 180 | - * 'MODULE__ROUTE_EDITOR_CUSTOM_DATA_EDITING', |
|
| 181 | - * 'MODULE__VOICE_NAVIGATION:TRUE', |
|
| 182 | - * 'MODULE__VOICE_NAVIGATION' |
|
| 183 | - */ |
|
| 184 | - public $licensed_modules; |
|
| 185 | - |
|
| 186 | - /** @var int $last_active_timestamp |
|
| 187 | - * Last active timestamp |
|
| 188 | - */ |
|
| 189 | - public $last_active_timestamp; |
|
| 13 | + /** @var boolean $status |
|
| 14 | + * True, if authentication process was finished successfuly. |
|
| 15 | + */ |
|
| 16 | + public $status; |
|
| 17 | + |
|
| 18 | + /** @var string $geocoding_service |
|
| 19 | + * Geocoding service |
|
| 20 | + */ |
|
| 21 | + public $geocoding_service; |
|
| 22 | + |
|
| 23 | + /** @var int $session_id |
|
| 24 | + * Session ID |
|
| 25 | + */ |
|
| 26 | + public $session_id; |
|
| 27 | + |
|
| 28 | + /** @var string $session_guid |
|
| 29 | + * Session guid |
|
| 30 | + */ |
|
| 31 | + public $session_guid; |
|
| 32 | + |
|
| 33 | + /** @var int $member_id |
|
| 34 | + * Member ID |
|
| 35 | + */ |
|
| 36 | + public $member_id; |
|
| 37 | + |
|
| 38 | + /** @var string $api_key |
|
| 39 | + * API key of an user |
|
| 40 | + */ |
|
| 41 | + public $api_key; |
|
| 42 | + |
|
| 43 | + /** @var int $tracking_ttl |
|
| 44 | + * Tracking TTL |
|
| 45 | + */ |
|
| 46 | + public $tracking_ttl; |
|
| 47 | + |
|
| 48 | + /** @var string $update_channel_name |
|
| 49 | + * Update channel name |
|
| 50 | + */ |
|
| 51 | + public $update_channel_name; |
|
| 52 | + |
|
| 53 | + /** @var string $geofence_polygon_shape |
|
| 54 | + * Geofence polygon shape. ENUM('circle', 'poly', 'rect'). |
|
| 55 | + */ |
|
| 56 | + public $geofence_polygon_shape ; |
|
| 57 | + |
|
| 58 | + /** @var int $geofence_polygon_size |
|
| 59 | + * Geofence polygon size |
|
| 60 | + */ |
|
| 61 | + public $geofence_polygon_size; |
|
| 62 | + |
|
| 63 | + /** @var int $geofence_time_onsite_trigger_secs |
|
| 64 | + * Geofence time onsite trigger in seconds. |
|
| 65 | + */ |
|
| 66 | + public $geofence_time_onsite_trigger_secs; |
|
| 67 | + |
|
| 68 | + /** @var int $geofence_minimum_trigger_speed |
|
| 69 | + * Geofence minimum trigger speed. |
|
| 70 | + */ |
|
| 71 | + public $geofence_minimum_trigger_speed; |
|
| 72 | + |
|
| 73 | + /** @var boolean $is_subscription_past_due |
|
| 74 | + * If true, subscription is past due. |
|
| 75 | + */ |
|
| 76 | + public $is_subscription_past_due; |
|
| 77 | + |
|
| 78 | + /** @var string $visited_departed_enabled |
|
| 79 | + * if true, triggering of the visited and departed activities is enabled. |
|
| 80 | + */ |
|
| 81 | + public $visited_departed_enabled; |
|
| 82 | + |
|
| 83 | + /** @var string $long_press_enabled |
|
| 84 | + * if true, long press is enabled. |
|
| 85 | + */ |
|
| 86 | + public $long_press_enabled; |
|
| 87 | + |
|
| 88 | + /** @var string $account_type_id |
|
| 89 | + * The account type ID |
|
| 90 | + */ |
|
| 91 | + public $account_type_id; |
|
| 92 | + |
|
| 93 | + /** @var string $account_type_alias |
|
| 94 | + * Account type alias. |
|
| 95 | + */ |
|
| 96 | + public $account_type_alias; |
|
| 97 | + |
|
| 98 | + /** @var string $member_type |
|
| 99 | + * A type of the member. |
|
| 100 | + * Available values: |
|
| 101 | + * 'PRIMARY_ACCOUNT', |
|
| 102 | + * 'SUB_ACCOUNT_ADMIN', |
|
| 103 | + * 'SUB_ACCOUNT_REGIONAL_MANAGER', |
|
| 104 | + * 'SUB_ACCOUNT_DISPATCHER', |
|
| 105 | + * 'SUB_ACCOUNT_PLANNER', |
|
| 106 | + * 'SUB_ACCOUNT_DRIVER', |
|
| 107 | + * 'SUB_ACCOUNT_ANALYST', |
|
| 108 | + * 'SUB_ACCOUNT_VENDOR', |
|
| 109 | + * 'SUB_ACCOUNT_CUSTOMER_SERVICE' |
|
| 110 | + */ |
|
| 111 | + public $member_type; |
|
| 112 | + |
|
| 113 | + /** @var string $max_stops_per_route |
|
| 114 | + * Maximum stops per route. |
|
| 115 | + */ |
|
| 116 | + public $max_stops_per_route; |
|
| 117 | + |
|
| 118 | + /** @var string $max_routes |
|
| 119 | + * Maximum number of the routes. |
|
| 120 | + */ |
|
| 121 | + public $max_routes; |
|
| 122 | + |
|
| 123 | + /** @var int $routes_planned |
|
| 124 | + * Number of the planned routes by an user. |
|
| 125 | + */ |
|
| 126 | + public $routes_planned; |
|
| 127 | + |
|
| 128 | + /** @var string $preferred_units |
|
| 129 | + * Preferred units. Enum('km', 'mi'). |
|
| 130 | + */ |
|
| 131 | + public $preferred_units; |
|
| 132 | + |
|
| 133 | + /** @var string $preferred_language |
|
| 134 | + * Preferred language. Enum('en', 'fr'). |
|
| 135 | + */ |
|
| 136 | + public $preferred_language; |
|
| 137 | + |
|
| 138 | + /** @var string $HIDE_ROUTED_ADDRESSES |
|
| 139 | + * If true, routed addresses will be hidden. |
|
| 140 | + */ |
|
| 141 | + public $HIDE_ROUTED_ADDRESSES; |
|
| 142 | + |
|
| 143 | + /** @var string $HIDE_VISITED_ADDRESSES |
|
| 144 | + * If true, visited addresses will be hidden. |
|
| 145 | + */ |
|
| 146 | + public $HIDE_VISITED_ADDRESSES; |
|
| 147 | + |
|
| 148 | + /** @var string $HIDE_NONFUTURE_ROUTES |
|
| 149 | + * If equal to true, nonfuture addresses will be hidden. |
|
| 150 | + */ |
|
| 151 | + public $HIDE_NONFUTURE_ROUTES; |
|
| 152 | + |
|
| 153 | + /** @var string $READONLY_USER |
|
| 154 | + * If equal to true, user can only read data. |
|
| 155 | + */ |
|
| 156 | + public $READONLY_USER; |
|
| 157 | + |
|
| 158 | + /** @var int $auto_logout_ts |
|
| 159 | + * Time in seconds. If a user is inactive during this period, he will be logout. |
|
| 160 | + */ |
|
| 161 | + public $auto_logout_ts; |
|
| 162 | + |
|
| 163 | + /** @var string $last_known_member_payment_device |
|
| 164 | + * Last known member payment device (e.g. 'web') |
|
| 165 | + */ |
|
| 166 | + public $last_known_member_payment_device; |
|
| 167 | + |
|
| 168 | + /** @var int $account_expires_timestamp |
|
| 169 | + * Account expire date |
|
| 170 | + */ |
|
| 171 | + public $account_expires_timestamp; |
|
| 172 | + |
|
| 173 | + /** @var boolean $account_past_due |
|
| 174 | + * Account past due |
|
| 175 | + */ |
|
| 176 | + public $account_past_due; |
|
| 177 | + |
|
| 178 | + /** @var array $licensed_modules |
|
| 179 | + * Licensed module. e.g.: |
|
| 180 | + * 'MODULE__ROUTE_EDITOR_CUSTOM_DATA_EDITING', |
|
| 181 | + * 'MODULE__VOICE_NAVIGATION:TRUE', |
|
| 182 | + * 'MODULE__VOICE_NAVIGATION' |
|
| 183 | + */ |
|
| 184 | + public $licensed_modules; |
|
| 185 | + |
|
| 186 | + /** @var int $last_active_timestamp |
|
| 187 | + * Last active timestamp |
|
| 188 | + */ |
|
| 189 | + public $last_active_timestamp; |
|
| 190 | 190 | } |
@@ -7,20 +7,20 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class MemberConfigurationResponse extends \Route4Me\Common |
| 9 | 9 | { |
| 10 | - /* |
|
| 10 | + /* |
|
| 11 | 11 | * Configuration result |
| 12 | 12 | */ |
| 13 | - public $result; |
|
| 13 | + public $result; |
|
| 14 | 14 | |
| 15 | - /* |
|
| 15 | + /* |
|
| 16 | 16 | * How many configuration key -> data pairs affected |
| 17 | 17 | */ |
| 18 | - public $affected; |
|
| 18 | + public $affected; |
|
| 19 | 19 | |
| 20 | - /* |
|
| 20 | + /* |
|
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | - public $data = []; |
|
| 23 | + public $data = []; |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | |
@@ -163,13 +163,13 @@ |
||
| 163 | 163 | |
| 164 | 164 | foreach ($members['results'] as $memb) { |
| 165 | 165 | if (isset($memb['member_id']) && isset($memb['member_type'])) { |
| 166 | - if ($memberType == $memb['member_type']) { |
|
| 166 | + if ($memberType==$memb['member_type']) { |
|
| 167 | 167 | $memberIDs[] = $memb['member_id']; |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if (sizeof($memberIDs) < 1) { |
|
| 172 | + if (sizeof($memberIDs)<1) { |
|
| 173 | 173 | return null; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -8,347 +8,347 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Member extends \Route4Me\Common |
| 10 | 10 | { |
| 11 | - public $device_id; |
|
| 12 | - public $device_type; |
|
| 13 | - public $format; |
|
| 14 | - |
|
| 15 | - public $strEmail; |
|
| 16 | - public $strPassword; |
|
| 17 | - public $strPassword_1; |
|
| 18 | - public $strPassword_2; |
|
| 19 | - public $strFirstName; |
|
| 20 | - public $strLastName; |
|
| 21 | - public $strIndustry; |
|
| 22 | - public $chkTerms; |
|
| 23 | - public $plan; |
|
| 24 | - |
|
| 25 | - public $session_guid; |
|
| 26 | - public $member_id; |
|
| 27 | - |
|
| 28 | - public $email_address; |
|
| 29 | - public $first_name; |
|
| 30 | - public $last_name; |
|
| 31 | - public $phone_number; |
|
| 32 | - public $company_name; |
|
| 33 | - public $webinar_date; |
|
| 34 | - |
|
| 35 | - public $subscription_name; |
|
| 36 | - public $token; |
|
| 37 | - public $payload; |
|
| 38 | - |
|
| 39 | - public $HIDE_ROUTED_ADDRESSES; |
|
| 40 | - public $member_phone; |
|
| 41 | - public $member_zipcode; |
|
| 42 | - public $route_count; |
|
| 43 | - public $member_email; |
|
| 44 | - public $HIDE_VISITED_ADDRESSES; |
|
| 45 | - public $READONLY_USER; |
|
| 46 | - public $member_type; |
|
| 47 | - public $date_of_birth; |
|
| 48 | - public $member_first_name; |
|
| 49 | - public $member_password; |
|
| 50 | - public $HIDE_NONFUTURE_ROUTES; |
|
| 51 | - public $member_last_name; |
|
| 52 | - public $SHOW_ALL_VEHICLES; |
|
| 53 | - public $SHOW_ALL_DRIVERS; |
|
| 54 | - |
|
| 55 | - public $config_key; |
|
| 56 | - public $config_value; |
|
| 57 | - |
|
| 58 | - public $preferred_units; |
|
| 59 | - public $preferred_language; |
|
| 60 | - public $timezone; |
|
| 61 | - public $OWNER_MEMBER_ID; |
|
| 62 | - public $user_reg_state_id; |
|
| 63 | - public $user_reg_country_id; |
|
| 64 | - public $member_picture; |
|
| 65 | - public $api_key; |
|
| 66 | - public $custom_data; |
|
| 67 | - public $level; |
|
| 68 | - |
|
| 69 | - public function __construct() |
|
| 70 | - { |
|
| 71 | - Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - public static function getUsers() |
|
| 75 | - { |
|
| 76 | - $response = Route4Me::makeRequst([ |
|
| 77 | - 'url' => Endpoint::USER_V4, |
|
| 78 | - 'method' => 'GET', |
|
| 79 | - ]); |
|
| 80 | - |
|
| 81 | - return $response; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public static function getUser($params) |
|
| 85 | - { |
|
| 86 | - $response = Route4Me::makeRequst([ |
|
| 87 | - 'url' => Endpoint::USER_V4, |
|
| 88 | - 'method' => 'GET', |
|
| 89 | - 'query' => [ |
|
| 90 | - 'member_id' => isset($params['member_id']) ? $params['member_id'] : null, |
|
| 91 | - ], |
|
| 92 | - ]); |
|
| 93 | - |
|
| 94 | - return $response; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public static function getUserLocations($param) |
|
| 98 | - { |
|
| 99 | - $response = Route4Me::makeRequst([ |
|
| 100 | - 'url' => Endpoint::VIEW_USER_LOCATIONS, |
|
| 101 | - 'method' => 'GET', |
|
| 102 | - 'query' => [ |
|
| 103 | - 'query' => $param, |
|
| 104 | - ], |
|
| 105 | - ]); |
|
| 106 | - |
|
| 107 | - return $response; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - public static function addDeviceRecord($params) |
|
| 111 | - { |
|
| 112 | - $allQueryFields = ['device_id', 'device_type']; |
|
| 113 | - $allBodyFields = ['device_id', 'device_type', 'format']; |
|
| 114 | - |
|
| 115 | - $response = Route4Me::makeRequst([ |
|
| 116 | - 'url' => Endpoint::VERIFY_DEVICE_LICENSE, |
|
| 117 | - 'method' => 'POST', |
|
| 118 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 119 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 120 | - ]); |
|
| 121 | - |
|
| 122 | - return $response; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public static function createMember($params) |
|
| 126 | - { |
|
| 127 | - $excludeFields = ['session_guid', 'member_id', 'token', 'payload', 'webinar_date', |
|
| 128 | - 'company_name', 'config_key', 'config_value', 'api_key', ]; |
|
| 129 | - |
|
| 130 | - $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
| 131 | - |
|
| 132 | - $response = Route4Me::makeRequst([ |
|
| 133 | - 'url' => Endpoint::USER_V4, |
|
| 134 | - 'method' => 'POST', |
|
| 135 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 136 | - ]); |
|
| 137 | - |
|
| 138 | - return $response; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public static function getRandomMemberByType($memberType) |
|
| 142 | - { |
|
| 143 | - $members = self::getUsers(); |
|
| 144 | - |
|
| 145 | - if (is_null($members) || !isset($members['results'])) { |
|
| 146 | - return null; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $memberIDs = []; |
|
| 150 | - |
|
| 151 | - foreach ($members['results'] as $memb) { |
|
| 152 | - if (isset($memb['member_id']) && isset($memb['member_type'])) { |
|
| 153 | - if ($memberType == $memb['member_type']) { |
|
| 154 | - $memberIDs[] = $memb['member_id']; |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - if (sizeof($memberIDs) < 1) { |
|
| 160 | - return null; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - $randomIndex = rand(0, sizeof($memberIDs) - 1); |
|
| 164 | - |
|
| 165 | - return $memberIDs[$randomIndex]; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - public static function updateMember($body) |
|
| 169 | - { |
|
| 170 | - $excludeFields = ['session_guid', 'token', 'payload', 'webinar_date', |
|
| 171 | - 'company_name', 'config_key', 'config_value', 'api_key', ]; |
|
| 172 | - |
|
| 173 | - $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
| 174 | - |
|
| 175 | - $response = Route4Me::makeRequst([ |
|
| 176 | - 'url' => Endpoint::USER_V4, |
|
| 177 | - 'method' => 'PUT', |
|
| 178 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $body), |
|
| 179 | - ]); |
|
| 180 | - |
|
| 181 | - return $response; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - public static function deleteMember($body, &$errorText) |
|
| 185 | - { |
|
| 186 | - $response = null; |
|
| 187 | - |
|
| 188 | - try { |
|
| 189 | - $response = Route4Me::makeRequst([ |
|
| 190 | - 'url' => Endpoint::USER_V4, |
|
| 191 | - 'method' => 'DELETE', |
|
| 192 | - 'body' => [ |
|
| 193 | - 'member_id' => isset($body->member_id) ? $body->member_id : null, |
|
| 194 | - ], |
|
| 195 | - ]); |
|
| 196 | - } catch (\Exception $ex) { |
|
| 197 | - $errorText = $ex->getMessage(); |
|
| 198 | - $response = null; |
|
| 199 | - } finally { |
|
| 200 | - return $response; |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - public static function newAccountRegistration($params, &$errorText) |
|
| 205 | - { |
|
| 206 | - $allQueryFields = ['plan']; |
|
| 207 | - $allBodyFields = ['strEmail', 'strPassword_1', 'strPassword_2', 'strFirstName', |
|
| 208 | - 'strLastName', 'format', 'strIndustry', 'chkTerms', 'device_type', 'strSubAccountType', |
|
| 209 | - 'blDisableMarketing', 'blDisableAccountActivationEmail', ]; |
|
| 210 | - |
|
| 211 | - $response = null; |
|
| 212 | - |
|
| 213 | - try { |
|
| 214 | - $response = Route4Me::makeRequst([ |
|
| 215 | - 'url' => Endpoint::REGISTER_ACTION, |
|
| 216 | - 'method' => 'POST', |
|
| 217 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 218 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 219 | - 'HTTPHEADER' => 'Content-Type: multipart/form-data', |
|
| 220 | - ]); |
|
| 221 | - } catch (\Exception $ex) { |
|
| 222 | - $response = null; |
|
| 223 | - $errorText = "Cannot registrate new account <br> ".$ex->getMessage(); |
|
| 224 | - } finally { |
|
| 225 | - return $response; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - public static function validateSession($params) |
|
| 230 | - { |
|
| 231 | - $allQueryFields = ['session_guid', 'member_id', 'format']; |
|
| 232 | - |
|
| 233 | - $response = Route4Me::makeRequst([ |
|
| 234 | - 'url' => Endpoint::VALIDATE_SESSION, |
|
| 235 | - 'method' => 'GET', |
|
| 236 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 237 | - ]); |
|
| 238 | - |
|
| 239 | - return $response; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - public static function memberAuthentication($params) |
|
| 243 | - { |
|
| 244 | - $allBodyFields = ['strEmail', 'strPassword', 'format']; |
|
| 245 | - |
|
| 246 | - $response = Route4Me::makeRequst([ |
|
| 247 | - 'url' => Endpoint::AUTHENTICATE, |
|
| 248 | - 'method' => 'POST', |
|
| 249 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 250 | - 'HTTPHEADER' => 'Content-Type: multipart/form-data', |
|
| 251 | - ]); |
|
| 252 | - |
|
| 253 | - return $response; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - public static function webinarRegistration($params) |
|
| 257 | - { |
|
| 258 | - $allBodyFields = ['email_address', 'first_name', 'last_name', 'phone_number', |
|
| 259 | - 'company_name', 'member_id', 'webinar_date', ]; |
|
| 260 | - |
|
| 261 | - $response = null; |
|
| 262 | - |
|
| 263 | - try { |
|
| 264 | - $response = Route4Me::makeRequst([ |
|
| 265 | - 'url' => Endpoint::WEBINAR_REGISTER, |
|
| 266 | - 'method' => 'POST', |
|
| 267 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 268 | - ]); |
|
| 269 | - } catch (\Exception $ex) { |
|
| 270 | - $response = null; |
|
| 271 | - } finally { |
|
| 272 | - return $response; |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - public static function purchaseUserLicense($params) |
|
| 277 | - { |
|
| 278 | - $allQueryFields = ['device_id']; |
|
| 279 | - $allBodyFields = ['member_id', 'session_guid', 'device_id', 'device_type', |
|
| 280 | - 'subscription_name', 'token', 'payload', 'format', ]; |
|
| 281 | - |
|
| 282 | - $response = Route4Me::makeRequst([ |
|
| 283 | - 'url' => Endpoint::USER_LICENSE, |
|
| 284 | - 'method' => 'POST', |
|
| 285 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 286 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 287 | - ]); |
|
| 288 | - |
|
| 289 | - return $response; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - public static function newMemberConfigKey($params) |
|
| 293 | - { |
|
| 294 | - $allBodyFields = ['config_key', 'config_value']; |
|
| 295 | - |
|
| 296 | - $response = Route4Me::makeRequst([ |
|
| 297 | - 'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
| 298 | - 'method' => 'POST', |
|
| 299 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 300 | - ]); |
|
| 301 | - |
|
| 302 | - return $response; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - public static function removeMemberConfigKey($params) |
|
| 306 | - { |
|
| 307 | - $allBodyFields = ['config_key']; |
|
| 308 | - |
|
| 309 | - $response = Route4Me::makeRequst([ |
|
| 310 | - 'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
| 311 | - 'method' => 'DELETE', |
|
| 312 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 313 | - ]); |
|
| 314 | - |
|
| 315 | - return $response; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - public static function getMemberConfigData($params) |
|
| 319 | - { |
|
| 320 | - $allQueryFields = ['config_key']; |
|
| 321 | - |
|
| 322 | - $response = Route4Me::makeRequst([ |
|
| 323 | - 'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
| 324 | - 'method' => 'GET', |
|
| 325 | - 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 326 | - ]); |
|
| 327 | - |
|
| 328 | - return $response; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - public static function updateMemberConfigKey($params) |
|
| 332 | - { |
|
| 333 | - $allBodyFields = ['config_key', 'config_value']; |
|
| 334 | - |
|
| 335 | - $response = Route4Me::makeRequst([ |
|
| 336 | - 'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
| 337 | - 'method' => 'PUT', |
|
| 338 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 339 | - ]); |
|
| 340 | - |
|
| 341 | - return $response; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - public static function getMemberCapabilities() |
|
| 345 | - { |
|
| 346 | - $response = Route4Me::makeRequst([ |
|
| 347 | - 'url' => Endpoint::MEMBER_CAPABILITIES, |
|
| 348 | - 'method' => 'GET', |
|
| 349 | - 'query' => Route4Me::generateRequestParameters([], null), |
|
| 350 | - ]); |
|
| 351 | - |
|
| 352 | - return $response; |
|
| 353 | - } |
|
| 11 | + public $device_id; |
|
| 12 | + public $device_type; |
|
| 13 | + public $format; |
|
| 14 | + |
|
| 15 | + public $strEmail; |
|
| 16 | + public $strPassword; |
|
| 17 | + public $strPassword_1; |
|
| 18 | + public $strPassword_2; |
|
| 19 | + public $strFirstName; |
|
| 20 | + public $strLastName; |
|
| 21 | + public $strIndustry; |
|
| 22 | + public $chkTerms; |
|
| 23 | + public $plan; |
|
| 24 | + |
|
| 25 | + public $session_guid; |
|
| 26 | + public $member_id; |
|
| 27 | + |
|
| 28 | + public $email_address; |
|
| 29 | + public $first_name; |
|
| 30 | + public $last_name; |
|
| 31 | + public $phone_number; |
|
| 32 | + public $company_name; |
|
| 33 | + public $webinar_date; |
|
| 34 | + |
|
| 35 | + public $subscription_name; |
|
| 36 | + public $token; |
|
| 37 | + public $payload; |
|
| 38 | + |
|
| 39 | + public $HIDE_ROUTED_ADDRESSES; |
|
| 40 | + public $member_phone; |
|
| 41 | + public $member_zipcode; |
|
| 42 | + public $route_count; |
|
| 43 | + public $member_email; |
|
| 44 | + public $HIDE_VISITED_ADDRESSES; |
|
| 45 | + public $READONLY_USER; |
|
| 46 | + public $member_type; |
|
| 47 | + public $date_of_birth; |
|
| 48 | + public $member_first_name; |
|
| 49 | + public $member_password; |
|
| 50 | + public $HIDE_NONFUTURE_ROUTES; |
|
| 51 | + public $member_last_name; |
|
| 52 | + public $SHOW_ALL_VEHICLES; |
|
| 53 | + public $SHOW_ALL_DRIVERS; |
|
| 54 | + |
|
| 55 | + public $config_key; |
|
| 56 | + public $config_value; |
|
| 57 | + |
|
| 58 | + public $preferred_units; |
|
| 59 | + public $preferred_language; |
|
| 60 | + public $timezone; |
|
| 61 | + public $OWNER_MEMBER_ID; |
|
| 62 | + public $user_reg_state_id; |
|
| 63 | + public $user_reg_country_id; |
|
| 64 | + public $member_picture; |
|
| 65 | + public $api_key; |
|
| 66 | + public $custom_data; |
|
| 67 | + public $level; |
|
| 68 | + |
|
| 69 | + public function __construct() |
|
| 70 | + { |
|
| 71 | + Route4Me::setBaseUrl(Endpoint::BASE_URL); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + public static function getUsers() |
|
| 75 | + { |
|
| 76 | + $response = Route4Me::makeRequst([ |
|
| 77 | + 'url' => Endpoint::USER_V4, |
|
| 78 | + 'method' => 'GET', |
|
| 79 | + ]); |
|
| 80 | + |
|
| 81 | + return $response; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public static function getUser($params) |
|
| 85 | + { |
|
| 86 | + $response = Route4Me::makeRequst([ |
|
| 87 | + 'url' => Endpoint::USER_V4, |
|
| 88 | + 'method' => 'GET', |
|
| 89 | + 'query' => [ |
|
| 90 | + 'member_id' => isset($params['member_id']) ? $params['member_id'] : null, |
|
| 91 | + ], |
|
| 92 | + ]); |
|
| 93 | + |
|
| 94 | + return $response; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public static function getUserLocations($param) |
|
| 98 | + { |
|
| 99 | + $response = Route4Me::makeRequst([ |
|
| 100 | + 'url' => Endpoint::VIEW_USER_LOCATIONS, |
|
| 101 | + 'method' => 'GET', |
|
| 102 | + 'query' => [ |
|
| 103 | + 'query' => $param, |
|
| 104 | + ], |
|
| 105 | + ]); |
|
| 106 | + |
|
| 107 | + return $response; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + public static function addDeviceRecord($params) |
|
| 111 | + { |
|
| 112 | + $allQueryFields = ['device_id', 'device_type']; |
|
| 113 | + $allBodyFields = ['device_id', 'device_type', 'format']; |
|
| 114 | + |
|
| 115 | + $response = Route4Me::makeRequst([ |
|
| 116 | + 'url' => Endpoint::VERIFY_DEVICE_LICENSE, |
|
| 117 | + 'method' => 'POST', |
|
| 118 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 119 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 120 | + ]); |
|
| 121 | + |
|
| 122 | + return $response; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public static function createMember($params) |
|
| 126 | + { |
|
| 127 | + $excludeFields = ['session_guid', 'member_id', 'token', 'payload', 'webinar_date', |
|
| 128 | + 'company_name', 'config_key', 'config_value', 'api_key', ]; |
|
| 129 | + |
|
| 130 | + $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
| 131 | + |
|
| 132 | + $response = Route4Me::makeRequst([ |
|
| 133 | + 'url' => Endpoint::USER_V4, |
|
| 134 | + 'method' => 'POST', |
|
| 135 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 136 | + ]); |
|
| 137 | + |
|
| 138 | + return $response; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public static function getRandomMemberByType($memberType) |
|
| 142 | + { |
|
| 143 | + $members = self::getUsers(); |
|
| 144 | + |
|
| 145 | + if (is_null($members) || !isset($members['results'])) { |
|
| 146 | + return null; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $memberIDs = []; |
|
| 150 | + |
|
| 151 | + foreach ($members['results'] as $memb) { |
|
| 152 | + if (isset($memb['member_id']) && isset($memb['member_type'])) { |
|
| 153 | + if ($memberType == $memb['member_type']) { |
|
| 154 | + $memberIDs[] = $memb['member_id']; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + if (sizeof($memberIDs) < 1) { |
|
| 160 | + return null; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + $randomIndex = rand(0, sizeof($memberIDs) - 1); |
|
| 164 | + |
|
| 165 | + return $memberIDs[$randomIndex]; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + public static function updateMember($body) |
|
| 169 | + { |
|
| 170 | + $excludeFields = ['session_guid', 'token', 'payload', 'webinar_date', |
|
| 171 | + 'company_name', 'config_key', 'config_value', 'api_key', ]; |
|
| 172 | + |
|
| 173 | + $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields); |
|
| 174 | + |
|
| 175 | + $response = Route4Me::makeRequst([ |
|
| 176 | + 'url' => Endpoint::USER_V4, |
|
| 177 | + 'method' => 'PUT', |
|
| 178 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $body), |
|
| 179 | + ]); |
|
| 180 | + |
|
| 181 | + return $response; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + public static function deleteMember($body, &$errorText) |
|
| 185 | + { |
|
| 186 | + $response = null; |
|
| 187 | + |
|
| 188 | + try { |
|
| 189 | + $response = Route4Me::makeRequst([ |
|
| 190 | + 'url' => Endpoint::USER_V4, |
|
| 191 | + 'method' => 'DELETE', |
|
| 192 | + 'body' => [ |
|
| 193 | + 'member_id' => isset($body->member_id) ? $body->member_id : null, |
|
| 194 | + ], |
|
| 195 | + ]); |
|
| 196 | + } catch (\Exception $ex) { |
|
| 197 | + $errorText = $ex->getMessage(); |
|
| 198 | + $response = null; |
|
| 199 | + } finally { |
|
| 200 | + return $response; |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + public static function newAccountRegistration($params, &$errorText) |
|
| 205 | + { |
|
| 206 | + $allQueryFields = ['plan']; |
|
| 207 | + $allBodyFields = ['strEmail', 'strPassword_1', 'strPassword_2', 'strFirstName', |
|
| 208 | + 'strLastName', 'format', 'strIndustry', 'chkTerms', 'device_type', 'strSubAccountType', |
|
| 209 | + 'blDisableMarketing', 'blDisableAccountActivationEmail', ]; |
|
| 210 | + |
|
| 211 | + $response = null; |
|
| 212 | + |
|
| 213 | + try { |
|
| 214 | + $response = Route4Me::makeRequst([ |
|
| 215 | + 'url' => Endpoint::REGISTER_ACTION, |
|
| 216 | + 'method' => 'POST', |
|
| 217 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 218 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 219 | + 'HTTPHEADER' => 'Content-Type: multipart/form-data', |
|
| 220 | + ]); |
|
| 221 | + } catch (\Exception $ex) { |
|
| 222 | + $response = null; |
|
| 223 | + $errorText = "Cannot registrate new account <br> ".$ex->getMessage(); |
|
| 224 | + } finally { |
|
| 225 | + return $response; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + public static function validateSession($params) |
|
| 230 | + { |
|
| 231 | + $allQueryFields = ['session_guid', 'member_id', 'format']; |
|
| 232 | + |
|
| 233 | + $response = Route4Me::makeRequst([ |
|
| 234 | + 'url' => Endpoint::VALIDATE_SESSION, |
|
| 235 | + 'method' => 'GET', |
|
| 236 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 237 | + ]); |
|
| 238 | + |
|
| 239 | + return $response; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + public static function memberAuthentication($params) |
|
| 243 | + { |
|
| 244 | + $allBodyFields = ['strEmail', 'strPassword', 'format']; |
|
| 245 | + |
|
| 246 | + $response = Route4Me::makeRequst([ |
|
| 247 | + 'url' => Endpoint::AUTHENTICATE, |
|
| 248 | + 'method' => 'POST', |
|
| 249 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 250 | + 'HTTPHEADER' => 'Content-Type: multipart/form-data', |
|
| 251 | + ]); |
|
| 252 | + |
|
| 253 | + return $response; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + public static function webinarRegistration($params) |
|
| 257 | + { |
|
| 258 | + $allBodyFields = ['email_address', 'first_name', 'last_name', 'phone_number', |
|
| 259 | + 'company_name', 'member_id', 'webinar_date', ]; |
|
| 260 | + |
|
| 261 | + $response = null; |
|
| 262 | + |
|
| 263 | + try { |
|
| 264 | + $response = Route4Me::makeRequst([ |
|
| 265 | + 'url' => Endpoint::WEBINAR_REGISTER, |
|
| 266 | + 'method' => 'POST', |
|
| 267 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 268 | + ]); |
|
| 269 | + } catch (\Exception $ex) { |
|
| 270 | + $response = null; |
|
| 271 | + } finally { |
|
| 272 | + return $response; |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + public static function purchaseUserLicense($params) |
|
| 277 | + { |
|
| 278 | + $allQueryFields = ['device_id']; |
|
| 279 | + $allBodyFields = ['member_id', 'session_guid', 'device_id', 'device_type', |
|
| 280 | + 'subscription_name', 'token', 'payload', 'format', ]; |
|
| 281 | + |
|
| 282 | + $response = Route4Me::makeRequst([ |
|
| 283 | + 'url' => Endpoint::USER_LICENSE, |
|
| 284 | + 'method' => 'POST', |
|
| 285 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 286 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 287 | + ]); |
|
| 288 | + |
|
| 289 | + return $response; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + public static function newMemberConfigKey($params) |
|
| 293 | + { |
|
| 294 | + $allBodyFields = ['config_key', 'config_value']; |
|
| 295 | + |
|
| 296 | + $response = Route4Me::makeRequst([ |
|
| 297 | + 'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
| 298 | + 'method' => 'POST', |
|
| 299 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 300 | + ]); |
|
| 301 | + |
|
| 302 | + return $response; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + public static function removeMemberConfigKey($params) |
|
| 306 | + { |
|
| 307 | + $allBodyFields = ['config_key']; |
|
| 308 | + |
|
| 309 | + $response = Route4Me::makeRequst([ |
|
| 310 | + 'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
| 311 | + 'method' => 'DELETE', |
|
| 312 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 313 | + ]); |
|
| 314 | + |
|
| 315 | + return $response; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + public static function getMemberConfigData($params) |
|
| 319 | + { |
|
| 320 | + $allQueryFields = ['config_key']; |
|
| 321 | + |
|
| 322 | + $response = Route4Me::makeRequst([ |
|
| 323 | + 'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
| 324 | + 'method' => 'GET', |
|
| 325 | + 'query' => Route4Me::generateRequestParameters($allQueryFields, $params), |
|
| 326 | + ]); |
|
| 327 | + |
|
| 328 | + return $response; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + public static function updateMemberConfigKey($params) |
|
| 332 | + { |
|
| 333 | + $allBodyFields = ['config_key', 'config_value']; |
|
| 334 | + |
|
| 335 | + $response = Route4Me::makeRequst([ |
|
| 336 | + 'url' => Endpoint::CONFIGURATION_SETTINGS, |
|
| 337 | + 'method' => 'PUT', |
|
| 338 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params), |
|
| 339 | + ]); |
|
| 340 | + |
|
| 341 | + return $response; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + public static function getMemberCapabilities() |
|
| 345 | + { |
|
| 346 | + $response = Route4Me::makeRequst([ |
|
| 347 | + 'url' => Endpoint::MEMBER_CAPABILITIES, |
|
| 348 | + 'method' => 'GET', |
|
| 349 | + 'query' => Route4Me::generateRequestParameters([], null), |
|
| 350 | + ]); |
|
| 351 | + |
|
| 352 | + return $response; |
|
| 353 | + } |
|
| 354 | 354 | } |