From 717db3ceaf73142d4a0fbc89ba3b3e933a768a57 Mon Sep 17 00:00:00 2001 From: Dorian Merz <merz@ub.uni-leipzig.de> Date: Wed, 20 Oct 2021 14:52:23 +0200 Subject: [PATCH] refs #20813 [finc] uniified getItemStatus * moved 'service_type' entry (and helper function) from de_zi4 * add separate getItemNotes --- .../finc/src/finc/ILS/Driver/FincLibero.php | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/module/finc/src/finc/ILS/Driver/FincLibero.php b/module/finc/src/finc/ILS/Driver/FincLibero.php index bca8dc110f6..2ad8a9f2e22 100644 --- a/module/finc/src/finc/ILS/Driver/FincLibero.php +++ b/module/finc/src/finc/ILS/Driver/FincLibero.php @@ -483,17 +483,7 @@ class FincLibero extends FincILS implements TranslatorAwareInterface { $return = parent::getItemStatus($item); - // add all item specific information from DAIA field about to item_notes - // (https://intern.finc.info/issues/7863) - $about = (isset($item['about'])) ? [$item['about']] : []; - - $return['item_notes'] = array_unique( - array_merge( - (array) $return['status'], - $return['item_notes'], - $about - ) - ); + $return['item_notes'] = $this->getItemNotes($return, $item); $return['awlRecordId'] = $this->getBoundItemId($item); // is this item bound with another item? @@ -516,9 +506,49 @@ class FincLibero extends FincILS implements TranslatorAwareInterface } } + $return['service_type'] = $this->_reduceServices($return['services']); + return $return; } + /** + * Helper function for getItemStatus(). + * Gather all item notes from current (parent) result and DAIA item + * + * @param array $return intermediate result from parent::getItemStatus() + * @param array $item DAIA item + * @return array 'item_notes' part for result + */ + protected function getItemNotes($return, $item) + { + // add all item specific information from DAIA field about to item_notes + // (https://intern.finc.info/issues/7863) + return array_unique( + array_merge( + (array)$return['status'], + $return['item_notes'], + $item['about'] ?? [] + ) + ); + } + + /** + * Helper function for 'service_type' entry in getItemStatus + * + * @param array $services actually present services in DAIA item + * @return false|int|mixed preferred service if present or 0 + */ + protected function _reduceServices($services) + { + $prio = [ + 'loan', + 'presentation', + ]; + $res = array_intersect($prio, $services); + if (empty($res)) return 0; + else return current($res); + } + /** * Helper function to return an appropriate status string for current item * -- GitLab