@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class AvoidanceZone extends Common |
| 9 | 9 | { |
| 10 | - public $territory_id; // Avoidance zone id |
|
| 10 | + public $territory_id; // Avoidance zone id |
|
| 11 | 11 | public $territory_name; |
| 12 | 12 | public $territory_color; |
| 13 | 13 | public $orders; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | $avoidanceZoneParameters = new AvoidanceZone(); |
| 32 | 32 | |
| 33 | - foreach($params as $key => $value) { |
|
| 33 | + foreach ($params as $key => $value) { |
|
| 34 | 34 | if (property_exists($avoidanceZoneParameters, $key)) { |
| 35 | 35 | $avoidanceZoneParameters->{$key} = $value; |
| 36 | 36 | } |
@@ -7,111 +7,111 @@ |
||
| 7 | 7 | |
| 8 | 8 | class AvoidanceZone extends Common |
| 9 | 9 | { |
| 10 | - public $territory_id; // Avoidance zone id |
|
| 11 | - public $territory_name; |
|
| 12 | - public $territory_color; |
|
| 13 | - public $orders; |
|
| 14 | - public $member_id; |
|
| 15 | - public $territory; // Territory parameters |
|
| 10 | + public $territory_id; // Avoidance zone id |
|
| 11 | + public $territory_name; |
|
| 12 | + public $territory_color; |
|
| 13 | + public $orders; |
|
| 14 | + public $member_id; |
|
| 15 | + public $territory; // Territory parameters |
|
| 16 | 16 | |
| 17 | - public static function fromArray(array $params) |
|
| 18 | - { |
|
| 19 | - if (!isset($params['territory_name'])) { |
|
| 20 | - throw new BadParam('Territory name must be provided'); |
|
| 21 | - } |
|
| 17 | + public static function fromArray(array $params) |
|
| 18 | + { |
|
| 19 | + if (!isset($params['territory_name'])) { |
|
| 20 | + throw new BadParam('Territory name must be provided'); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - if (!isset($params['territory_color'])) { |
|
| 24 | - throw new BadParam('Territory color must be provided'); |
|
| 25 | - } |
|
| 23 | + if (!isset($params['territory_color'])) { |
|
| 24 | + throw new BadParam('Territory color must be provided'); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - if (!isset($params['territory'])) { |
|
| 28 | - throw new BadParam('Territory must be provided'); |
|
| 29 | - } |
|
| 27 | + if (!isset($params['territory'])) { |
|
| 28 | + throw new BadParam('Territory must be provided'); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $avoidanceZoneParameters = new AvoidanceZone(); |
|
| 31 | + $avoidanceZoneParameters = new AvoidanceZone(); |
|
| 32 | 32 | |
| 33 | - foreach($params as $key => $value) { |
|
| 34 | - if (property_exists($avoidanceZoneParameters, $key)) { |
|
| 35 | - $avoidanceZoneParameters->{$key} = $value; |
|
| 36 | - } |
|
| 37 | - } |
|
| 33 | + foreach($params as $key => $value) { |
|
| 34 | + if (property_exists($avoidanceZoneParameters, $key)) { |
|
| 35 | + $avoidanceZoneParameters->{$key} = $value; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - return $avoidanceZoneParameters; |
|
| 40 | - } |
|
| 39 | + return $avoidanceZoneParameters; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public static function getAvoidanceZone($territory_id) |
|
| 43 | - { |
|
| 44 | - $avoidanceZone = Route4Me::makeRequst(array( |
|
| 45 | - 'url' => Endpoint::AVOIDANCE_ZONE, |
|
| 46 | - 'method' => 'GET', |
|
| 47 | - 'query' => array( |
|
| 48 | - 'territory_id' => $territory_id |
|
| 49 | - ) |
|
| 50 | - )); |
|
| 42 | + public static function getAvoidanceZone($territory_id) |
|
| 43 | + { |
|
| 44 | + $avoidanceZone = Route4Me::makeRequst(array( |
|
| 45 | + 'url' => Endpoint::AVOIDANCE_ZONE, |
|
| 46 | + 'method' => 'GET', |
|
| 47 | + 'query' => array( |
|
| 48 | + 'territory_id' => $territory_id |
|
| 49 | + ) |
|
| 50 | + )); |
|
| 51 | 51 | |
| 52 | - return $avoidanceZone; |
|
| 53 | - } |
|
| 52 | + return $avoidanceZone; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public static function getAvoidanceZones($params) |
|
| 56 | - { |
|
| 57 | - $avoidanceZones = Route4Me::makeRequst(array( |
|
| 58 | - 'url' => Endpoint::AVOIDANCE_ZONE, |
|
| 59 | - 'method' => 'GET', |
|
| 60 | - 'query' => array( |
|
| 61 | - 'offset' => isset($params->offset) ? $params->offset : null, |
|
| 62 | - 'limit' => isset($params->limit) ? $params->limit : null, |
|
| 63 | - ) |
|
| 64 | - )); |
|
| 55 | + public static function getAvoidanceZones($params) |
|
| 56 | + { |
|
| 57 | + $avoidanceZones = Route4Me::makeRequst(array( |
|
| 58 | + 'url' => Endpoint::AVOIDANCE_ZONE, |
|
| 59 | + 'method' => 'GET', |
|
| 60 | + 'query' => array( |
|
| 61 | + 'offset' => isset($params->offset) ? $params->offset : null, |
|
| 62 | + 'limit' => isset($params->limit) ? $params->limit : null, |
|
| 63 | + ) |
|
| 64 | + )); |
|
| 65 | 65 | |
| 66 | - return $avoidanceZones; |
|
| 67 | - } |
|
| 66 | + return $avoidanceZones; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public static function addAvoidanceZone($params) |
|
| 70 | - { |
|
| 71 | - $terParams = array(); |
|
| 69 | + public static function addAvoidanceZone($params) |
|
| 70 | + { |
|
| 71 | + $terParams = array(); |
|
| 72 | 72 | |
| 73 | - if (isset($params->territory['type'])) { |
|
| 74 | - $terParams['type'] = $params->territory['type']; |
|
| 75 | - } |
|
| 73 | + if (isset($params->territory['type'])) { |
|
| 74 | + $terParams['type'] = $params->territory['type']; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - if (isset($params->territory['data'])) { |
|
| 78 | - $terParams['data'] = $params->territory['data']; |
|
| 79 | - } |
|
| 77 | + if (isset($params->territory['data'])) { |
|
| 78 | + $terParams['data'] = $params->territory['data']; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $abContacts = Route4Me::makeRequst(array( |
|
| 82 | - 'url' => Endpoint::AVOIDANCE_ZONE, |
|
| 83 | - 'method' => 'POST', |
|
| 84 | - 'body' => array( |
|
| 85 | - 'territory_name' => isset($params->territory_name) ? $params->territory_name : null, |
|
| 86 | - 'territory_color' => isset($params->territory_color) ? $params->territory_color : null, |
|
| 87 | - 'territory' => $terParams |
|
| 88 | - ) |
|
| 89 | - )); |
|
| 81 | + $abContacts = Route4Me::makeRequst(array( |
|
| 82 | + 'url' => Endpoint::AVOIDANCE_ZONE, |
|
| 83 | + 'method' => 'POST', |
|
| 84 | + 'body' => array( |
|
| 85 | + 'territory_name' => isset($params->territory_name) ? $params->territory_name : null, |
|
| 86 | + 'territory_color' => isset($params->territory_color) ? $params->territory_color : null, |
|
| 87 | + 'territory' => $terParams |
|
| 88 | + ) |
|
| 89 | + )); |
|
| 90 | 90 | |
| 91 | - return $abContacts; |
|
| 92 | - } |
|
| 91 | + return $abContacts; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - public function deleteAvoidanceZone($territory_id) |
|
| 95 | - { |
|
| 96 | - $result = Route4Me::makeRequst(array( |
|
| 97 | - 'url' => Endpoint::AVOIDANCE_ZONE, |
|
| 98 | - 'method' => 'DELETEARRAY', |
|
| 99 | - 'query' => array( |
|
| 100 | - 'territory_id' => $territory_id |
|
| 101 | - ) |
|
| 102 | - )); |
|
| 94 | + public function deleteAvoidanceZone($territory_id) |
|
| 95 | + { |
|
| 96 | + $result = Route4Me::makeRequst(array( |
|
| 97 | + 'url' => Endpoint::AVOIDANCE_ZONE, |
|
| 98 | + 'method' => 'DELETEARRAY', |
|
| 99 | + 'query' => array( |
|
| 100 | + 'territory_id' => $territory_id |
|
| 101 | + ) |
|
| 102 | + )); |
|
| 103 | 103 | |
| 104 | - return $result; |
|
| 105 | - } |
|
| 104 | + return $result; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function updateAvoidanceZone($params) |
|
| 108 | - { |
|
| 109 | - $avoidanceZone = Route4Me::makeRequst(array( |
|
| 110 | - 'url' => Endpoint::AVOIDANCE_ZONE, |
|
| 111 | - 'method' => 'PUT', |
|
| 112 | - 'body' => $params, |
|
| 113 | - )); |
|
| 107 | + public function updateAvoidanceZone($params) |
|
| 108 | + { |
|
| 109 | + $avoidanceZone = Route4Me::makeRequst(array( |
|
| 110 | + 'url' => Endpoint::AVOIDANCE_ZONE, |
|
| 111 | + 'method' => 'PUT', |
|
| 112 | + 'body' => $params, |
|
| 113 | + )); |
|
| 114 | 114 | |
| 115 | - return $avoidanceZone; |
|
| 116 | - } |
|
| 115 | + return $avoidanceZone; |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | Route4Me::setApiKey('11111111111111111111111111111111'); |
| 15 | 15 | |
| 16 | 16 | $activityParameters = ActivityParameters::fromArray(array( |
| 17 | - "limit" => 10, |
|
| 18 | - "offset" => 0 |
|
| 17 | + "limit" => 10, |
|
| 18 | + "offset" => 0 |
|
| 19 | 19 | )); |
| 20 | 20 | |
| 21 | 21 | $activities = new ActivityParameters(); |
@@ -23,6 +23,6 @@ discard block |
||
| 23 | 23 | $results = $activities->getValue($actresults, "results"); |
| 24 | 24 | |
| 25 | 25 | foreach ($results as $result) { |
| 26 | - Route4Me::simplePrint($result); |
|
| 27 | - echo "<br>"; |
|
| 26 | + Route4Me::simplePrint($result); |
|
| 27 | + echo "<br>"; |
|
| 28 | 28 | } |
@@ -16,9 +16,9 @@ discard block |
||
| 16 | 16 | Route4Me::setApiKey('11111111111111111111111111111111'); |
| 17 | 17 | |
| 18 | 18 | $activityParameters = ActivityParameters::fromArray(array( |
| 19 | - "limit" => 10, |
|
| 20 | - "offset" => 0, |
|
| 21 | - "start" => strtotime("-1 week") |
|
| 19 | + "limit" => 10, |
|
| 20 | + "offset" => 0, |
|
| 21 | + "start" => strtotime("-1 week") |
|
| 22 | 22 | )); |
| 23 | 23 | |
| 24 | 24 | $activities = new ActivityParameters(); |
@@ -26,6 +26,6 @@ discard block |
||
| 26 | 26 | $results = $activities->getValue($actresults, "results"); |
| 27 | 27 | |
| 28 | 28 | foreach ($results as $result) { |
| 29 | - Route4Me::simplePrint($result); |
|
| 30 | - echo "<br>"; |
|
| 29 | + Route4Me::simplePrint($result); |
|
| 30 | + echo "<br>"; |
|
| 31 | 31 | } |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Route4Me; |
| 3 | 3 | |
| 4 | -$root=realpath(dirname(__FILE__).'/../../'); |
|
| 4 | +$root = realpath(dirname(__FILE__).'/../../'); |
|
| 5 | 5 | require $root.'/vendor/autoload.php'; |
| 6 | 6 | |
| 7 | 7 | use Route4Me\Enum\DeviceType; |
@@ -27,16 +27,16 @@ discard block |
||
| 27 | 27 | // Set GPS postion to the selected route |
| 28 | 28 | // Set right member_id corresponding to the API key |
| 29 | 29 | $params = TrackSetParams::fromArray(array( |
| 30 | - 'format' => Format::SERIALIZED, |
|
| 31 | - 'route_id' => $routeId, |
|
| 32 | - 'member_id' => 105323, |
|
| 33 | - 'course' => 3, |
|
| 34 | - 'speed' => 100, |
|
| 35 | - 'lat' => 41.8927521, |
|
| 36 | - 'lng' => -109.0803888, |
|
| 37 | - 'device_type' => DeviceType::IPHONE, |
|
| 38 | - 'device_guid' => 'qweqweqwe', |
|
| 39 | - 'device_timestamp' => date('Y-m-d H:i:s') |
|
| 30 | + 'format' => Format::SERIALIZED, |
|
| 31 | + 'route_id' => $routeId, |
|
| 32 | + 'member_id' => 105323, |
|
| 33 | + 'course' => 3, |
|
| 34 | + 'speed' => 100, |
|
| 35 | + 'lat' => 41.8927521, |
|
| 36 | + 'lng' => -109.0803888, |
|
| 37 | + 'device_type' => DeviceType::IPHONE, |
|
| 38 | + 'device_guid' => 'qweqweqwe', |
|
| 39 | + 'device_timestamp' => date('Y-m-d H:i:s') |
|
| 40 | 40 | )); |
| 41 | 41 | |
| 42 | 42 | $status = Track::set($params); |
@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | assert($status['status'], "Can't send GPS position to the selected route"); |
| 47 | 47 | |
| 48 | 48 | if (!$status) { |
| 49 | - echo "Setting of GPS position failed"; |
|
| 50 | - return; |
|
| 49 | + echo "Setting of GPS position failed"; |
|
| 50 | + return; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $params = array( |
| 54 | - 'route_id' => $routeId, |
|
| 55 | - 'device_tracking_history' => '1' |
|
| 54 | + 'route_id' => $routeId, |
|
| 55 | + 'device_tracking_history' => '1' |
|
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | 58 | $result = $route->GetLastLocation($params); |
| 59 | 59 | |
| 60 | 60 | if (isset($result->tracking_history)) { |
| 61 | - foreach ($result->tracking_history as $history) { |
|
| 62 | - echo "Speed --> ".$history['s']."<br>"; |
|
| 63 | - echo "course --> ".$history['d']."<br>"; |
|
| 64 | - echo "Timestamp --> ".$history['ts_friendly']."<br>"; |
|
| 65 | - echo "Latitude --> ".$history['lt']."<br>"; |
|
| 66 | - echo "Longitude --> ".$history['lg']."<br>"; |
|
| 67 | - echo "========================================<br><br>"; |
|
| 68 | - } |
|
| 61 | + foreach ($result->tracking_history as $history) { |
|
| 62 | + echo "Speed --> ".$history['s']."<br>"; |
|
| 63 | + echo "course --> ".$history['d']."<br>"; |
|
| 64 | + echo "Timestamp --> ".$history['ts_friendly']."<br>"; |
|
| 65 | + echo "Latitude --> ".$history['lt']."<br>"; |
|
| 66 | + echo "Longitude --> ".$history['lg']."<br>"; |
|
| 67 | + echo "========================================<br><br>"; |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -44,21 +44,21 @@ discard block |
||
| 44 | 44 | $locationsFieldsMapping['monthly_nth_wwhat'] = 17; |
| 45 | 45 | |
| 46 | 46 | if (($handle = fopen("$source_file", "r"))!==FALSE) { |
| 47 | - $oAbook = new AddressBookLocation(); |
|
| 47 | + $oAbook = new AddressBookLocation(); |
|
| 48 | 48 | |
| 49 | - $results = $oAbook->addLocationsFromCsvFile($handle, $locationsFieldsMapping); |
|
| 49 | + $results = $oAbook->addLocationsFromCsvFile($handle, $locationsFieldsMapping); |
|
| 50 | 50 | |
| 51 | - echo "Errors: <br><br>"; |
|
| 51 | + echo "Errors: <br><br>"; |
|
| 52 | 52 | |
| 53 | - foreach ($results['fail'] as $evalue) { |
|
| 54 | - echo $evalue."<br>"; |
|
| 55 | - } |
|
| 53 | + foreach ($results['fail'] as $evalue) { |
|
| 54 | + echo $evalue."<br>"; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - echo "Successes: <br><br>"; |
|
| 57 | + echo "Successes: <br><br>"; |
|
| 58 | 58 | |
| 59 | - foreach ($results['success'] as $svalue) { |
|
| 60 | - echo $svalue."<br>"; |
|
| 61 | - } |
|
| 59 | + foreach ($results['success'] as $svalue) { |
|
| 60 | + echo $svalue."<br>"; |
|
| 61 | + } |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /* Add orders with schedules from a CSV file */ |
@@ -78,20 +78,20 @@ discard block |
||
| 78 | 78 | $ordersFieldsMapping['day_scheduled_for_YYMMDD'] = 8; |
| 79 | 79 | |
| 80 | 80 | if (($handle = fopen("$orders_file", "r"))!==FALSE) { |
| 81 | - $order = new Order(); |
|
| 82 | - $results = $order->addOrdersFromCsvFile($handle, $ordersFieldsMapping); |
|
| 81 | + $order = new Order(); |
|
| 82 | + $results = $order->addOrdersFromCsvFile($handle, $ordersFieldsMapping); |
|
| 83 | 83 | |
| 84 | - echo "Errors: <br><br>"; |
|
| 84 | + echo "Errors: <br><br>"; |
|
| 85 | 85 | |
| 86 | - foreach ($results['fail'] as $evalue) { |
|
| 87 | - echo $evalue."<br>"; |
|
| 88 | - } |
|
| 86 | + foreach ($results['fail'] as $evalue) { |
|
| 87 | + echo $evalue."<br>"; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - echo "Successes: <br><br>"; |
|
| 90 | + echo "Successes: <br><br>"; |
|
| 91 | 91 | |
| 92 | - foreach ($results['success'] as $svalue) { |
|
| 93 | - echo $svalue."<br>"; |
|
| 94 | - } |
|
| 92 | + foreach ($results['success'] as $svalue) { |
|
| 93 | + echo $svalue."<br>"; |
|
| 94 | + } |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /* Get Hybrid Optimization */ |
@@ -100,63 +100,63 @@ discard block |
||
| 100 | 100 | $sched_date = date("Y-m-d", $ep); |
| 101 | 101 | |
| 102 | 102 | $hybridParams = array( |
| 103 | - "target_date_string" => $sched_date, |
|
| 104 | - "timezone_offset_minutes" => 480 |
|
| 103 | + "target_date_string" => $sched_date, |
|
| 104 | + "timezone_offset_minutes" => 480 |
|
| 105 | 105 | ); |
| 106 | 106 | |
| 107 | 107 | $optimization = new OptimizationProblem(); |
| 108 | 108 | $hybridOptimization = $optimization->getHybridOptimization($hybridParams); |
| 109 | 109 | |
| 110 | 110 | if ($hybridOptimization!=null) { |
| 111 | - if (isset($hybridOptimization['optimization_problem_id'])) { |
|
| 112 | - $optid = $hybridOptimization['optimization_problem_id']; |
|
| 111 | + if (isset($hybridOptimization['optimization_problem_id'])) { |
|
| 112 | + $optid = $hybridOptimization['optimization_problem_id']; |
|
| 113 | 113 | |
| 114 | - echo "Hibrid optimization with optimization_problem_id = $optid <br><br>"; |
|
| 114 | + echo "Hibrid optimization with optimization_problem_id = $optid <br><br>"; |
|
| 115 | 115 | |
| 116 | - /* Add depots to the Hybrid Optimization */ |
|
| 117 | - $depotfile = "depots.csv"; |
|
| 116 | + /* Add depots to the Hybrid Optimization */ |
|
| 117 | + $depotfile = "depots.csv"; |
|
| 118 | 118 | |
| 119 | - if (($handle = fopen("$depotfile", "r"))!==FALSE) { |
|
| 120 | - $columns = fgetcsv($handle, $max_line_length, $delemietr); |
|
| 119 | + if (($handle = fopen("$depotfile", "r"))!==FALSE) { |
|
| 120 | + $columns = fgetcsv($handle, $max_line_length, $delemietr); |
|
| 121 | 121 | |
| 122 | - if (empty($columns)) { |
|
| 123 | - $error['message'] = 'Empty'; |
|
| 124 | - return ($error); |
|
| 125 | - } |
|
| 122 | + if (empty($columns)) { |
|
| 123 | + $error['message'] = 'Empty'; |
|
| 124 | + return ($error); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - $depotsParams = array( |
|
| 128 | - 'optimization_problem_id' => $optid, |
|
| 129 | - 'delete_old_depots' => true, |
|
| 130 | - ); |
|
| 127 | + $depotsParams = array( |
|
| 128 | + 'optimization_problem_id' => $optid, |
|
| 129 | + 'delete_old_depots' => true, |
|
| 130 | + ); |
|
| 131 | 131 | |
| 132 | - $iRow = 1; |
|
| 133 | - $depotAddresses = array(); |
|
| 132 | + $iRow = 1; |
|
| 133 | + $depotAddresses = array(); |
|
| 134 | 134 | |
| 135 | - while (($rows = fgetcsv($handle, $max_line_length, $delemietr))!==false) { |
|
| 136 | - if ($rows[0] && $rows[1] && $rows[3] && array(null)!==$rows) { |
|
| 137 | - $depotAddress['lat'] = $rows[0]; |
|
| 138 | - $depotAddress['lng'] = $rows[1]; |
|
| 139 | - $depotAddress['address'] = $rows[3]; |
|
| 140 | - array_push($depotAddresses, $depotAddress); |
|
| 141 | - } |
|
| 142 | - } |
|
| 135 | + while (($rows = fgetcsv($handle, $max_line_length, $delemietr))!==false) { |
|
| 136 | + if ($rows[0] && $rows[1] && $rows[3] && array(null)!==$rows) { |
|
| 137 | + $depotAddress['lat'] = $rows[0]; |
|
| 138 | + $depotAddress['lng'] = $rows[1]; |
|
| 139 | + $depotAddress['address'] = $rows[3]; |
|
| 140 | + array_push($depotAddresses, $depotAddress); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - $depotsParams['new_depots'] = $depotAddresses; |
|
| 144 | + $depotsParams['new_depots'] = $depotAddresses; |
|
| 145 | 145 | |
| 146 | - $optProblem = new OptimizationProblem(); |
|
| 146 | + $optProblem = new OptimizationProblem(); |
|
| 147 | 147 | |
| 148 | - $resultDepots = $optProblem->addDepotsToHybrid($depotsParams); |
|
| 148 | + $resultDepots = $optProblem->addDepotsToHybrid($depotsParams); |
|
| 149 | 149 | |
| 150 | - /* Reoptimize hybrid optimization */ |
|
| 150 | + /* Reoptimize hybrid optimization */ |
|
| 151 | 151 | |
| 152 | - if ($resultDepots!=null) { |
|
| 153 | - $problemParams = array( |
|
| 154 | - 'optimization_problem_id' => $optid |
|
| 155 | - ); |
|
| 156 | - $problem = OptimizationProblem::reoptimize($problemParams); |
|
| 152 | + if ($resultDepots!=null) { |
|
| 153 | + $problemParams = array( |
|
| 154 | + 'optimization_problem_id' => $optid |
|
| 155 | + ); |
|
| 156 | + $problem = OptimizationProblem::reoptimize($problemParams); |
|
| 157 | 157 | |
| 158 | - Route4Me::simplePrint($problem); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 158 | + Route4Me::simplePrint($problem); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | 162 | } |
@@ -96,7 +96,7 @@ |
||
| 96 | 96 | |
| 97 | 97 | /* Get Hybrid Optimization */ |
| 98 | 98 | |
| 99 | -$ep = time()+604800; |
|
| 99 | +$ep = time() + 604800; |
|
| 100 | 100 | $sched_date = date("Y-m-d", $ep); |
| 101 | 101 | |
| 102 | 102 | $hybridParams = array( |
@@ -15,14 +15,14 @@ |
||
| 15 | 15 | $vehicle = new Vehicle(); |
| 16 | 16 | |
| 17 | 17 | $vehicleParameters = array( |
| 18 | - "with_pagination" => true, |
|
| 19 | - "page" => 2, |
|
| 20 | - "perPage" => 10 |
|
| 21 | - ); |
|
| 18 | + "with_pagination" => true, |
|
| 19 | + "page" => 2, |
|
| 20 | + "perPage" => 10 |
|
| 21 | + ); |
|
| 22 | 22 | |
| 23 | 23 | $response = $vehicle->getVehicles($vehicleParameters); |
| 24 | 24 | |
| 25 | 25 | foreach ($response['data'] as $key => $vehicle) { |
| 26 | - Route4Me::simplePrint($vehicle); |
|
| 27 | - echo "<br>"; |
|
| 26 | + Route4Me::simplePrint($vehicle); |
|
| 27 | + echo "<br>"; |
|
| 28 | 28 | } |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | |
| 25 | 25 | // Delete member from the user's account |
| 26 | 26 | $params = Member::fromArray(array ( |
| 27 | - "member_id" => $randomMemberID |
|
| 27 | + "member_id" => $randomMemberID |
|
| 28 | 28 | )); |
| 29 | 29 | |
| 30 | 30 | $response = $member->deleteMember($params); |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | assert(!is_null($randomMemberID), "There is no member of the type SUB_ACCOUNT_DRIVER in the user's account"); |
| 24 | 24 | |
| 25 | 25 | // Delete member from the user's account |
| 26 | -$params = Member::fromArray(array ( |
|
| 26 | +$params = Member::fromArray(array( |
|
| 27 | 27 | "member_id" => $randomMemberID |
| 28 | 28 | )); |
| 29 | 29 | |
@@ -134,7 +134,7 @@ |
||
| 134 | 134 | |
| 135 | 135 | if ($file!=null) { |
| 136 | 136 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
| 137 | - $fp=fopen($file, 'r'); |
|
| 137 | + $fp = fopen($file, 'r'); |
|
| 138 | 138 | curl_setopt($ch, CURLOPT_INFILE, $fp); |
| 139 | 139 | curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
| 140 | 140 | } |
@@ -207,6 +207,7 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | /** |
| 209 | 209 | * @param $object: JSON object |
| 210 | + * @param \SimpleXMLElement $object |
|
| 210 | 211 | */ |
| 211 | 212 | public static function object2array($object) |
| 212 | 213 | { |
@@ -304,6 +305,7 @@ discard block |
||
| 304 | 305 | * Returns an array of the object properties |
| 305 | 306 | * @param $object: An object. |
| 306 | 307 | * @param $exclude: array of the object parameters to be excluded from the returned array. |
| 308 | + * @param string[] $exclude |
|
| 307 | 309 | */ |
| 308 | 310 | public static function getObjectProperties($object, $exclude) |
| 309 | 311 | { |
@@ -324,6 +326,7 @@ discard block |
||
| 324 | 326 | * Returns url path generated from the array of the fields and parameters. |
| 325 | 327 | * @param $allFields; array of the paossible fields (parameter names). |
| 326 | 328 | * @param $params: input parameters (array or object). |
| 329 | + * @param string[] $allFields |
|
| 327 | 330 | */ |
| 328 | 331 | public static function generateUrlPath($allFields, $params) |
| 329 | 332 | { |
@@ -7,291 +7,291 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Route4Me |
| 9 | 9 | { |
| 10 | - static public $apiKey; |
|
| 11 | - static public $baseUrl = Endpoint::BASE_URL; |
|
| 10 | + static public $apiKey; |
|
| 11 | + static public $baseUrl = Endpoint::BASE_URL; |
|
| 12 | 12 | |
| 13 | - public static function setApiKey($apiKey) |
|
| 14 | - { |
|
| 15 | - self::$apiKey = $apiKey; |
|
| 16 | - } |
|
| 13 | + public static function setApiKey($apiKey) |
|
| 14 | + { |
|
| 15 | + self::$apiKey = $apiKey; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public static function getApiKey() |
|
| 19 | - { |
|
| 20 | - return self::$apiKey; |
|
| 21 | - } |
|
| 18 | + public static function getApiKey() |
|
| 19 | + { |
|
| 20 | + return self::$apiKey; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public static function setBaseUrl($baseUrl) |
|
| 24 | - { |
|
| 25 | - self::$baseUrl = $baseUrl; |
|
| 26 | - } |
|
| 23 | + public static function setBaseUrl($baseUrl) |
|
| 24 | + { |
|
| 25 | + self::$baseUrl = $baseUrl; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public static function getBaseUrl() |
|
| 29 | - { |
|
| 30 | - return self::$baseUrl; |
|
| 31 | - } |
|
| 28 | + public static function getBaseUrl() |
|
| 29 | + { |
|
| 30 | + return self::$baseUrl; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public static function makeRequst($options) { |
|
| 34 | - $errorHandler = new myErrorHandler(); |
|
| 33 | + public static function makeRequst($options) { |
|
| 34 | + $errorHandler = new myErrorHandler(); |
|
| 35 | 35 | |
| 36 | - $old_error_handler = set_error_handler(array($errorHandler, "proc_error")); |
|
| 36 | + $old_error_handler = set_error_handler(array($errorHandler, "proc_error")); |
|
| 37 | 37 | |
| 38 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
| 39 | - $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
| 38 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
| 39 | + $query = isset($options['query']) ? array_filter($options['query'], function($x) { return !is_null($x); } ) : array(); |
|
| 40 | 40 | |
| 41 | - $body = isset($options['body']) ? $options['body'] : null; |
|
| 42 | - $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
| 43 | - $headers = array( |
|
| 44 | - "User-Agent: Route4Me php-sdk" |
|
| 45 | - ); |
|
| 41 | + $body = isset($options['body']) ? $options['body'] : null; |
|
| 42 | + $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
| 43 | + $headers = array( |
|
| 44 | + "User-Agent: Route4Me php-sdk" |
|
| 45 | + ); |
|
| 46 | 46 | |
| 47 | - if (isset($options['HTTPHEADER'])) { |
|
| 48 | - $headers[] = $options['HTTPHEADER']; |
|
| 49 | - } |
|
| 47 | + if (isset($options['HTTPHEADER'])) { |
|
| 48 | + $headers[] = $options['HTTPHEADER']; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - if (isset($options['HTTPHEADERS'])) { |
|
| 52 | - foreach ($options['HTTPHEADERS'] As $header) { |
|
| 53 | - $headers[] = $header; |
|
| 54 | - } |
|
| 55 | - } |
|
| 51 | + if (isset($options['HTTPHEADERS'])) { |
|
| 52 | + foreach ($options['HTTPHEADERS'] As $header) { |
|
| 53 | + $headers[] = $header; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $ch = curl_init(); |
|
| 57 | + $ch = curl_init(); |
|
| 58 | 58 | |
| 59 | - $url = isset($options['url']) ? $options['url'].'?'.http_build_query(array_merge( |
|
| 60 | - $query, array('api_key' => self::getApiKey()) |
|
| 61 | - )) : ""; |
|
| 59 | + $url = isset($options['url']) ? $options['url'].'?'.http_build_query(array_merge( |
|
| 60 | + $query, array('api_key' => self::getApiKey()) |
|
| 61 | + )) : ""; |
|
| 62 | 62 | |
| 63 | - $baseUrl = self::getBaseUrl(); |
|
| 63 | + $baseUrl = self::getBaseUrl(); |
|
| 64 | 64 | |
| 65 | - $curlOpts = array( |
|
| 66 | - CURLOPT_URL => $baseUrl.$url, |
|
| 67 | - CURLOPT_RETURNTRANSFER => true, |
|
| 68 | - CURLOPT_TIMEOUT => 80, |
|
| 69 | - CURLOPT_FOLLOWLOCATION => true, |
|
| 70 | - CURLOPT_SSL_VERIFYHOST => FALSE, |
|
| 71 | - CURLOPT_SSL_VERIFYPEER => FALSE, |
|
| 72 | - CURLOPT_HTTPHEADER => $headers |
|
| 73 | - ); |
|
| 65 | + $curlOpts = array( |
|
| 66 | + CURLOPT_URL => $baseUrl.$url, |
|
| 67 | + CURLOPT_RETURNTRANSFER => true, |
|
| 68 | + CURLOPT_TIMEOUT => 80, |
|
| 69 | + CURLOPT_FOLLOWLOCATION => true, |
|
| 70 | + CURLOPT_SSL_VERIFYHOST => FALSE, |
|
| 71 | + CURLOPT_SSL_VERIFYPEER => FALSE, |
|
| 72 | + CURLOPT_HTTPHEADER => $headers |
|
| 73 | + ); |
|
| 74 | 74 | |
| 75 | - curl_setopt_array($ch, $curlOpts); |
|
| 75 | + curl_setopt_array($ch, $curlOpts); |
|
| 76 | 76 | |
| 77 | - if ($file!=null) { |
|
| 78 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
| 79 | - $fp=fopen($file, 'r'); |
|
| 80 | - curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
| 81 | - curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
| 82 | - } |
|
| 77 | + if ($file!=null) { |
|
| 78 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
|
| 79 | + $fp=fopen($file, 'r'); |
|
| 80 | + curl_setopt($ch, CURLOPT_INFILE, $fp); |
|
| 81 | + curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file)); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - switch ($method) { |
|
| 85 | - case 'DELETE': |
|
| 86 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
| 87 | - break; |
|
| 88 | - case 'DELETEARRAY': |
|
| 89 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
| 90 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
| 91 | - break; |
|
| 92 | - case 'PUT': |
|
| 93 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
| 94 | - break; |
|
| 95 | - case 'POST': |
|
| 96 | - if (isset($body)) { |
|
| 97 | - $bodyData = json_encode($body); |
|
| 98 | - if (isset($options['HTTPHEADER'])) { |
|
| 99 | - if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) { |
|
| 100 | - $bodyData = $body; |
|
| 101 | - } |
|
| 102 | - } |
|
| 84 | + switch ($method) { |
|
| 85 | + case 'DELETE': |
|
| 86 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
| 87 | + break; |
|
| 88 | + case 'DELETEARRAY': |
|
| 89 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
| 90 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
| 91 | + break; |
|
| 92 | + case 'PUT': |
|
| 93 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
| 94 | + break; |
|
| 95 | + case 'POST': |
|
| 96 | + if (isset($body)) { |
|
| 97 | + $bodyData = json_encode($body); |
|
| 98 | + if (isset($options['HTTPHEADER'])) { |
|
| 99 | + if (strpos($options['HTTPHEADER'], "multipart/form-data")>0) { |
|
| 100 | + $bodyData = $body; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
| 105 | - } |
|
| 106 | - break; |
|
| 107 | - case 'ADD': |
|
| 108 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
| 109 | - } |
|
| 104 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
| 105 | + } |
|
| 106 | + break; |
|
| 107 | + case 'ADD': |
|
| 108 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); break; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - if (is_numeric(array_search($method, array('DELETE', 'PUT')))) { |
|
| 112 | - if (isset($body)) { |
|
| 113 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
| 114 | - } |
|
| 115 | - } |
|
| 111 | + if (is_numeric(array_search($method, array('DELETE', 'PUT')))) { |
|
| 112 | + if (isset($body)) { |
|
| 113 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - $result = curl_exec($ch); |
|
| 117 | + $result = curl_exec($ch); |
|
| 118 | 118 | |
| 119 | - $isxml = FALSE; |
|
| 120 | - $jxml = ""; |
|
| 121 | - if (strpos($result, '<?xml')>-1) { |
|
| 122 | - $xml = simplexml_load_string($result); |
|
| 123 | - //$jxml = json_encode($xml); |
|
| 124 | - $jxml = self::object2array($xml); |
|
| 125 | - $isxml = TRUE; |
|
| 126 | - } |
|
| 119 | + $isxml = FALSE; |
|
| 120 | + $jxml = ""; |
|
| 121 | + if (strpos($result, '<?xml')>-1) { |
|
| 122 | + $xml = simplexml_load_string($result); |
|
| 123 | + //$jxml = json_encode($xml); |
|
| 124 | + $jxml = self::object2array($xml); |
|
| 125 | + $isxml = TRUE; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 129 | - curl_close($ch); |
|
| 128 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 129 | + curl_close($ch); |
|
| 130 | 130 | |
| 131 | - if (200==$code) { |
|
| 132 | - if ($isxml) { |
|
| 133 | - $json = $jxml; |
|
| 134 | - } else { |
|
| 135 | - $json = json_decode($result, true); |
|
| 136 | - } |
|
| 131 | + if (200==$code) { |
|
| 132 | + if ($isxml) { |
|
| 133 | + $json = $jxml; |
|
| 134 | + } else { |
|
| 135 | + $json = json_decode($result, true); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - if (isset($json['errors'])) { |
|
| 139 | - throw new ApiError(implode(', ', $json['errors'])); |
|
| 140 | - } else { |
|
| 141 | - return $json; |
|
| 142 | - } |
|
| 143 | - } elseif (409==$code) { |
|
| 144 | - throw new ApiError('Wrong API key'); |
|
| 145 | - } else { |
|
| 146 | - throw new ApiError('Something wrong'); |
|
| 147 | - } |
|
| 148 | - } |
|
| 138 | + if (isset($json['errors'])) { |
|
| 139 | + throw new ApiError(implode(', ', $json['errors'])); |
|
| 140 | + } else { |
|
| 141 | + return $json; |
|
| 142 | + } |
|
| 143 | + } elseif (409==$code) { |
|
| 144 | + throw new ApiError('Wrong API key'); |
|
| 145 | + } else { |
|
| 146 | + throw new ApiError('Something wrong'); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * @param $object: JSON object |
|
| 152 | - */ |
|
| 153 | - public static function object2array($object) |
|
| 154 | - { |
|
| 155 | - return @json_decode(@json_encode($object), 1); |
|
| 156 | - } |
|
| 150 | + /** |
|
| 151 | + * @param $object: JSON object |
|
| 152 | + */ |
|
| 153 | + public static function object2array($object) |
|
| 154 | + { |
|
| 155 | + return @json_decode(@json_encode($object), 1); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Prints on the screen main keys and values of the array |
|
| 161 | - * @param $results: object to be printed on the screen. |
|
| 162 | - * @param $deepPrinting: if true, object will be printed recursively. |
|
| 163 | - */ |
|
| 164 | - public static function simplePrint($results, $deepPrinting = null) |
|
| 165 | - { |
|
| 166 | - if (isset($results)) { |
|
| 167 | - if (is_array($results)) { |
|
| 168 | - foreach ($results as $key=>$result) { |
|
| 169 | - if (is_array($result)) { |
|
| 170 | - foreach ($result as $key1=>$result1) { |
|
| 171 | - if (is_array($result1)) { |
|
| 172 | - if ($deepPrinting) { |
|
| 173 | - echo "<br>$key1 ------><br>"; |
|
| 174 | - Route4Me::simplePrint($result1, true); |
|
| 175 | - echo "------<br>"; |
|
| 176 | - } else { |
|
| 177 | - echo $key1." --> "."Array() <br>"; |
|
| 178 | - } |
|
| 179 | - } else { |
|
| 180 | - if (is_object($result1)) { |
|
| 181 | - if ($deepPrinting) { |
|
| 182 | - echo "<br>$key1 ------><br>"; |
|
| 183 | - $oarray = (array)$result1; |
|
| 184 | - Route4Me::simplePrint($oarray, true); |
|
| 185 | - echo "------<br>"; |
|
| 186 | - } else { |
|
| 187 | - echo $key1." --> "."Object <br>"; |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - if (!is_null($result1)) { |
|
| 191 | - echo $key1." --> ".$result1."<br>"; |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - } else { |
|
| 197 | - if (is_object($result)) { |
|
| 198 | - if ($deepPrinting) { |
|
| 199 | - echo "<br>$key ------><br>"; |
|
| 200 | - $oarray = (array)$result; |
|
| 201 | - Route4Me::simplePrint($oarray, true); |
|
| 202 | - echo "------<br>"; |
|
| 203 | - } else { |
|
| 204 | - echo $key." --> "."Object <br>"; |
|
| 205 | - } |
|
| 206 | - } else { |
|
| 207 | - if (!is_null($result)) { |
|
| 208 | - echo $key." --> ".$result."<br>"; |
|
| 209 | - } |
|
| 210 | - } |
|
| 159 | + /** |
|
| 160 | + * Prints on the screen main keys and values of the array |
|
| 161 | + * @param $results: object to be printed on the screen. |
|
| 162 | + * @param $deepPrinting: if true, object will be printed recursively. |
|
| 163 | + */ |
|
| 164 | + public static function simplePrint($results, $deepPrinting = null) |
|
| 165 | + { |
|
| 166 | + if (isset($results)) { |
|
| 167 | + if (is_array($results)) { |
|
| 168 | + foreach ($results as $key=>$result) { |
|
| 169 | + if (is_array($result)) { |
|
| 170 | + foreach ($result as $key1=>$result1) { |
|
| 171 | + if (is_array($result1)) { |
|
| 172 | + if ($deepPrinting) { |
|
| 173 | + echo "<br>$key1 ------><br>"; |
|
| 174 | + Route4Me::simplePrint($result1, true); |
|
| 175 | + echo "------<br>"; |
|
| 176 | + } else { |
|
| 177 | + echo $key1." --> "."Array() <br>"; |
|
| 178 | + } |
|
| 179 | + } else { |
|
| 180 | + if (is_object($result1)) { |
|
| 181 | + if ($deepPrinting) { |
|
| 182 | + echo "<br>$key1 ------><br>"; |
|
| 183 | + $oarray = (array)$result1; |
|
| 184 | + Route4Me::simplePrint($oarray, true); |
|
| 185 | + echo "------<br>"; |
|
| 186 | + } else { |
|
| 187 | + echo $key1." --> "."Object <br>"; |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + if (!is_null($result1)) { |
|
| 191 | + echo $key1." --> ".$result1."<br>"; |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + } else { |
|
| 197 | + if (is_object($result)) { |
|
| 198 | + if ($deepPrinting) { |
|
| 199 | + echo "<br>$key ------><br>"; |
|
| 200 | + $oarray = (array)$result; |
|
| 201 | + Route4Me::simplePrint($oarray, true); |
|
| 202 | + echo "------<br>"; |
|
| 203 | + } else { |
|
| 204 | + echo $key." --> "."Object <br>"; |
|
| 205 | + } |
|
| 206 | + } else { |
|
| 207 | + if (!is_null($result)) { |
|
| 208 | + echo $key." --> ".$result."<br>"; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - } |
|
| 213 | - //echo "<br>"; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 212 | + } |
|
| 213 | + //echo "<br>"; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * Generates query or body parameters. |
|
| 221 | - * @param $allFields: all known fields could be used for parameters generation. |
|
| 222 | - * @param $params: input parameters (array or object) |
|
| 223 | - */ |
|
| 224 | - public static function generateRequestParameters($allFields, $params) |
|
| 225 | - { |
|
| 226 | - $generatedParams = array(); |
|
| 219 | + /** |
|
| 220 | + * Generates query or body parameters. |
|
| 221 | + * @param $allFields: all known fields could be used for parameters generation. |
|
| 222 | + * @param $params: input parameters (array or object) |
|
| 223 | + */ |
|
| 224 | + public static function generateRequestParameters($allFields, $params) |
|
| 225 | + { |
|
| 226 | + $generatedParams = array(); |
|
| 227 | 227 | |
| 228 | - if (is_array($params)) { |
|
| 229 | - foreach ($allFields as $field) { |
|
| 230 | - if (isset($params[$field])) { |
|
| 231 | - $generatedParams[$field] = $params[$field]; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - } elseif (is_object($params)) { |
|
| 235 | - foreach ($allFields as $field) { |
|
| 236 | - if (isset($params->{$field})) { |
|
| 237 | - $generatedParams[$field] = $params->{$field}; |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - } |
|
| 228 | + if (is_array($params)) { |
|
| 229 | + foreach ($allFields as $field) { |
|
| 230 | + if (isset($params[$field])) { |
|
| 231 | + $generatedParams[$field] = $params[$field]; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + } elseif (is_object($params)) { |
|
| 235 | + foreach ($allFields as $field) { |
|
| 236 | + if (isset($params->{$field})) { |
|
| 237 | + $generatedParams[$field] = $params->{$field}; |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $generatedParams; |
|
| 243 | - } |
|
| 242 | + return $generatedParams; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Returns an array of the object properties |
|
| 247 | - * @param $object: An object. |
|
| 248 | - * @param $exclude: array of the object parameters to be excluded from the returned array. |
|
| 249 | - */ |
|
| 250 | - public static function getObjectProperties($object, $exclude) |
|
| 251 | - { |
|
| 252 | - $objectParameters = array(); |
|
| 245 | + /** |
|
| 246 | + * Returns an array of the object properties |
|
| 247 | + * @param $object: An object. |
|
| 248 | + * @param $exclude: array of the object parameters to be excluded from the returned array. |
|
| 249 | + */ |
|
| 250 | + public static function getObjectProperties($object, $exclude) |
|
| 251 | + { |
|
| 252 | + $objectParameters = array(); |
|
| 253 | 253 | |
| 254 | - foreach (get_object_vars($object) as $key => $value) { |
|
| 255 | - if (property_exists($object, $key)) { |
|
| 256 | - if (!is_numeric(array_search($key, $exclude))) { |
|
| 257 | - array_push($objectParameters, $key); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - } |
|
| 254 | + foreach (get_object_vars($object) as $key => $value) { |
|
| 255 | + if (property_exists($object, $key)) { |
|
| 256 | + if (!is_numeric(array_search($key, $exclude))) { |
|
| 257 | + array_push($objectParameters, $key); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return $objectParameters; |
|
| 263 | - } |
|
| 262 | + return $objectParameters; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * Returns url path generated from the array of the fields and parameters. |
|
| 267 | - * @param $allFields; array of the paossible fields (parameter names). |
|
| 268 | - * @param $params: input parameters (array or object). |
|
| 269 | - */ |
|
| 270 | - public static function generateUrlPath($allFields, $params) |
|
| 271 | - { |
|
| 272 | - $generatedPath = ""; |
|
| 265 | + /** |
|
| 266 | + * Returns url path generated from the array of the fields and parameters. |
|
| 267 | + * @param $allFields; array of the paossible fields (parameter names). |
|
| 268 | + * @param $params: input parameters (array or object). |
|
| 269 | + */ |
|
| 270 | + public static function generateUrlPath($allFields, $params) |
|
| 271 | + { |
|
| 272 | + $generatedPath = ""; |
|
| 273 | 273 | |
| 274 | - if (is_array($params)) { |
|
| 275 | - foreach ($allFields as $field) { |
|
| 276 | - if (isset($params[$field])) { |
|
| 277 | - $generatedPath .= $params[$field].'/'; |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - } elseif (is_object($params)) { |
|
| 281 | - foreach ($allFields as $field) { |
|
| 282 | - if (isset($params->{$field})) { |
|
| 283 | - $generatedPath .= $params->{$field}.'/'; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - } |
|
| 274 | + if (is_array($params)) { |
|
| 275 | + foreach ($allFields as $field) { |
|
| 276 | + if (isset($params[$field])) { |
|
| 277 | + $generatedPath .= $params[$field].'/'; |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + } elseif (is_object($params)) { |
|
| 281 | + foreach ($allFields as $field) { |
|
| 282 | + if (isset($params->{$field})) { |
|
| 283 | + $generatedPath .= $params->{$field}.'/'; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - return $generatedPath; |
|
| 289 | - } |
|
| 288 | + return $generatedPath; |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - public static function getFileRealPath($fileName) |
|
| 292 | - { |
|
| 293 | - $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
| 291 | + public static function getFileRealPath($fileName) |
|
| 292 | + { |
|
| 293 | + $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
| 294 | 294 | |
| 295 | - return $rpath; |
|
| 296 | - } |
|
| 295 | + return $rpath; |
|
| 296 | + } |
|
| 297 | 297 | } |
@@ -17,9 +17,9 @@ |
||
| 17 | 17 | // Example refers to the process of searching for the routed locations |
| 18 | 18 | |
| 19 | 19 | $params = array( |
| 20 | - 'offset' => 0, |
|
| 21 | - 'limit' => 5, |
|
| 22 | - 'display' => 'routed' |
|
| 20 | + 'offset' => 0, |
|
| 21 | + 'limit' => 5, |
|
| 22 | + 'display' => 'routed' |
|
| 23 | 23 | ); |
| 24 | 24 | |
| 25 | 25 | $abcResult = $ablocation->searchAddressBookLocations($params); |