diff --git a/.env.dist b/.env.dist index b6766d67..509fee86 100644 --- a/.env.dist +++ b/.env.dist @@ -66,3 +66,6 @@ INVENTORY_API_AUTH_TOKEN=insert_auth_token_here # API logging API_LOGGING=set_to_true_or_false + +# customer distance limit in km +CUST_DISTANCE_LIMIT=set_to_number diff --git a/config/cmb.services.yaml b/config/cmb.services.yaml index 2c4accff..5f24e525 100644 --- a/config/cmb.services.yaml +++ b/config/cmb.services.yaml @@ -64,6 +64,7 @@ services: arguments: $em: "@doctrine.orm.entity_manager" $gmaps_api_key: "%env(GMAPS_API_KEY)%" + $cust_dist_limit: "%env(CUST_DISTANCE_LIMIT)%" App\Service\RisingTideGateway: arguments: diff --git a/config/resq.services.yaml b/config/resq.services.yaml index 3dbf1a91..284b7b73 100644 --- a/config/resq.services.yaml +++ b/config/resq.services.yaml @@ -64,6 +64,7 @@ services: arguments: $em: "@doctrine.orm.entity_manager" $gmaps_api_key: "%env(GMAPS_API_KEY)%" + $cust_dist_limit: "%env(CUST_DISTANCE_LIMIT)%" App\Service\RisingTideGateway: arguments: diff --git a/config/services.yaml b/config/services.yaml index 3dbf1a91..284b7b73 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -64,6 +64,7 @@ services: arguments: $em: "@doctrine.orm.entity_manager" $gmaps_api_key: "%env(GMAPS_API_KEY)%" + $cust_dist_limit: "%env(CUST_DISTANCE_LIMIT)%" App\Service\RisingTideGateway: arguments: diff --git a/src/Service/MapTools.php b/src/Service/MapTools.php index 17511fba..b60130a0 100644 --- a/src/Service/MapTools.php +++ b/src/Service/MapTools.php @@ -17,10 +17,15 @@ class MapTools // google maps api key protected $gmaps_api_key; - public function __construct(EntityManagerInterface $em, $gmaps_api_key) + // customer distance limit + protected $cust_dist_limit; + + public function __construct(EntityManagerInterface $em, $gmaps_api_key, + $cust_dist_limit) { $this->em = $em; $this->gmaps_api_key = $gmaps_api_key; + $this->cust_dist_limit = $cust_dist_limit; } protected function mapGetDistances(Point $point, $hubs) @@ -148,7 +153,8 @@ class MapTools return $final_data; */ } - + + // NOTE: only the API calls this public function getClosestOpenHubs(Point $point, $limit, $time = false) { // get closest hubs based on st_distance function from db @@ -184,14 +190,18 @@ class MapTools // get distance in kilometers from customer point to hub point $dist = $this->distance($cust_lat, $cust_lng, $hub_lat, $hub_lng); - $final_data[] = [ - 'hub' => $row[0], - 'db_distance' => $row['dist'], - 'distance' => $dist, - 'duration' => 0, - ]; + if ($dist < $this->cust_dist_limit) + { + $final_data[] = [ + 'hub' => $row[0], + 'db_distance' => $row['dist'], + 'distance' => $dist, + 'duration' => 0, + ]; + } } + error_log('nearest open hubs count: ' . count($final_data)); return $final_data; }