Skip to content
Snippets Groups Projects
Commit bbdc075c authored by Ere Maijala's avatar Ere Maijala Committed by Demian Katz
Browse files

Improvements to Voyager pickup location display order

- Sort Voyager pickup locations alphabetically by default
- Make it possible to define or refine the order in the ini file.
parent f7597067
No related merge requests found
......@@ -107,6 +107,11 @@ extraHoldFields = comments:requiredByDate:pickUpLocation
; 3) a value within the Location IDs returned by getPickUpLocations()
defaultPickUpLocation = ""
; By default the pick up location list is sorted alphabetically. This setting can be
; used to manually set the order by entering location IDs as a colon-separated list.
; You can also disable sorting by setting this to false.
;pickUpLocationOrder = 158:155
; The maximum number of holding items to generate request links for. The process of
; checking the API for a valid hold is intensive. Any hold items above this this
; limit will have their hold status checked via ajax or when a user clicks on the
......
......@@ -770,6 +770,32 @@ class VoyagerRestful extends Voyager implements \VuFindHttp\HttpServiceAwareInte
];
}
}
// Do we need to sort pickup locations? If the setting is false, don't
// bother doing any more work. If it's not set at all, default to
// alphabetical order.
$orderSetting = isset($this->config['Holds']['pickUpLocationOrder'])
? $this->config['Holds']['pickUpLocationOrder'] : 'default';
if (count($pickResponse) > 1 && !empty($orderSetting)) {
$locationOrder = $orderSetting === 'default'
? [] : array_flip(explode(':', $orderSetting));
$sortFunction = function ($a, $b) use ($locationOrder) {
$aLoc = $a['locationID'];
$bLoc = $b['locationID'];
if (isset($locationOrder[$aLoc])) {
if (isset($locationOrder[$bLoc])) {
return $locationOrder[$aLoc] - $locationOrder[$bLoc];
}
return -1;
}
if (isset($locationOrder[$bLoc])) {
return 1;
}
return strcasecmp($a['locationDisplay'], $b['locationDisplay']);
};
usort($pickResponse, $sortFunction);
}
return $pickResponse;
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment