diff --git a/src/Service/HubSelector.php b/src/Service/HubSelector.php index 8de3c718..929d7bf5 100644 --- a/src/Service/HubSelector.php +++ b/src/Service/HubSelector.php @@ -80,7 +80,7 @@ class HubSelector // get all the hubs within distance $filtered_hubs = $this->getClosestHubs($point, $limit_distance, $jo_id, $customer_id); - + // gather all params in one array // TODO: figure out a better way to do this where we don't have to specify the filter names here $params = [ @@ -120,6 +120,12 @@ class HubSelector // loop through all enabled filters foreach ($this->getActiveFilters() as $hub_filter) { $f = $this->container->get($hub_filter); + + // check if supported area is exempted from this filter + if ($this->isExemptedByArea($f->getID(), $point)) { + continue; + } + $f->setJOID($jo_id); $f->setCustomerID($customer_id); @@ -197,5 +203,33 @@ class HubSelector return round(($miles * 1.609344), 1); } + + protected function isExemptedByArea(string $filter_id, Point $coordinates): bool + { + $long = $coordinates->getLongitude(); + $lat = $coordinates->getLatitude(); + + // get supported area given a set of coordinates + $query = $this->em->createQuery('SELECT s from App\Entity\SupportedArea s where st_contains(s.coverage_area, point(:long, :lat)) = true'); + $area = $query->setParameter('long', $long) + ->setParameter('lat', $lat) + ->setMaxResults(1) + ->getOneOrNullResult(); + + if ($area !== null) { + // get all exceptions + $exceptions = $area->getHubFilterExceptions(); + + if (isset($exceptions[$filter_id])) { + error_log("FILTER " . $filter_id . " DISABLED FOR AREA: " . $area->getName()); + + // disable this filter for this area + return true; + } + } + + // filter is in place + return false; + } } diff --git a/utils/hub_filter_exceptions/hub_filter_exceptions.sql b/utils/hub_filter_exceptions/hub_filter_exceptions.sql new file mode 100644 index 00000000..ef165614 --- /dev/null +++ b/utils/hub_filter_exceptions/hub_filter_exceptions.sql @@ -0,0 +1,2 @@ +update supported_area set hub_filter_exceptions = '{"no_inventory":true,"no_available_rider":true}' where id = 34; +update supported_area set hub_filter_exceptions = '{"no_inventory":true,"no_available_rider":true}' where id = 35; \ No newline at end of file