From b81f5c3f741108955b522ed285b1253dace5e1ba Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Wed, 18 Oct 2017 21:26:59 +0300
Subject: [PATCH] Allow (optional) barcode display in checked out list (#1051)

- Also includes addition of barcode support to SierraRest and Voyager drivers.
---
 config/vufind/config.ini                               |  3 +++
 languages/en.ini                                       |  1 +
 languages/fi.ini                                       |  1 +
 languages/sv.ini                                       |  1 +
 .../src/VuFind/Controller/MyResearchController.php     |  5 ++++-
 module/VuFind/src/VuFind/ILS/Driver/SierraRest.php     |  3 ++-
 module/VuFind/src/VuFind/ILS/Driver/Voyager.php        | 10 +++++++---
 .../bootstrap3/templates/myresearch/checkedout.phtml   |  4 ++++
 8 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/config/vufind/config.ini b/config/vufind/config.ini
index 3197dc2f057..433914987ff 100644
--- a/config/vufind/config.ini
+++ b/config/vufind/config.ini
@@ -300,6 +300,9 @@ title_level_holds_mode = "disabled"
 ; memory problems for users with huge numbers of items). Default = 50.
 ;checked_out_page_size = 50
 
+; Whether to display the item barcode for each loan. Default is false.
+;display_checked_out_item_barcode = true
+
 ; This section allows you to determine how the users will authenticate.
 ; You can use an LDAP directory, the local ILS (or multiple ILSes through
 ; the MultiILS option), the VuFind database (Database), Shibboleth, SIP2,
diff --git a/languages/en.ini b/languages/en.ini
index fb5fadb133f..ce747a8b8da 100644
--- a/languages/en.ini
+++ b/languages/en.ini
@@ -93,6 +93,7 @@ Back to Search Results = "Back to Search Results"
 Backtrace = "Backtrace"
 Bag = "Bag"
 Balance = "Balance"
+Barcode = "Barcode"
 basic_search_keep_filters = "Retain current filters"
 Be the first to leave a comment = "Be the first to leave a comment"
 Be the first to tag this record = "Be the first to tag this record"
diff --git a/languages/fi.ini b/languages/fi.ini
index f5855eeab32..e0d332f2b9b 100644
--- a/languages/fi.ini
+++ b/languages/fi.ini
@@ -92,6 +92,7 @@ Back to Search Results = "Takaisin hakutuloksiin"
 Backtrace = "Kutsupino"
 Bag = "Kori"
 Balance = "Maksettavaa"
+Barcode = "Viivakoodi"
 basic_search_keep_filters = "Säilytä käytössä oleva rajaus"
 Be the first to leave a comment = "Lisää ensimmäinen kommentti"
 Be the first to tag this record = "Lisää ensimmäinen tagi"
diff --git a/languages/sv.ini b/languages/sv.ini
index ad1a1de0bc5..4fb42fb7113 100644
--- a/languages/sv.ini
+++ b/languages/sv.ini
@@ -92,6 +92,7 @@ Back to Search Results = "Tillbaka till sökresultaten"
 Backtrace = "Anropsstacken"
 Bag = "Korg"
 Balance = "Att betala"
+Barcode = "Streckkod"
 basic_search_keep_filters = "Spara filtreringen i bruk"
 Be the first to leave a comment = "Lägg till första kommentaren"
 Be the first to tag this record = "Lägg till första taggen"
diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php
index ad6ff2e4018..e36635dd25c 100644
--- a/module/VuFind/src/VuFind/Controller/MyResearchController.php
+++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php
@@ -1200,10 +1200,13 @@ class MyResearchController extends AbstractBase
             }
         }
 
+        $displayItemBarcode
+            = !empty($config->Catalog->display_checked_out_item_barcode);
+
         return $this->createViewModel(
             compact(
                 'transactions', 'renewForm', 'renewResult', 'paginator',
-                'hiddenTransactions'
+                'hiddenTransactions', 'displayItemBarcode'
             )
         );
     }
diff --git a/module/VuFind/src/VuFind/ILS/Driver/SierraRest.php b/module/VuFind/src/VuFind/ILS/Driver/SierraRest.php
index cd9c9fcc7fb..7fe5955de65 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/SierraRest.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/SierraRest.php
@@ -505,7 +505,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
                 'limit' => 10000,
                 'offset' => 0,
                 'fields' => 'item,dueDate,numberOfRenewals,outDate,recallDate'
-                    . ',callNumber'
+                    . ',callNumber,barcode'
             ],
             'GET',
             $patron
@@ -519,6 +519,7 @@ class SierraRest extends AbstractBase implements TranslatorAwareInterface,
                 'id' => '',
                 'checkout_id' => $this->extractId($entry['id']),
                 'item_id' => $this->extractId($entry['item']),
+                'barcode' => $entry['barcode'],
                 'duedate' => $this->dateConverter->convertToDisplayDate(
                     'Y-m-d', $entry['dueDate']
                 ),
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
index 0ad30c1379c..1f1eb622a2c 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
@@ -1317,6 +1317,7 @@ EOT;
             "MAX(CIRC_TRANSACTIONS.ITEM_ID) as ITEM_ID",
             "MAX(MFHD_ITEM.ITEM_ENUM) AS ITEM_ENUM",
             "MAX(MFHD_ITEM.YEAR) AS YEAR",
+            "MAX(ITEM_BARCODE.ITEM_BARCODE) AS ITEM_BARCODE",
             "MAX(BIB_TEXT.TITLE_BRIEF) AS TITLE_BRIEF",
             "MAX(BIB_TEXT.TITLE) AS TITLE",
             "LISTAGG(ITEM_STATUS_DESC, CHR(9)) "
@@ -1334,6 +1335,7 @@ EOT;
             $this->dbName . ".ITEM",
             $this->dbName . ".ITEM_STATUS",
             $this->dbName . ".ITEM_STATUS_TYPE",
+            $this->dbName . ".ITEM_BARCODE",
             $this->dbName . ".MFHD_ITEM",
             $this->dbName . ".BIB_TEXT",
             $this->dbName . ".CIRC_POLICY_MATRIX",
@@ -1352,6 +1354,9 @@ EOT;
             "BIB_ITEM.ITEM_ID = ITEM.ITEM_ID",
             "ITEM.ITEM_ID = ITEM_STATUS.ITEM_ID",
             "ITEM_STATUS.ITEM_STATUS = ITEM_STATUS_TYPE.ITEM_STATUS_TYPE",
+            "ITEM.ITEM_ID = ITEM_BARCODE.ITEM_ID(+)",
+            "ITEM_BARCODE.BARCODE_STATUS IN (SELECT BARCODE_STATUS_TYPE FROM " .
+            "$this->dbName.ITEM_BARCODE_STATUS WHERE BARCODE_STATUS_DESC = 'Active')"
         ];
 
         // Order
@@ -1433,6 +1438,7 @@ EOT;
         $transaction = [
             'id' => $sqlRow['BIB_ID'],
             'item_id' => $sqlRow['ITEM_ID'],
+            'barcode' => utf8_encode($sqlRow['ITEM_BARCODE']),
             'duedate' => $dueDate,
             'dueStatus' => $dueStatus,
             'volume' => str_replace("v.", "", utf8_encode($sqlRow['ITEM_ENUM'])),
@@ -1450,9 +1456,7 @@ EOT;
         ) {
             $transaction['dueTime'] = $dueTime;
         }
-        if (isset($this->config['Loans']['display_borrowing_location'])
-            && $this->config['Loans']['display_borrowing_location']
-        ) {
+        if (!empty($this->config['Loans']['display_borrowing_location'])) {
             $transaction['borrowingLocation']
                 = utf8_encode($sqlRow['BORROWING_LOCATION']);
         }
diff --git a/themes/bootstrap3/templates/myresearch/checkedout.phtml b/themes/bootstrap3/templates/myresearch/checkedout.phtml
index 87f4bdf714d..61f7dc094f2 100644
--- a/themes/bootstrap3/templates/myresearch/checkedout.phtml
+++ b/themes/bootstrap3/templates/myresearch/checkedout.phtml
@@ -124,6 +124,10 @@
               <strong><?=$this->transEsc('Year of Publication')?>:</strong> <?=$this->escapeHtml($ilsDetails['publication_year'])?>
               <br />
             <? endif; ?>
+            <? if ($this->displayItemBarcode && !empty($ilsDetails['barcode'])): ?>
+              <strong><?=$this->transEsc('Barcode')?>:</strong> <?=$this->escapeHtml($ilsDetails['barcode'])?>
+              <br />
+            <? endif; ?>
 
             <? if (!empty($ilsDetails['institution_name']) && (empty($ilsDetails['borrowingLocation']) || $ilsDetails['institution_name'] != $ilsDetails['borrowingLocation'])): ?>
               <strong><?=$this->transEsc('location_' . $ilsDetails['institution_name'], [], $ilsDetails['institution_name'])?></strong>
-- 
GitLab