From 5b4fd8e47f3f14e92e3a49ba30e737723f6a8e6a Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Tue, 31 Mar 2015 13:31:08 +0300
Subject: [PATCH] Added support for specifying priorities for Voyager item
 statuses so that the most important status can be displayed in holdings.

---
 config/vufind/Voyager.ini                     | 22 +++++++---
 config/vufind/VoyagerRestful.ini              | 44 ++++++++++++-------
 .../VuFind/src/VuFind/ILS/Driver/Voyager.php  |  6 +++
 3 files changed, 49 insertions(+), 23 deletions(-)

diff --git a/config/vufind/Voyager.ini b/config/vufind/Voyager.ini
index 614d0ee0f21..6ec0d37115f 100644
--- a/config/vufind/Voyager.ini
+++ b/config/vufind/Voyager.ini
@@ -16,9 +16,9 @@ connect_with_sid = false
 ; recommended values are LAST_NAME or PATRON_PIN (LAST_NAME is default)
 login_field = LAST_NAME
 
-; If using PATRON_PIN as login_field, allow fallback to another field if the 
+; If using PATRON_PIN as login_field, allow fallback to another field if the
 ; user has no PIN code. Disabled by default.
-;fallback_login_field = LAST_NAME  
+;fallback_login_field = LAST_NAME
 
 ; These settings affect the Fund list used as a limiter in the "new items" module:
 [Funds]
@@ -38,7 +38,7 @@ login_field = LAST_NAME
 ;blacklist[] = "Second Bad Value"
 
 ; This setting can be used to limit the fund list to those that are under a specific
-; fund.  Set it to 0 for top-level funds only.  Set it to a FUND_ID deeper in the 
+; fund.  Set it to 0 for top-level funds only.  Set it to a FUND_ID deeper in the
 ; fund tree to filter out unwanted values.  Leave it commented out to get all funds.
 ;parent_fund = 0
 
@@ -47,8 +47,8 @@ login_field = LAST_NAME
 ; How purchase history is displayed. Supported values are:
 ; 1) false - Purchase history is not displayed at all.
 ; 2) true - Purchase history is displayed below other holdings (default)
-; 3) "split" - Purchase history is split to each corresponding holdings record and 
-; displayed by location 
+; 3) "split" - Purchase history is split to each corresponding holdings record and
+; displayed by location
 ;purchase_history = true
 ; Fields to include in notes. Default is "852z".
 ;notes = "845a:852az"
@@ -62,7 +62,17 @@ login_field = LAST_NAME
 ; line to disable sorting.
 ;use_sort_groups = false
 
+; Status rankings can be used to either promote or demote certain item statuses when
+; determining the status to be displayed. The lower the rank, the higher the
+; priority. The sample values below make "Missing" most important and drop request
+; statuses below others so that e.g. "On Hold" is displayed instead of
+; "Hold Request".
+[StatusRankings]
+;Missing = 0
+;Recall Request = 99
+;Hold Request = 99
+
 ; Settings for controlling how loans are displayed
 [Loans]
 ; Uncomment this line to display the location where each loan was made
-;display_borrowing_location = true
\ No newline at end of file
+;display_borrowing_location = true
diff --git a/config/vufind/VoyagerRestful.ini b/config/vufind/VoyagerRestful.ini
index f780eeb379c..492142e9fb8 100644
--- a/config/vufind/VoyagerRestful.ini
+++ b/config/vufind/VoyagerRestful.ini
@@ -16,9 +16,9 @@ connect_with_sid = false
 ; recommended values are LAST_NAME or PATRON_PIN (LAST_NAME is default)
 login_field = LAST_NAME
 
-; If using PATRON_PIN as login_field, allow fallback to another field if the 
+; If using PATRON_PIN as login_field, allow fallback to another field if the
 ; user has no PIN code. Disabled by default.
-;fallback_login_field = LAST_NAME  
+;fallback_login_field = LAST_NAME
 
 ; This is the timeout value for making HTTP requests to the Voyager API.
 http_timeout = 30
@@ -41,7 +41,7 @@ http_timeout = 30
 ;blacklist[] = "Second Bad Value"
 
 ; This setting can be used to limit the fund list to those that are under a specific
-; fund.  Set it to 0 for top-level funds only.  Set it to a FUND_ID deeper in the 
+; fund.  Set it to 0 for top-level funds only.  Set it to a FUND_ID deeper in the
 ; fund tree to filter out unwanted values.  Leave it commented out to get all funds.
 ;parent_fund = 0
 
@@ -96,19 +96,19 @@ HMACKeys = item_id:holdtype:level
 defaultRequiredDate = 0:1:0
 
 ; extraHoldFields - A colon-separated list used to display extra visible fields in the
-; place holds form. Supported values are "comments", "requiredByDate", 
+; place holds form. Supported values are "comments", "requiredByDate",
 ; "pickUpLocation" and "requestGroup"
 extraHoldFields = comments:requiredByDate:pickUpLocation
 
 ; A Pick Up Location Code used to pre-select the pick up location drop down list and
-; provide a default option if others are not available. Must be one of the following: 
+; provide a default option if others are not available. Must be one of the following:
 ; 1) empty string to indicate that the first location is default (default setting)
 ; 2) "user-selected" to indicate that the user always has to choose the location
 ; 3) a value within the Location IDs returned by getPickUpLocations()
 defaultPickUpLocation = ""
 
 ; 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 
+; 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
 ; link. Use "0" to check all items via ajax. Default is 15.
 holdCheckLimit = 15
@@ -129,7 +129,7 @@ holdCheckLimit = 15
 ;defaultRequestGroup = ""
 
 ; By default the request group list is sorted alphabetically. This setting can be
-; used to manually set the order by entering request group IDs as a colon-separated 
+; used to manually set the order by entering request group IDs as a colon-separated
 ; list.
 ; This setting is only effective if requestGroup is specified in extraHoldFields.
 ;requestGroupOrder = 33
@@ -141,11 +141,11 @@ holdCheckLimit = 15
 ;pickupLocationsInRequestGroup = true
 
 ; By default a title hold can be placed even when there are no items. Uncomment this
-; to prevent holds if no items exist. If request groups are enabled, item existence 
+; to prevent holds if no items exist. If request groups are enabled, item existence
 ; is checked only in the selected request group.
 ;checkItemsExist = true
 
-; By default a title hold can be placed even when there are items available. 
+; By default a title hold can be placed even when there are items available.
 ; Uncomment this to prevent holds if items are available. If request groups are
 ; enabled, availability is checked only in the selected request group.
 ;checkItemsNotAvailable = true
@@ -156,7 +156,7 @@ holdCheckLimit = 15
 ; This setting is only effective if requestGroup is specified in extraHoldFields.
 disableAvailabilityCheckForRequestGroups = "15:19:21:32"
 
-; A colon-separated list of ids from the LOCATION table. If provided, items with a 
+; A colon-separated list of ids from the LOCATION table. If provided, items with a
 ; matching location are excluded from item availability.
 ;excludedItemLocations = "2:4:23:10"
 
@@ -170,7 +170,7 @@ disableAvailabilityCheckForRequestGroups = "15:19:21:32"
 ;helpText[en-gb] = "Help text for English language."
 
 
-; This section controls call slip behavior (storage retrieval requests in VuFind). 
+; This section controls call slip behavior (storage retrieval requests in VuFind).
 ; To enable, uncomment (at minimum) the HMACKeys and extraFields settings below.
 [StorageRetrievalRequests]
 ; Colon-separated list of item types where call slip is allowed
@@ -195,7 +195,7 @@ disableAvailabilityCheckForRequestGroups = "15:19:21:32"
 ;helpText = "Help text for all languages."
 ;helpText[en-gb] = "Help text for English language."
 
-; This section controls UB (Universal Borrowing, ILL in VuFind) behavior. To enable, 
+; This section controls UB (Universal Borrowing, ILL in VuFind) behavior. To enable,
 ; uncomment (at minimum) the HMACKeys and extraFields settings below. See also
 ; section ILLRequestSources for mapping between patron ID's and UB libraries.
 [ILLRequests]
@@ -204,7 +204,7 @@ disableAvailabilityCheckForRequestGroups = "15:19:21:32"
 ;HMACKeys = item_id:holdings_id
 
 ; extraFields - A colon-separated list used to display extra visible fields in the
-; request form. Supported values are "pickUpLibrary", 
+; request form. Supported values are "pickUpLibrary",
 ; "pickUpLibraryLocation", "requiredByDate" and "comments" (although comments are
 ; not properly stored for UB requests at least in version 8.1)
 ;extraFields = pickUpLibrary:pickUpLibraryLocation:requiredByDate
@@ -220,7 +220,7 @@ disableAvailabilityCheckForRequestGroups = "15:19:21:32"
 
 ; This section lists the valid patron id prefixes for UB (ILL in VuFind) requests,
 ; and maps them to the their Voyager UB library IDs. Any patron of another library
-; with a prefix listed here may attempt a UB request in this system. 
+; with a prefix listed here may attempt a UB request in this system.
 [ILLRequestSources]
 ;devdb = "1@DEVDB20011102161616"
 ;otherdb = "1@OTHERDB20011030191919"
@@ -230,8 +230,8 @@ disableAvailabilityCheckForRequestGroups = "15:19:21:32"
 ; How purchase history is displayed. Supported values are:
 ; 1) false - Purchase history is not displayed at all.
 ; 2) true - Purchase history is displayed below other holdings (default)
-; 3) "split" - Purchase history is split to each corresponding holdings record and 
-; displayed by location 
+; 3) "split" - Purchase history is split to each corresponding holdings record and
+; displayed by location
 ;purchase_history = true
 ; Fields to include in notes. Default is "852z".
 ;notes = "845a:852az"
@@ -245,12 +245,22 @@ disableAvailabilityCheckForRequestGroups = "15:19:21:32"
 ; line to disable sorting.
 ;use_sort_groups = false
 
+; Status rankings can be used to either promote or demote certain item statuses when
+; determining the status to be displayed. The lower the rank, the higher the
+; priority. The sample values below make "Missing" most important and drop request
+; statuses below others so that e.g. "On Hold" is displayed instead of
+; "Hold Request".
+[StatusRankings]
+;Missing = 0
+;Recall Request = 99
+;Hold Request = 99
+
 ; Settings for controlling how loans are displayed
 [Loans]
 ; Uncomment this line to display the location where each loan was made
 ;display_borrowing_location = true
 
-; Uncomment the following lines to enable password (PIN) change 
+; Uncomment the following lines to enable password (PIN) change
 ;[changePassword]
 ; PIN change parameters. The default limits are taken from the interface documentation.
 ;minLength = 5
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
index 438b73a70d3..1d69818251d 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
@@ -250,6 +250,12 @@ class Voyager extends AbstractBase
                 $this->statusRankings[$row['ITEM_STATUS_DESC']]
                     = $row['ITEM_STATUS_TYPE'];
             }
+
+            if (!empty($this->config['StatusRankings'])) {
+                $this->statusRankings = array_merge(
+                    $this->statusRankings, $this->config['StatusRankings']
+                );
+            }
         }
 
         // We may occasionally get a status message not found in the array (i.e. the
-- 
GitLab