From baab6dc995458c6f5f918aedd514324d6568bc6e Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 26 Apr 2013 09:23:15 -0400
Subject: [PATCH] Resolving VUFIND-800 (Implement level-based requests in
 HorizonXMLAPI driver) Thanks to Jay Roos.

---
 .../src/VuFind/ILS/Driver/HorizonXMLAPI.php   | 58 ++++++++-----------
 1 file changed, 25 insertions(+), 33 deletions(-)

diff --git a/module/VuFind/src/VuFind/ILS/Driver/HorizonXMLAPI.php b/module/VuFind/src/VuFind/ILS/Driver/HorizonXMLAPI.php
index 6cc63d83145..ddd142345e6 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/HorizonXMLAPI.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/HorizonXMLAPI.php
@@ -120,30 +120,11 @@ class HorizonXMLAPI extends Horizon implements \VuFindHttp\HttpServiceAwareInter
     {
         $holding = parent::processHoldingRow($id, $row, $patron);
         $holding += array(
-            'item_id' => $id,
             'addLink' => $this->checkItemRequests($patron, $id)
         );
         return $holding;
     }
 
-    /**
-     * Protected support method for getMyHolds.
-     *
-     * @param array $row An sql row
-     *
-     * @return array Keyed data
-     */
-    protected function processHoldsRow($row)
-    {
-        $hold = parent::processHoldsRow($row);
-        // item# not populated by Horizon,
-        // this is provided for VuFind matching
-        if ($hold) {
-            $hold['item_id'] = $row['BIB_NUM'];
-        }
-        return $hold;
-    }
-
     /**
      * Determine Renewability
      *
@@ -559,6 +540,11 @@ class HorizonXMLAPI extends Horizon implements \VuFindHttp\HttpServiceAwareInter
                         "GetXML" => "true"
                         );
 
+        // set itemkey only if available
+        if ($requestDetails['itemId'] != '') {
+            $params += array("itemkey" => $requestDetails['itemId']);
+        }
+
         $initResponse = $this->makeRequest($params);
 
         if ($initResponse->request_confirm) {
@@ -621,22 +607,22 @@ class HorizonXMLAPI extends Horizon implements \VuFindHttp\HttpServiceAwareInter
     protected function cancelRequest($session, $data)
     {
         $responseItems = array();
-        
-        foreach ($data as $values) {
-            $bibData[] = $values['bib_id'];
-            $items[] = $values['item_id'];
-        }
 
-        $params = array("session" => $session,
-                        "profile" => $this->wsProfile,
-                        "lang" => "eng",
-                        "menu" => "account",
-                        "submenu" => "holds",
+        $params = array("session"    => $session,
+                        "profile"    => $this->wsProfile,
+                        "lang"       => "eng",
+                        "menu"       => "account",
+                        "submenu"    => "holds",
                         "cancelhold" => "Cancel Request",
-                        "waitingholdselected" => $bibData,
-                        "GetXML" => "true"
+                        "GetXML"     => "true"
                         );
 
+        foreach ($data as $values) {
+            $cancelData[] = $values['bib_id'] . ':' . $values['item_id'];
+        }
+
+        $params += array("waitingholdselected" => $cancelData);
+
         $response = $this->makeRequest($params);
 
         // No Indication of Success or Failure
@@ -705,17 +691,23 @@ class HorizonXMLAPI extends Horizon implements \VuFindHttp\HttpServiceAwareInter
         $userBarcode      = $holdDetails['patron']['id'];
         $userPassword     = $holdDetails['patron']['cat_password'];
         $bibId            = $holdDetails['id'];
+        $itemId           = $holdDetails['item_id'];
+        $level            = $holdDetails['level'];
         $pickUpLocationID = !empty($holdDetails['pickUpLocation'])
                           ? $holdDetails['pickUpLocation']
                           : $this->getDefaultPickUpLocation();
         $notify           = $this->config['Holds']['notify'];
 
         $requestDetails = array(
-            'bibId' => $bibId,
+            'bibId'          => $bibId,
             'pickuplocation' => $pickUpLocationID,
-            'notify' => $notify
+            'notify'         => $notify
         );
 
+        if ($level != 'title' && $itemId != '') {
+            $requestDetails += array('itemId' => $itemId);
+        }
+
         // Register Account
         $session = $this->registerUser($userBarcode, $userPassword);
         if ($session) {
-- 
GitLab