Add regional filter support for hub filters #800
This commit is contained in:
parent
204c039fba
commit
3b287236ec
2 changed files with 37 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
2
utils/hub_filter_exceptions/hub_filter_exceptions.sql
Normal file
2
utils/hub_filter_exceptions/hub_filter_exceptions.sql
Normal file
|
|
@ -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;
|
||||
Loading…
Reference in a new issue