diff --git a/config/vufind/KohaILSDI.ini b/config/vufind/KohaILSDI.ini index d4561db68119886fb3cceb4d8a9876f5d39eb951..f191e4c9c6b078556c2cd44ec1cd76f6a0d2ec7a 100755 --- a/config/vufind/KohaILSDI.ini +++ b/config/vufind/KohaILSDI.ini @@ -43,6 +43,9 @@ extraHoldFields = comments:pickUpLocation:requiredByDate ; available. The default of 'false' will force users to pick a pickup ; location. By setting this to a Koha location code (e.g. '"MAIN"'), ; Vufind will default to that location. +; If no defaultPickUpLocation and no pickupLocations are defined, +; the driver will try to use the actual holdingbranch(es) of the item/title +; as a fallback. defaultPickUpLocation = "MAIN" ; branchcodes for libraries avalaible as pickup locations diff --git a/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php b/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php index 1e3f82a19ffb08a895cf8301768d37e3eb3fe530..0cb28f7ebd8f4fb531b4c9205b8b7a3de5f214ff 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php +++ b/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php @@ -463,6 +463,45 @@ class KohaILSDI extends \VuFind\ILS\Driver\AbstractBase implements if (!$this->db) { $this->initDb(); } + if (!$this->pickupEnableBranchcodes) { + // No defaultPickupLocation is defined in config + // AND no pickupLocations are defined either + if (isset($holdDetails['item_id']) && (empty($holdDetails['level']) + || $holdDetails['level'] == 'item') + ) { + // We try to get the actual branchcode the item is found at + $item_id = $holdDetails['item_id']; + $sql = "SELECT holdingbranch + FROM items + WHERE itemnumber=($item_id)"; + try { + $sqlSt = $this->db->prepare($sql); + $sqlSt->execute(); + $this->pickupEnableBranchcodes = $sqlSt->fetch(); + } catch (PDOException $e) { + $this->debug('Connection failed: ' . $e->getMessage()); + throw new ILSException($e->getMessage()); + } + } elseif (!empty($holdDetails['level']) + && $holdDetails['level'] == 'title' + ) { + // We try to get the actual branchcodes the title is found at + $id = $holdDetails['id']; + $sql = "SELECT DISTINCT holdingbranch + FROM items + WHERE biblionumber=($id)"; + try { + $sqlSt = $this->db->prepare($sql); + $sqlSt->execute(); + foreach ($sqlSt->fetchAll() as $row) { + $this->pickupEnableBranchcodes[] = $row['holdingbranch']; + } + } catch (PDOException $e) { + $this->debug('Connection failed: ' . $e->getMessage()); + throw new ILSException($e->getMessage()); + } + } + } $branchcodes = "'" . implode( "','", $this->pickupEnableBranchcodes ) . "'";