From 0de8f71d0e22d98e3247f9cc6bd7e748b6552321 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 29 Jul 2021 06:40:07 +0000 Subject: [PATCH] Add hub filter option in .env. #605 --- .env.dist | 1 + config/services.yaml | 1 + src/Controller/APIController.php | 27 +++++++++++++------ src/Service/HubFilteringGeoChecker.php | 4 --- .../JobOrderHandler/ResqJobOrderHandler.php | 24 +++++++++++------ 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/.env.dist b/.env.dist index 611bfcfe..3919b7e8 100644 --- a/.env.dist +++ b/.env.dist @@ -89,3 +89,4 @@ HUB_JO_KEY=hub_jo_count # hub geofence HUB_GEOFENCE_ENABLE=set_to_true_or_false +HUB_FILTER_ENABLE=set_to_true_or_false diff --git a/config/services.yaml b/config/services.yaml index bed217dd..0498fcdd 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -171,6 +171,7 @@ services: arguments: $country_code: "%env(COUNTRY_CODE)%" $cust_distance_limit: "%env(CUST_DISTANCE_LIMIT_ADMIN_PANEL)%" + $hub_filter_enabled: "%env(HUB_FILTER_ENABLE)%" #job order generator interface App\Service\JobOrderHandlerInterface: "@App\\Service\\JobOrderHandler\\ResqJobOrderHandler" diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index cd0c8212..e42a3556 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -854,6 +854,8 @@ class APIController extends Controller implements LoggedController return $res->getReturnResponse(); } + // TODO: remove later + // mobile app no longer calls this public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo, MapTools $map_tools, InventoryManager $im, MQTTClient $mclient, RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger, @@ -2767,22 +2769,31 @@ class APIController extends Controller implements LoggedController $hub_criteria->setPoint($jo->getCoordinates()); // get distance limit for mobile from env + // get value of hub_filter_enable from env $dotenv = new Dotenv(); $dotenv->loadEnv(__DIR__.'/../../.env'); $limit_distance = $_ENV['CUST_DISTANCE_LIMIT']; + $hub_filter_enabled = $_ENV['HUB_FILTER_ENABLE']; // set distance limit $hub_criteria->setLimitDistance($limit_distance); - if ($hub_geofence->isCovered($long, $lat)) + // check if hub filter is enabled. If not, use default values + // for the rest of the HubCriteria fields + if ($hub_filter_enabled == 'true') { - // if true, set other values for HubCriteria - // TODO: set this properly, since the other flags - // are on default values - error_log('Area is covered by hub filtering'); - $hub_criteria->setJoType($jo->getServiceType()) - ->setPaymentMethod($jo->getModeOfPayment()) - ->setRoundRobin(true); + error_log('hub filter is enabled'); + // check if customer location is in hub filter area + if ($hub_geofence->isCovered($long, $lat)) + { + // if true, set other values for HubCriteria + // TODO: set this properly, since the other flags + // are on default values + error_log('Area is covered by hub filtering'); + $hub_criteria->setJoType($jo->getServiceType()) + ->setPaymentMethod($jo->getModeOfPayment()) + ->setRoundRobin(true); + } } // add battery to items diff --git a/src/Service/HubFilteringGeoChecker.php b/src/Service/HubFilteringGeoChecker.php index b23d3ecb..8db7ac66 100644 --- a/src/Service/HubFilteringGeoChecker.php +++ b/src/Service/HubFilteringGeoChecker.php @@ -21,10 +21,6 @@ class HubFilteringGeoChecker public function isCovered($long, $lat) { - // TODO: remove this - // NOTE: this is a temporary fix to disable hub filtering altogether - return false; - // check if geofence is enabled if ($this->geofence_flag == 'true') { diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 5a8ea914..c86ac1e1 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -81,6 +81,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface protected $hub_dist; protected $hub_geofence; protected $cust_distance_limit; + protected $hub_filter_enable; protected $template_hash; @@ -89,7 +90,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, string $country_code, WarrantyHandler $wh, RisingTideGateway $rt, PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence, - string $cust_distance_limit) + string $cust_distance_limit, string $hub_filter_enabled) { $this->em = $em; $this->ic = $ic; @@ -104,6 +105,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $this->hub_dist = $hub_dist; $this->hub_geofence = $hub_geofence; $this->cust_distance_limit = $cust_distance_limit; + $this->hub_filter_enabled = $hub_filter_enabled; $this->loadTemplates(); } @@ -1986,14 +1988,20 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $hub_criteria->setPoint($obj->getCoordinates()) ->setLimitResults(50); - if ($this->hub_geofence->isCovered($long, $lat)) + // check if hub filter is enabled. If not, use default values + // for the rest of the HubCriteria fields + if ($this->hub_filter_enabled == 'true') { - // if true, set other values for HubCriteria - error_log('Area is covered by hub filtering'); - $hub_criteria->setLimitDistance($this->cust_distance_limit) - ->setPaymentMethod($obj->getModeOfPayment()) - ->setJoType($obj->getServiceType()) - ->setRoundRobin(true); + error_log('hub filter is enabled'); + if ($this->hub_geofence->isCovered($long, $lat)) + { + // if true, set other values for HubCriteria + error_log('Area is covered by hub filtering'); + $hub_criteria->setLimitDistance($this->cust_distance_limit) + ->setPaymentMethod($obj->getModeOfPayment()) + ->setJoType($obj->getServiceType()) + ->setRoundRobin(true); + } } // check if emergency or not