diff --git a/module/finc/src/finc/ILS/Driver/FincLibero.php b/module/finc/src/finc/ILS/Driver/FincLibero.php index 7dba67eafafc7363aa95bb741e2f82d875699bcd..8c552e7387710567d5bbd0afafb0fb8b81e6b827 100644 --- a/module/finc/src/finc/ILS/Driver/FincLibero.php +++ b/module/finc/src/finc/ILS/Driver/FincLibero.php @@ -30,6 +30,7 @@ namespace finc\ILS\Driver; use VuFind\I18n\Translator\TranslatorAwareTrait; use VuFind\I18n\Translator\TranslatorAwareInterface, VuFind\Exception\ILS as ILSException; +use VuFindSearch\Query\Query; /** * Finc specific Libero ILS Driver for VuFind, using PAIA, DAIA and LiberoWachtl @@ -106,6 +107,25 @@ class FincLibero extends FincILS implements TranslatorAwareInterface */ protected $readingRoomURIs = []; + /** + * Regex pattern to detect bound item ID + * @var string + */ + protected $boundItemIdPattern; + + /** + * Regex pattern to detect bound item label + * @var string + */ + protected $boundItemLabelPattern; + + public function init() + { + parent::init(); + $this->boundItemIdPattern = $this->config['General']['bound_item_id_pattern'] ?? null; + $this->boundItemLabelPattern = $this->config['General']['bound_item_label_pattern'] ?? null; + } + /** * Helper function to extract the Namespace from the DAIA URI prefix. * @@ -701,15 +721,81 @@ class FincLibero extends FincILS implements TranslatorAwareInterface return $pickUpLocations; } + /** - * TODO: check status of this function - * de_15 -> getBoundItemId() vs. de_l152 -> getBoundItemInfo() - * @param $item - * @return array + * Helper method to check whether this item is bound with another item and needs + * to be ordered via this bound item + * + * @param array $item Array with DAIA item data + * + * @return null */ protected function getBoundItemId($item) { - return []; + if (!isset($this->boundItemIdPattern)) return null; + $availabilities = ['available', 'unavailable']; + + // start logic to check if we have a bound item that needs to be ordered + // via another record (see https://intern.finc.info/issues/5068) + foreach ($availabilities as $availability) { + if (isset($item[$availability])) { + foreach ($item[$availability] as $available) { + if (isset($available['limitation'])) { + foreach ($available['limitation'] as $limitation) { + if (in_array($limitation['id'], $this->awlLimitations)) { + // items with limitations identifying the record for + // being bound to another item contain the RSN of the + // bound item in their current available service href + if (isset($available['href']) + && preg_match($this->boundItemIdPattern, + $available['href'], + $matches + ) + ) { + return $this->queryBoundItem($matches['id']); + } + } + } + } + } + } + } + + // if we made it this far this item definitely is not bound to another item + return null; + } + + + /** + * Helper method to query bound item by rsn for record_id + * + * @param string $key + * + * @return string record_id + */ + protected function queryBoundItem($key) { + + $query = $this->getBoundItemQueryString($key); + if (empty($query)) { + return null; + } + try { + // let's search with the built query + $result = $this->searchService + ->search('VuFind', new Query($query)); + if (count($result) === 0) { + $this->debug('Problem retrieving rsn ' . + 'for record with query:' . $query); + return null; + } + // pass the id from the first found record as + // awlRecordId to the controller + return current($result->getRecords()) + ->getUniqueId(); + } catch (\Exception $e) { + $this->debug($e); + return null; + } } /** @@ -816,4 +902,18 @@ class FincLibero extends FincILS implements TranslatorAwareInterface } return $holdDetails; } + + /** + * Helper function for queryBoundItem. Prepares instance specific query string + * to get the ID of the bound item + * + * Override in inherited FincLibero + * + * @param $key string ID to search for + * @return string SOLR query to be used as q parameter + */ + protected function getBoundItemQueryString($key) + { + return ''; + } }