From ae4b3b43b6275c6adb5b7c692223f172fa60ef34 Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Wed, 6 Aug 2014 09:25:54 -0400
Subject: [PATCH] Added support for displaying the borrowing location for
 loans.

---
 config/vufind/Voyager.ini                     |  5 +++++
 config/vufind/VoyagerRestful.ini              |  5 +++++
 languages/en.ini                              |  1 +
 languages/fi.ini                              |  1 +
 languages/sv.ini                              |  1 +
 module/VuFind/src/VuFind/ILS/Driver/Demo.php  |  6 ++++--
 .../VuFind/src/VuFind/ILS/Driver/Voyager.php  | 19 +++++++++++++++----
 .../templates/myresearch/checkedout.phtml     | 15 ++++++++++-----
 .../templates/myresearch/checkedout.phtml     | 17 +++++++++++------
 .../templates/myresearch/checkedout.phtml     | 15 ++++++++++-----
 .../templates/myresearch/checkedout.phtml     | 11 ++++++++---
 .../templates/myresearch/checkedout.phtml     | 11 ++++++++---
 12 files changed, 79 insertions(+), 28 deletions(-)

diff --git a/config/vufind/Voyager.ini b/config/vufind/Voyager.ini
index 4ea47826204..614d0ee0f21 100644
--- a/config/vufind/Voyager.ini
+++ b/config/vufind/Voyager.ini
@@ -61,3 +61,8 @@ login_field = LAST_NAME
 ; By default holdings are sorted by Voyager's Holdings Sort Groups. Uncomment this
 ; line to disable sorting.
 ;use_sort_groups = false
+
+; 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
diff --git a/config/vufind/VoyagerRestful.ini b/config/vufind/VoyagerRestful.ini
index 8a0157980f3..9981b9acde5 100644
--- a/config/vufind/VoyagerRestful.ini
+++ b/config/vufind/VoyagerRestful.ini
@@ -244,3 +244,8 @@ disableAvailabilityCheckForRequestGroups = "15:19:21:32"
 ; By default holdings are sorted by Voyager's Holdings Sort Groups. Uncomment this
 ; line to disable sorting.
 ;use_sort_groups = false
+
+; Settings for controlling how loans are displayed
+[Loans]
+; Uncomment this line to display the location where each loan was made
+;display_borrowing_location = true
diff --git a/languages/en.ini b/languages/en.ini
index 1793c09c97d..f4225c2c8a8 100644
--- a/languages/en.ini
+++ b/languages/en.ini
@@ -104,6 +104,7 @@ bookbag_save = "Save Selected Book Bag Items"
 bookbag_save_selected  = "Save Selected"
 Bookmark = Bookmark
 Books = Books
+Borrowing Location = "Borrowing Location"
 Braille = Braille
 Brief View = "Brief View"
 Browse = Browse
diff --git a/languages/fi.ini b/languages/fi.ini
index ca7e1c73ba5..b56bf740cdf 100644
--- a/languages/fi.ini
+++ b/languages/fi.ini
@@ -102,6 +102,7 @@ bookbag_save = "Tallenna valitut"
 bookbag_save_selected  = "Tallenna valitut"
 Bookmark = "Kirjanmerkki"
 Books = "Kirjat"
+Borrowing Location = Lainauspaikka
 Braille = "Braille"
 Brief View = "Lyhyet tiedot"
 Browse = "Selaa"
diff --git a/languages/sv.ini b/languages/sv.ini
index ea120a7528e..bfffc9d8ce5 100644
--- a/languages/sv.ini
+++ b/languages/sv.ini
@@ -102,6 +102,7 @@ bookbag_save = "Lagra de utvalda"
 bookbag_save_selected  = "Lagra de utvalda"
 Bookmark = "Bokmärke"
 Books = "Böcker"
+Borrowing Location = LÃ¥neplats
 Braille = "Brailleskrift"
 Brief View = "Kort vy"
 Browse = "Bläddra"
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Demo.php b/module/VuFind/src/VuFind/ILS/Driver/Demo.php
index 3f820dd31a9..02420ee92dd 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Demo.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Demo.php
@@ -794,7 +794,8 @@ class Demo extends AbstractBase
                         'title'   => "ILL Loan Title $i",
                         'institution_id' => 'ill_institution',
                         'institution_name' => 'ILL Library',
-                        'institution_dbkey' => 'ill_institution'
+                        'institution_dbkey' => 'ill_institution',
+                        'borrowingLocation' => 'ILL Service Desk'
                     );
                 } else {
                     $transList[] = $this->getRandomItemIdentifier() + array(
@@ -805,7 +806,8 @@ class Demo extends AbstractBase
                         'renewLimit' => $renewLimit,
                         'request' => $req,
                         'item_id' => $i,
-                        'renewable' => $renew < $renewLimit
+                        'renewable' => $renew < $renewLimit,
+                        'borrowingLocation' => $this->getFakeLoc()
                     );
                     if ($this->idsInMyResearch) {
                         $transList[$i]['id'] = $this->getRandomBibId();
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
index 3953bc72c2b..ffd39a2d24c 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php
@@ -1286,7 +1286,8 @@ class Voyager extends AbstractBase
             "BIB_TEXT.TITLE_BRIEF",
             "BIB_TEXT.TITLE",
             "CIRC_TRANSACTIONS.RENEWAL_COUNT",
-            "CIRC_POLICY_MATRIX.RENEWAL_COUNT as RENEWAL_LIMIT"
+            "CIRC_POLICY_MATRIX.RENEWAL_COUNT as RENEWAL_LIMIT",
+            "LOCATION.LOCATION_DISPLAY_NAME as BORROWING_LOCATION"
         );
 
         // From
@@ -1295,7 +1296,8 @@ class Voyager extends AbstractBase
             $this->dbName.".BIB_ITEM",
             $this->dbName.".MFHD_ITEM",
             $this->dbName.".BIB_TEXT",
-            $this->dbName.".CIRC_POLICY_MATRIX"
+            $this->dbName.".CIRC_POLICY_MATRIX",
+            $this->dbName.".LOCATION"
         );
 
         // Where
@@ -1305,7 +1307,8 @@ class Voyager extends AbstractBase
             "CIRC_TRANSACTIONS.ITEM_ID = MFHD_ITEM.ITEM_ID(+)",
             "BIB_TEXT.BIB_ID = BIB_ITEM.BIB_ID",
             "CIRC_TRANSACTIONS.CIRC_POLICY_MATRIX_ID = " .
-            "CIRC_POLICY_MATRIX.CIRC_POLICY_MATRIX_ID"
+            "CIRC_POLICY_MATRIX.CIRC_POLICY_MATRIX_ID",
+            "CIRC_TRANSACTIONS.CHARGE_LOCATION = LOCATION.LOCATION_ID"
         );
 
         // Order
@@ -1360,7 +1363,7 @@ class Voyager extends AbstractBase
             }
         }
 
-        return array(
+        $transaction = array(
             'id' => $sqlRow['BIB_ID'],
             'item_id' => $sqlRow['ITEM_ID'],
             'duedate' => $dueDate,
@@ -1373,6 +1376,14 @@ class Voyager extends AbstractBase
             'renew' => $sqlRow['RENEWAL_COUNT'],
             'renewLimit' => $sqlRow['RENEWAL_LIMIT']
         );
+        if (isset($this->config['Loans']['display_borrowing_location'])
+            && $this->config['Loans']['display_borrowing_location']
+        ) {
+            $transaction['borrowingLocation']
+                = utf8_encode($sqlRow['BORROWING_LOCATION']);
+        }
+
+        return $transaction;
     }
 
     /**
diff --git a/themes/blueprint/templates/myresearch/checkedout.phtml b/themes/blueprint/templates/myresearch/checkedout.phtml
index 87aedb53de7..2728c44edb4 100644
--- a/themes/blueprint/templates/myresearch/checkedout.phtml
+++ b/themes/blueprint/templates/myresearch/checkedout.phtml
@@ -67,29 +67,34 @@
               <?=$this->record($resource)->getFormatList()?>
               <br/>
             <? endif; ?>
-            <? if (isset($ilsDetails['volume']) && !empty($ilsDetails['volume'])): ?>
+            <? if (!empty($ilsDetails['volume'])): ?>
               <strong><?=$this->transEsc('Volume')?>:</strong> <?=$this->escapeHtml($ilsDetails['volume'])?>
               <br />
             <? endif; ?>
 
-            <? if (isset($ilsDetails['publication_year']) && !empty($ilsDetails['publication_year'])): ?>
+            <? if (!empty($ilsDetails['publication_year'])): ?>
               <strong><?=$this->transEsc('Year of Publication')?>:</strong> <?=$this->escapeHtml($ilsDetails['publication_year'])?>
               <br />
             <? endif; ?>
 
-            <? if (isset($ilsDetails['institution_name']) && !empty($ilsDetails['institution_name'])): ?>
+            <? if (!empty($ilsDetails['institution_name'])): ?>
               <strong><?=$this->transEsc('location_' . $ilsDetails['institution_name'], array(), $ilsDetails['institution_name'])?></strong>
               <br />
             <? endif; ?>
 
+            <? if (!empty($ilsDetails['borrowingLocation'])): ?>
+              <strong><?=$this->transEsc('Borrowing Location')?>:</strong> <?=$this->transEsc('location_' . $ilsDetails['borrowingLocation'], array(), $ilsDetails['borrowingLocation'])?>
+              <br />
+            <? endif; ?>
+
             <? if (isset($ilsDetails['renew'])): ?>
               <strong><?=$this->transEsc('Renewed')?>:</strong> <?=$this->transEsc($ilsDetails['renew'])?>
               <? if (isset($ilsDetails['renewLimit'])): ?>
                 / <?=$this->transEsc($ilsDetails['renewLimit'])?>
               <? endif; ?>
               <br />
-            <? endif; ?>            
-            
+            <? endif; ?>
+
             <? $showStatus = true; ?>
 
             <? if (isset($this->renewResult[$ilsDetails['item_id']])): ?>
diff --git a/themes/bootprint/templates/myresearch/checkedout.phtml b/themes/bootprint/templates/myresearch/checkedout.phtml
index 65c2915253d..aba0c1c9400 100644
--- a/themes/bootprint/templates/myresearch/checkedout.phtml
+++ b/themes/bootprint/templates/myresearch/checkedout.phtml
@@ -62,29 +62,34 @@
             <?=str_replace('class="', 'class="label label-info ', $this->record($resource)->getFormatList())?>
             <br/>
           <? endif; ?>
-          <? if (isset($ilsDetails['volume']) && !empty($ilsDetails['volume'])): ?>
+          <? if (!empty($ilsDetails['volume'])): ?>
             <strong><?=$this->transEsc('Volume')?>:</strong> <?=$this->escapeHtml($ilsDetails['volume'])?>
             <br />
           <? endif; ?>
 
-          <? if (isset($ilsDetails['publication_year']) && !empty($ilsDetails['publication_year'])): ?>
+          <? if (!empty($ilsDetails['publication_year'])): ?>
             <strong><?=$this->transEsc('Year of Publication')?>:</strong> <?=$this->escapeHtml($ilsDetails['publication_year'])?>
             <br />
           <? endif; ?>
 
-          <? if (isset($ilsDetails['institution_name']) && !empty($ilsDetails['institution_name'])): ?>
+          <? if (!empty($ilsDetails['institution_name']) && (empty($ilsDetails['borrowingLocation']) || $ilsDetails['institution_name'] != $ilsDetails['borrowingLocation'])): ?>
             <strong><?=$this->transEsc('location_' . $ilsDetails['institution_name'], array(), $ilsDetails['institution_name'])?></strong>
             <br />
           <? endif; ?>
-          
+
+          <? if (!empty($ilsDetails['borrowingLocation'])): ?>
+            <strong><?=$this->transEsc('Borrowing Location')?>:</strong> <?=$this->transEsc('location_' . $ilsDetails['borrowingLocation'], array(), $ilsDetails['borrowingLocation'])?>
+            <br />
+          <? endif; ?>
+
           <? if (isset($ilsDetails['renew'])): ?>
             <strong><?=$this->transEsc('Renewed')?>:</strong> <?=$this->transEsc($ilsDetails['renew'])?>
             <? if (isset($ilsDetails['renewLimit'])): ?>
               / <?=$this->transEsc($ilsDetails['renewLimit'])?>
             <? endif; ?>
             <br />
-          <? endif; ?>            
-          
+          <? endif; ?>
+
           <? $showStatus = true; ?>
 
           <? if (isset($this->renewResult[$ilsDetails['item_id']])): ?>
diff --git a/themes/bootstrap/templates/myresearch/checkedout.phtml b/themes/bootstrap/templates/myresearch/checkedout.phtml
index 2c4de0ceed6..e7bec7686f1 100644
--- a/themes/bootstrap/templates/myresearch/checkedout.phtml
+++ b/themes/bootstrap/templates/myresearch/checkedout.phtml
@@ -62,29 +62,34 @@
             <?=str_replace('class="', 'class="label label-info ', $this->record($resource)->getFormatList())?>
             <br/>
           <? endif; ?>
-          <? if (isset($ilsDetails['volume']) && !empty($ilsDetails['volume'])): ?>
+          <? if (!empty($ilsDetails['volume'])): ?>
             <strong><?=$this->transEsc('Volume')?>:</strong> <?=$this->escapeHtml($ilsDetails['volume'])?>
             <br />
           <? endif; ?>
 
-          <? if (isset($ilsDetails['publication_year']) && !empty($ilsDetails['publication_year'])): ?>
+          <? if (!empty($ilsDetails['publication_year'])): ?>
             <strong><?=$this->transEsc('Year of Publication')?>:</strong> <?=$this->escapeHtml($ilsDetails['publication_year'])?>
             <br />
           <? endif; ?>
 
-          <? if (isset($ilsDetails['institution_name']) && !empty($ilsDetails['institution_name'])): ?>
+          <? if (!empty($ilsDetails['institution_name']) && (empty($ilsDetails['borrowingLocation']) || $ilsDetails['institution_name'] != $ilsDetails['borrowingLocation'])): ?>
             <strong><?=$this->transEsc('location_' . $ilsDetails['institution_name'], array(), $ilsDetails['institution_name'])?></strong>
             <br />
           <? endif; ?>
 
+          <? if (!empty($ilsDetails['borrowingLocation'])): ?>
+            <strong><?=$this->transEsc('Borrowing Location')?>:</strong> <?=$this->transEsc('location_' . $ilsDetails['borrowingLocation'], array(), $ilsDetails['borrowingLocation'])?>
+            <br />
+          <? endif; ?>
+
           <? if (isset($ilsDetails['renew'])): ?>
             <strong><?=$this->transEsc('Renewed')?>:</strong> <?=$this->transEsc($ilsDetails['renew'])?>
             <? if (isset($ilsDetails['renewLimit'])): ?>
               / <?=$this->transEsc($ilsDetails['renewLimit'])?>
             <? endif; ?>
             <br />
-          <? endif; ?>            
-          
+          <? endif; ?>
+
           <? $showStatus = true; ?>
 
           <? if (isset($this->renewResult[$ilsDetails['item_id']])): ?>
diff --git a/themes/bootstrap3/templates/myresearch/checkedout.phtml b/themes/bootstrap3/templates/myresearch/checkedout.phtml
index 00e17ea2279..7d15422500c 100644
--- a/themes/bootstrap3/templates/myresearch/checkedout.phtml
+++ b/themes/bootstrap3/templates/myresearch/checkedout.phtml
@@ -61,21 +61,26 @@
             <?=str_replace('class="', 'class="label label-info ', $this->record($resource)->getFormatList())?>
             <br/>
           <? endif; ?>
-          <? if (isset($ilsDetails['volume']) && !empty($ilsDetails['volume'])): ?>
+          <? if (!empty($ilsDetails['volume'])): ?>
             <strong><?=$this->transEsc('Volume')?>:</strong> <?=$this->escapeHtml($ilsDetails['volume'])?>
             <br />
           <? endif; ?>
 
-          <? if (isset($ilsDetails['publication_year']) && !empty($ilsDetails['publication_year'])): ?>
+          <? if (!empty($ilsDetails['publication_year'])): ?>
             <strong><?=$this->transEsc('Year of Publication')?>:</strong> <?=$this->escapeHtml($ilsDetails['publication_year'])?>
             <br />
           <? endif; ?>
 
-          <? if (isset($ilsDetails['institution_name']) && !empty($ilsDetails['institution_name'])): ?>
+          <? if (!empty($ilsDetails['institution_name']) && (empty($ilsDetails['borrowingLocation']) || $ilsDetails['institution_name'] != $ilsDetails['borrowingLocation'])): ?>
             <strong><?=$this->transEsc('location_' . $ilsDetails['institution_name'], array(), $ilsDetails['institution_name'])?></strong>
             <br />
           <? endif; ?>
 
+          <? if (!empty($ilsDetails['borrowingLocation'])): ?>
+            <strong><?=$this->transEsc('Borrowing Location')?>:</strong> <?=$this->transEsc('location_' . $ilsDetails['borrowingLocation'], array(), $ilsDetails['borrowingLocation'])?>
+            <br />
+          <? endif; ?>
+
           <? if (isset($ilsDetails['renew'])): ?>
             <strong><?=$this->transEsc('Renewed')?>:</strong> <?=$this->transEsc($ilsDetails['renew'])?>
             <? if (isset($ilsDetails['renewLimit'])): ?>
diff --git a/themes/jquerymobile/templates/myresearch/checkedout.phtml b/themes/jquerymobile/templates/myresearch/checkedout.phtml
index 7eec680b6e6..fa7ecdb1b9c 100644
--- a/themes/jquerymobile/templates/myresearch/checkedout.phtml
+++ b/themes/jquerymobile/templates/myresearch/checkedout.phtml
@@ -47,15 +47,20 @@
             <? $formats = $resource->getFormats(); if (count($formats) > 0): ?>
               <?=$this->record($resource)->getFormatList()?>
             <? endif; ?>
-            
+
+            <? if (!empty($ilsDetails['borrowingLocation'])): ?>
+              <strong><?=$this->transEsc('Borrowing Location')?>:</strong> <?=$this->transEsc('location_' . $ilsDetails['borrowingLocation'], array(), $ilsDetails['borrowingLocation'])?>
+              <br />
+            <? endif; ?>
+
             <? if (isset($ilsDetails['renew'])): ?>
               <strong><?=$this->transEsc('Renewed')?>:</strong> <?=$this->transEsc($ilsDetails['renew'])?>
               <? if (isset($ilsDetails['renewLimit'])): ?>
                 / <?=$this->transEsc($ilsDetails['renewLimit'])?>
               <? endif; ?>
               <br />
-            <? endif; ?>            
-            
+            <? endif; ?>
+
             <? $showStatus = true; ?>
 
             <? if (isset($this->renewResult[$ilsDetails['item_id']])): ?>
-- 
GitLab