Move requested params to filters instead of hub selector #800

This commit is contained in:
Ramon Gutierrez 2024-06-26 09:59:29 +08:00
parent 3b287236ec
commit a21ed66490
9 changed files with 81 additions and 36 deletions

View file

@ -9,6 +9,13 @@ class DateAndTimeHubFilter extends BaseHubFilter implements HubFilterInterface
{
protected $id = 'date_and_time';
public function getRequestedParams() : array
{
return [
'date_time',
];
}
public function filter(array $hubs, array $params = []) : array
{
if ($params['date_time'] == null)

View file

@ -27,6 +27,18 @@ class InventoryHubFilter extends BaseHubFilter implements HubFilterInterface
$this->im = $im;
}
public function getRequestedParams() : array
{
return [
'flag_inventory_check',
'customer_class',
'jo_type',
'order_date',
'service_type',
'items',
];
}
public function filter(array $hubs, array $params = []) : array
{
// check if this is enabled

View file

@ -9,6 +9,14 @@ class JoTypeHubFilter extends BaseHubFilter implements HubFilterInterface
{
protected $id = 'job_order_type';
public function getRequestedParams() : array
{
return [
'flag_emergency',
'jo_type',
];
}
public function filter(array $hubs, array $params = []) : array
{
if ($params['flag_emergency'])

View file

@ -9,6 +9,13 @@ class MaxResultsHubFilter extends BaseHubFilter implements HubFilterInterface
{
protected $id = 'max_results';
public function getRequestedParams() : array
{
return [
'limit_results',
];
}
public function filter(array $hubs, array $params = []) : array
{
if (empty($params['limit_results']))

View file

@ -9,6 +9,14 @@ class PaymentMethodHubFilter extends BaseHubFilter implements HubFilterInterface
{
protected $id = 'no_payment_method';
public function getRequestedParams() : array
{
return [
'flag_emergency',
'payment_method',
];
}
public function filter(array $hubs, array $params = []) : array
{
if ($params['flag_emergency'])

View file

@ -12,6 +12,16 @@ class RiderAvailabilityHubFilter extends BaseHubFilter implements HubFilterInter
{
protected $id = 'no_available_rider';
public function getRequestedParams() : array
{
return [
'flag_riders_check',
'customer_class',
'order_date',
'service_type',
];
}
public function filter(array $hubs, array $params = []) : array
{
// check if this is enabled

View file

@ -23,6 +23,13 @@ class RoundRobinHubFilter extends BaseHubFilter implements HubFilterInterface
$this->hub_distributor = $hub_distributor;
}
public function getRequestedParams() : array
{
return [
'flag_round_robin',
];
}
public function filter(array $hubs, array $params = []) : array
{
if (!$params['flag_round_robin'])

View file

@ -10,9 +10,11 @@ interface HubFilterInterface
public function setJOID(int $jo_id);
public function getJOID(): int;
public function getJOID() : int;
public function setCustomerID(int $customer_id);
public function getCustomerID(): int;
public function getCustomerID() : int;
public function getRequestedParams() : array;
}

View file

@ -81,40 +81,20 @@ 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
// build param list
$params = [
'date_and_time' => [
'date_time' => $date_time,
],
'no_inventory' => [
'flag_inventory_check' => $flag_inventory_check,
'customer_class' => $customer_class,
'jo_type' => $jo_type,
'order_date' => $order_date,
'service_type' => $service_type,
'items' => $items,
],
'job_order_type' => [
'flag_emergency' => $flag_emergency,
'jo_type' => $jo_type,
],
'max_results' => [
'limit_results' => $limit_results,
],
'no_payment_method' => [
'flag_emergency' => $flag_emergency,
'payment_method' => $payment_method,
],
'no_available_rider' => [
'flag_riders_check' => $flag_riders_check,
'customer_class' => $customer_class,
'order_date' => $order_date,
'service_type' => $service_type,
],
'round_robin' => [
'flag_round_robin' => $flag_round_robin,
],
'date_time' => $date_time,
'flag_inventory_check' => $flag_inventory_check,
'customer_class' => $customer_class,
'jo_type' => $jo_type,
'order_date' => $order_date,
'service_type' => $service_type,
'items' => $items,
'flag_emergency' => $flag_emergency,
'limit_results' => $limit_results,
'payment_method' => $payment_method,
'flag_riders_check' => $flag_riders_check,
'flag_round_robin' => $flag_round_robin,
];
// loop through all enabled filters
@ -129,7 +109,11 @@ class HubSelector
$f->setJOID($jo_id);
$f->setCustomerID($customer_id);
$filtered_hubs = $f->filter($filtered_hubs, $params[$f->getID()]);
// get requested params only
$req_params = array_intersect_key($params, array_flip($f->getRequestedParams()));
// filter hub list
$filtered_hubs = $f->filter($filtered_hubs, $req_params);
// error_log($f->getID() . ' hubs ' . json_encode($filtered_hubs));
}