From 9e36d1c0e8ea1b4d3ce7f29ee000cf680014516d Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Wed, 18 Oct 2017 21:07:28 +0300
Subject: [PATCH] Voyager: add option to only display time part of due date for
 short loans. (#1047)

---
 config/vufind/Voyager.ini                     |  5 ++++
 config/vufind/VoyagerRestful.ini              |  5 ++++
 .../VuFind/src/VuFind/ILS/Driver/Voyager.php  | 23 +++++++++++++++++--
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/config/vufind/Voyager.ini b/config/vufind/Voyager.ini
index c911a165470..fac3b6b4c09 100644
--- a/config/vufind/Voyager.ini
+++ b/config/vufind/Voyager.ini
@@ -91,6 +91,11 @@ login_field = LAST_NAME
 ; Uncomment this line to display the location where each loan was made
 ;display_borrowing_location = true
 
+; Colon-separated list of loan intervals for which to display the time part of the
+; due date. By default the time is always displayed. Normal interval types are
+; H (hours), D (days) and T (term).
+;display_due_time_only_for_intervals = H:D
+
 ; This regular expression controls which status messages are displayed on the
 ; Checked Out Items list.
 show_statuses = "/lost|missing|claim/i"
diff --git a/config/vufind/VoyagerRestful.ini b/config/vufind/VoyagerRestful.ini
index 06beb4dc90b..ea1727d1488 100644
--- a/config/vufind/VoyagerRestful.ini
+++ b/config/vufind/VoyagerRestful.ini
@@ -299,6 +299,11 @@ disableAvailabilityCheckForRequestGroups = "15:19:21:32"
 ; Uncomment this line to display the location where each loan was made
 ;display_borrowing_location = true
 
+; Colon-separated list of loan intervals for which to display the time part of the
+; due date. By default the time is always displayed. Normal interval types are
+; H (hours), D (days) and T (term).
+;display_due_time_only_for_intervals = H:D
+
 ; This regular expression controls which status messages are displayed on the
 ; Checked Out Items list.
 show_statuses = "/lost|missing|claim/i"
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
index 4f915b74135..def6f4d681b 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
@@ -90,6 +90,13 @@ class Voyager extends AbstractBase
      */
     protected $useHoldingsSortGroups;
 
+    /**
+     * Loan interval types for which to display the due time (empty = all)
+     *
+     * @var array
+     */
+    protected $displayDueTimeIntervals;
+
     /**
      * Constructor
      *
@@ -141,6 +148,12 @@ class Voyager extends AbstractBase
         $this->useHoldingsSortGroups
             = isset($this->config['Holdings']['use_sort_groups'])
             ? $this->config['Holdings']['use_sort_groups'] : true;
+
+        $this->displayDueTimeIntervals
+            = isset($this->config['Loans']['display_due_time_only_for_intervals'])
+            ? explode(
+                ':', $this->config['Loans']['display_due_time_only_for_intervals']
+            ) : [];
     }
 
     /**
@@ -1310,7 +1323,8 @@ EOT;
             . "WITHIN GROUP (ORDER BY ITEM_STATUS_DESC) as status",
             "MAX(CIRC_TRANSACTIONS.RENEWAL_COUNT) AS RENEWAL_COUNT",
             "MAX(CIRC_POLICY_MATRIX.RENEWAL_COUNT) as RENEWAL_LIMIT",
-            "MAX(LOCATION.LOCATION_DISPLAY_NAME) as BORROWING_LOCATION"
+            "MAX(LOCATION.LOCATION_DISPLAY_NAME) as BORROWING_LOCATION",
+            "MAX(CIRC_POLICY_MATRIX.LOAN_INTERVAL) as LOAN_INTERVAL"
         ];
 
         // From
@@ -1420,7 +1434,6 @@ EOT;
             'id' => $sqlRow['BIB_ID'],
             'item_id' => $sqlRow['ITEM_ID'],
             'duedate' => $dueDate,
-            'dueTime' => $dueTime,
             'dueStatus' => $dueStatus,
             'volume' => str_replace("v.", "", utf8_encode($sqlRow['ITEM_ENUM'])),
             'publication_year' => $sqlRow['YEAR'],
@@ -1431,6 +1444,12 @@ EOT;
             'message' =>
                 $this->pickTransactionStatus(explode(chr(9), $sqlRow['STATUS'])),
         ];
+        // Display due time only if loan interval is not in days if configured
+        if (empty($this->displayDueTimeIntervals)
+            || in_array($sqlRow['LOAN_INTERVAL'], $this->displayDueTimeIntervals)
+        ) {
+            $transaction['dueTime'] = $dueTime;
+        }
         if (isset($this->config['Loans']['display_borrowing_location'])
             && $this->config['Loans']['display_borrowing_location']
         ) {
-- 
GitLab