From 2e917b08c6d2ef0c321970bb96db55419cc549d4 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Thu, 6 Jun 2024 15:49:50 +0200 Subject: [PATCH 01/29] Display status of item locations by status priority. --- .../src/VuFind/AjaxHandler/GetItemStatuses.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 65faef9f84a..25dba6dd3a4 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -337,15 +337,12 @@ protected function getItemStatusGroup($record, $callnumberSetting) $locations[$info['location']]['available'] = $availabilityStatus->getStatusDescription(); } } - // Check for a use_unknown_message flag - if ($availabilityStatus->is(AvailabilityStatusInterface::STATUS_UNKNOWN)) { - $locations[$info['location']]['status_unknown'] = true; - } // Store call number/location info: $locations[$info['location']]['callnumbers'][] = $this->formatCallNo( $info['callnumber_prefix'] ?? '', $info['callnumber'] ); + $locations[$info['location']]['items'][] = $info; } // Build list split out by location: @@ -362,8 +359,14 @@ protected function getItemStatusGroup($record, $callnumberSetting) $callnumberSetting, 'Multiple Call Numbers' ); + + // Get combined availability for location + $locationStatus = $this->availabilityStatusManager->combine($details['items']); + $locationAvailability = $locationStatus['availability']; + $locationInfo = [ - 'availability' => $details['available'] ?? false, + 'availability' => + $locationAvailability->is(AvailabilityStatusInterface::STATUS_AVAILABLE), 'location' => htmlentities( $this->translateWithPrefix('location_', $location), ENT_COMPAT, @@ -371,7 +374,8 @@ protected function getItemStatusGroup($record, $callnumberSetting) ), 'callnumbers' => htmlentities($locationCallnumbers, ENT_COMPAT, 'UTF-8'), - 'status_unknown' => $details['status_unknown'] ?? false, + 'status_unknown' => + $locationAvailability->is(AvailabilityStatusInterface::STATUS_UNKNOWN), 'callnumber_handler' => $callnumberHandler, ]; $locationList[] = $locationInfo; From 9c0777872a0e7b8ca73f52ff86b75cb10a5450cd Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Thu, 6 Jun 2024 16:11:08 +0200 Subject: [PATCH 02/29] Removed unneeded code --- module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 25dba6dd3a4..0d0525d99c4 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -330,13 +330,6 @@ protected function getItemStatusGroup($record, $callnumberSetting) // Summarize call number, location and availability info across all items: $locations = []; foreach ($record as $info) { - $availabilityStatus = $info['availability']; - // Find an available copy - if ($availabilityStatus->isAvailable()) { - if ('true' !== ($locations[$info['location']]['available'] ?? null)) { - $locations[$info['location']]['available'] = $availabilityStatus->getStatusDescription(); - } - } // Store call number/location info: $locations[$info['location']]['callnumbers'][] = $this->formatCallNo( $info['callnumber_prefix'] ?? '', From 4d74ee2c1f9da62d845b50a8fc0708fb1b8791e5 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Fri, 21 Jun 2024 11:23:15 +0200 Subject: [PATCH 03/29] Refactored display of item locations in the results --- .../VuFind/AjaxHandler/GetItemStatuses.php | 4 +-- .../VuFind/ILS/Logic/AvailabilityStatus.php | 4 +-- themes/bootstrap3/js/check_item_statuses.js | 25 ++++--------------- .../templates/search/results-scripts.phtml | 18 +++++++++++++ themes/bootstrap3/theme.config.php | 1 + themes/bootstrap5/js/check_item_statuses.js | 25 ++++--------------- .../templates/search/results-scripts.phtml | 19 ++++++++++++++ themes/bootstrap5/theme.config.php | 1 + 8 files changed, 52 insertions(+), 45 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 0d0525d99c4..a02562e2d6a 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -359,7 +359,7 @@ protected function getItemStatusGroup($record, $callnumberSetting) $locationInfo = [ 'availability' => - $locationAvailability->is(AvailabilityStatusInterface::STATUS_AVAILABLE), + $locationAvailability->availabilityAsString(), 'location' => htmlentities( $this->translateWithPrefix('location_', $location), ENT_COMPAT, @@ -367,8 +367,6 @@ protected function getItemStatusGroup($record, $callnumberSetting) ), 'callnumbers' => htmlentities($locationCallnumbers, ENT_COMPAT, 'UTF-8'), - 'status_unknown' => - $locationAvailability->is(AvailabilityStatusInterface::STATUS_UNKNOWN), 'callnumber_handler' => $callnumberHandler, ]; $locationList[] = $locationInfo; diff --git a/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php b/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php index 1ee722ee374..91f7860c3a2 100644 --- a/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php +++ b/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php @@ -143,9 +143,9 @@ public function availabilityAsString(): string { switch ($this->availability) { case AvailabilityStatusInterface::STATUS_UNAVAILABLE: - return 'false'; + return 'unavailable'; case AvailabilityStatusInterface::STATUS_AVAILABLE: - return 'true'; + return 'available'; case AvailabilityStatusInterface::STATUS_UNKNOWN: return 'unknown'; default: diff --git a/themes/bootstrap3/js/check_item_statuses.js b/themes/bootstrap3/js/check_item_statuses.js index dac8cf8ca8f..75a26956b2e 100644 --- a/themes/bootstrap3/js/check_item_statuses.js +++ b/themes/bootstrap3/js/check_item_statuses.js @@ -58,27 +58,12 @@ VuFind.register('itemStatuses', function ItemStatuses() { el.querySelectorAll('.callnumber,.hideIfDetailed,.location').forEach((e) => e.classList.add('hidden')); var locationListHTML = ""; for (var x = 0; x < result.locationList.length; x++) { + var status = result.locationList[x].status; locationListHTML += '
'; - if (result.locationList[x].availability) { - locationListHTML += '' - + VuFind.icon("status-available") - + result.locationList[x].location - + ' '; - } else if (typeof(result.locationList[x].status_unknown) !== 'undefined' - && result.locationList[x].status_unknown - ) { - if (result.locationList[x].location) { - locationListHTML += '' - + VuFind.icon("status-unknown") - + result.locationList[x].location - + ' '; - } - } else { - locationListHTML += '' - + VuFind.icon("status-unavailable") - + result.locationList[x].location - + ' '; - } + locationListHTML += '' + + VuFind.icon('status-' + status) + + result.locationList[x].location + + ' '; locationListHTML += '
'; locationListHTML += '
'; locationListHTML += (result.locationList[x].callnumbers) diff --git a/themes/bootstrap3/templates/search/results-scripts.phtml b/themes/bootstrap3/templates/search/results-scripts.phtml index a18328cd41e..6de7bcb56cc 100644 --- a/themes/bootstrap3/templates/search/results-scripts.phtml +++ b/themes/bootstrap3/templates/search/results-scripts.phtml @@ -14,3 +14,21 @@ if (($this->listViewOption ?? 'full') !== 'full') { if ($this->jsResults ?? false) { $this->headScript()->appendFile('search.js'); } + +$statuses = [ + \VuFind\ILS\Logic\AvailabilityStatus::STATUS_AVAILABLE, + \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNAVAILABLE, + \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNKNOWN, + \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNCERTAIN, +]; + +$availabilityStatuses = []; +foreach ($statuses as $status) { + $status = new \VuFind\ILS\Logic\AvailabilityStatus($status); + $availabilityStatusClasses[$status->availabilityAsString()] = + $this->availabilityStatus()->getClass($status); +} + +$this->headScript()->appendScript(<< 'FontAwesome:clock-o', 'status-ready' => 'FontAwesome:bell', 'status-unavailable' => 'FontAwesome:times', + 'status-uncertain' => 'FontAwesome:circle', 'status-unknown' => 'FontAwesome:circle', 'tag-add' => 'Alias:ui-add', 'tag-remove' => 'Alias:ui-remove', diff --git a/themes/bootstrap5/js/check_item_statuses.js b/themes/bootstrap5/js/check_item_statuses.js index dac8cf8ca8f..75a26956b2e 100644 --- a/themes/bootstrap5/js/check_item_statuses.js +++ b/themes/bootstrap5/js/check_item_statuses.js @@ -58,27 +58,12 @@ VuFind.register('itemStatuses', function ItemStatuses() { el.querySelectorAll('.callnumber,.hideIfDetailed,.location').forEach((e) => e.classList.add('hidden')); var locationListHTML = ""; for (var x = 0; x < result.locationList.length; x++) { + var status = result.locationList[x].status; locationListHTML += '
'; - if (result.locationList[x].availability) { - locationListHTML += '' - + VuFind.icon("status-available") - + result.locationList[x].location - + ' '; - } else if (typeof(result.locationList[x].status_unknown) !== 'undefined' - && result.locationList[x].status_unknown - ) { - if (result.locationList[x].location) { - locationListHTML += '' - + VuFind.icon("status-unknown") - + result.locationList[x].location - + ' '; - } - } else { - locationListHTML += '' - + VuFind.icon("status-unavailable") - + result.locationList[x].location - + ' '; - } + locationListHTML += '' + + VuFind.icon('status-' + status) + + result.locationList[x].location + + ' '; locationListHTML += '
'; locationListHTML += '
'; locationListHTML += (result.locationList[x].callnumbers) diff --git a/themes/bootstrap5/templates/search/results-scripts.phtml b/themes/bootstrap5/templates/search/results-scripts.phtml index a18328cd41e..7da11d56328 100644 --- a/themes/bootstrap5/templates/search/results-scripts.phtml +++ b/themes/bootstrap5/templates/search/results-scripts.phtml @@ -14,3 +14,22 @@ if (($this->listViewOption ?? 'full') !== 'full') { if ($this->jsResults ?? false) { $this->headScript()->appendFile('search.js'); } + +$statuses = [ + \VuFind\ILS\Logic\AvailabilityStatus::STATUS_AVAILABLE, + \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNAVAILABLE, + \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNKNOWN, + \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNCERTAIN, +]; + +$availabilityStatuses = []; +foreach ($statuses as $status) { + $status = new \VuFind\ILS\Logic\AvailabilityStatus($status); + $availabilityClasses[$status->availabilityAsString()] = + $this->availabilityStatus()->getClass($status); +} + +$availabilityClassesJson = json_encode($availabilityClasses); +$this->headScript()->appendScript(<< 'FontAwesome:clock-o', 'status-ready' => 'FontAwesome:bell', 'status-unavailable' => 'FontAwesome:times', + 'status-uncertain' => 'FontAwesome:circle', 'status-unknown' => 'FontAwesome:circle', 'tag-add' => 'Alias:ui-add', 'tag-remove' => 'Alias:ui-remove', From 8cf1ee993a620c0bbeb328c8b01ba01ac7336dd9 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Mon, 8 Jul 2024 09:29:35 +0200 Subject: [PATCH 04/29] Reverted return values of AvailabilityStatus::availabilityAsString. Adjusted check_item_statuses.js. --- .../VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php | 4 ++-- themes/bootstrap3/js/check_item_statuses.js | 9 +++++++-- themes/bootstrap5/js/check_item_statuses.js | 9 +++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php b/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php index 91f7860c3a2..1ee722ee374 100644 --- a/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php +++ b/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php @@ -143,9 +143,9 @@ public function availabilityAsString(): string { switch ($this->availability) { case AvailabilityStatusInterface::STATUS_UNAVAILABLE: - return 'unavailable'; + return 'false'; case AvailabilityStatusInterface::STATUS_AVAILABLE: - return 'available'; + return 'true'; case AvailabilityStatusInterface::STATUS_UNKNOWN: return 'unknown'; default: diff --git a/themes/bootstrap3/js/check_item_statuses.js b/themes/bootstrap3/js/check_item_statuses.js index 75a26956b2e..3939747a4bf 100644 --- a/themes/bootstrap3/js/check_item_statuses.js +++ b/themes/bootstrap3/js/check_item_statuses.js @@ -1,4 +1,4 @@ -/*global AjaxRequestQueue, VuFind */ +/*global AjaxRequestQueue, VuFind, availabilityClasses */ VuFind.register('itemStatuses', function ItemStatuses() { function formatCallnumbers(callnumber, callnumber_handler) { @@ -59,8 +59,13 @@ VuFind.register('itemStatuses', function ItemStatuses() { var locationListHTML = ""; for (var x = 0; x < result.locationList.length; x++) { var status = result.locationList[x].status; + var locationClass = + availabilityClasses[status] === 'true' ? 'available' + : availabilityClasses[status] === 'false' ? 'unavailable' + : availabilityClasses[status]; + locationListHTML += '
'; - locationListHTML += '' + locationListHTML += '' + VuFind.icon('status-' + status) + result.locationList[x].location + ' '; diff --git a/themes/bootstrap5/js/check_item_statuses.js b/themes/bootstrap5/js/check_item_statuses.js index 75a26956b2e..3939747a4bf 100644 --- a/themes/bootstrap5/js/check_item_statuses.js +++ b/themes/bootstrap5/js/check_item_statuses.js @@ -1,4 +1,4 @@ -/*global AjaxRequestQueue, VuFind */ +/*global AjaxRequestQueue, VuFind, availabilityClasses */ VuFind.register('itemStatuses', function ItemStatuses() { function formatCallnumbers(callnumber, callnumber_handler) { @@ -59,8 +59,13 @@ VuFind.register('itemStatuses', function ItemStatuses() { var locationListHTML = ""; for (var x = 0; x < result.locationList.length; x++) { var status = result.locationList[x].status; + var locationClass = + availabilityClasses[status] === 'true' ? 'available' + : availabilityClasses[status] === 'false' ? 'unavailable' + : availabilityClasses[status]; + locationListHTML += '
'; - locationListHTML += '' + locationListHTML += '' + VuFind.icon('status-' + status) + result.locationList[x].location + ' '; From cc13f9dbea3e600f1543418b289c1ad5e96a2232 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Mon, 8 Jul 2024 10:56:47 +0200 Subject: [PATCH 05/29] Code styling --- themes/bootstrap3/templates/search/results-scripts.phtml | 4 ++-- themes/bootstrap5/templates/search/results-scripts.phtml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/themes/bootstrap3/templates/search/results-scripts.phtml b/themes/bootstrap3/templates/search/results-scripts.phtml index 6de7bcb56cc..fae93577331 100644 --- a/themes/bootstrap3/templates/search/results-scripts.phtml +++ b/themes/bootstrap3/templates/search/results-scripts.phtml @@ -30,5 +30,5 @@ foreach ($statuses as $status) { } $this->headScript()->appendScript(<<headScript()->appendScript(<< Date: Mon, 8 Jul 2024 11:09:29 +0200 Subject: [PATCH 06/29] Code styling --- themes/bootstrap3/js/check_item_statuses.js | 6 +++--- themes/bootstrap5/js/check_item_statuses.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/themes/bootstrap3/js/check_item_statuses.js b/themes/bootstrap3/js/check_item_statuses.js index 3939747a4bf..2853f5239d3 100644 --- a/themes/bootstrap3/js/check_item_statuses.js +++ b/themes/bootstrap3/js/check_item_statuses.js @@ -60,9 +60,9 @@ VuFind.register('itemStatuses', function ItemStatuses() { for (var x = 0; x < result.locationList.length; x++) { var status = result.locationList[x].status; var locationClass = - availabilityClasses[status] === 'true' ? 'available' - : availabilityClasses[status] === 'false' ? 'unavailable' - : availabilityClasses[status]; + availabilityClasses[status] === 'true' ? 'available' + : availabilityClasses[status] === 'false' ? 'unavailable' + : availabilityClasses[status]; locationListHTML += '
'; locationListHTML += '' diff --git a/themes/bootstrap5/js/check_item_statuses.js b/themes/bootstrap5/js/check_item_statuses.js index 3939747a4bf..2853f5239d3 100644 --- a/themes/bootstrap5/js/check_item_statuses.js +++ b/themes/bootstrap5/js/check_item_statuses.js @@ -60,9 +60,9 @@ VuFind.register('itemStatuses', function ItemStatuses() { for (var x = 0; x < result.locationList.length; x++) { var status = result.locationList[x].status; var locationClass = - availabilityClasses[status] === 'true' ? 'available' - : availabilityClasses[status] === 'false' ? 'unavailable' - : availabilityClasses[status]; + availabilityClasses[status] === 'true' ? 'available' + : availabilityClasses[status] === 'false' ? 'unavailable' + : availabilityClasses[status]; locationListHTML += '
'; locationListHTML += '' From 5fc5bacbbfd0ac6cbef4365b096c04b59cc8af09 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Mon, 8 Jul 2024 11:15:05 +0200 Subject: [PATCH 07/29] Fixed results-scripts.phtml for theme bootstrap3 --- themes/bootstrap3/templates/search/results-scripts.phtml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/themes/bootstrap3/templates/search/results-scripts.phtml b/themes/bootstrap3/templates/search/results-scripts.phtml index fae93577331..7d8e2e4ad56 100644 --- a/themes/bootstrap3/templates/search/results-scripts.phtml +++ b/themes/bootstrap3/templates/search/results-scripts.phtml @@ -25,10 +25,11 @@ $statuses = [ $availabilityStatuses = []; foreach ($statuses as $status) { $status = new \VuFind\ILS\Logic\AvailabilityStatus($status); - $availabilityStatusClasses[$status->availabilityAsString()] = + $availabilityClasses[$status->availabilityAsString()] = $this->availabilityStatus()->getClass($status); } +$availabilityClassesJson = json_encode($availabilityClasses); $this->headScript()->appendScript(<< Date: Mon, 12 Aug 2024 15:32:55 +0200 Subject: [PATCH 08/29] Fixed availability display --- themes/bootstrap3/js/check_item_statuses.js | 14 +++++++------- themes/bootstrap5/js/check_item_statuses.js | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/themes/bootstrap3/js/check_item_statuses.js b/themes/bootstrap3/js/check_item_statuses.js index 2853f5239d3..3c31274ffa9 100644 --- a/themes/bootstrap3/js/check_item_statuses.js +++ b/themes/bootstrap3/js/check_item_statuses.js @@ -58,15 +58,15 @@ VuFind.register('itemStatuses', function ItemStatuses() { el.querySelectorAll('.callnumber,.hideIfDetailed,.location').forEach((e) => e.classList.add('hidden')); var locationListHTML = ""; for (var x = 0; x < result.locationList.length; x++) { - var status = result.locationList[x].status; - var locationClass = - availabilityClasses[status] === 'true' ? 'available' - : availabilityClasses[status] === 'false' ? 'unavailable' - : availabilityClasses[status]; + var availability = result.locationList[x].availability; + var statusIcon = + availability === 'true' ? 'available' + : availability === 'false' ? 'unavailable' + : availability; locationListHTML += '
'; - locationListHTML += '' - + VuFind.icon('status-' + status) + locationListHTML += '' + + VuFind.icon('status-' + statusIcon) + result.locationList[x].location + ' '; locationListHTML += '
'; diff --git a/themes/bootstrap5/js/check_item_statuses.js b/themes/bootstrap5/js/check_item_statuses.js index 2853f5239d3..3c31274ffa9 100644 --- a/themes/bootstrap5/js/check_item_statuses.js +++ b/themes/bootstrap5/js/check_item_statuses.js @@ -58,15 +58,15 @@ VuFind.register('itemStatuses', function ItemStatuses() { el.querySelectorAll('.callnumber,.hideIfDetailed,.location').forEach((e) => e.classList.add('hidden')); var locationListHTML = ""; for (var x = 0; x < result.locationList.length; x++) { - var status = result.locationList[x].status; - var locationClass = - availabilityClasses[status] === 'true' ? 'available' - : availabilityClasses[status] === 'false' ? 'unavailable' - : availabilityClasses[status]; + var availability = result.locationList[x].availability; + var statusIcon = + availability === 'true' ? 'available' + : availability === 'false' ? 'unavailable' + : availability; locationListHTML += '
'; - locationListHTML += '' - + VuFind.icon('status-' + status) + locationListHTML += '' + + VuFind.icon('status-' + statusIcon) + result.locationList[x].location + ' '; locationListHTML += '
'; From 04ee7cff6fa4a11fc4bc55ff8b4ec050924ee8f0 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Fri, 6 Sep 2024 11:47:39 +0200 Subject: [PATCH 09/29] Added 'status-uncertain' icons to js-icons.phtml --- themes/bootstrap3/templates/layout/js-icons.phtml | 1 + themes/bootstrap5/templates/layout/js-icons.phtml | 1 + 2 files changed, 2 insertions(+) diff --git a/themes/bootstrap3/templates/layout/js-icons.phtml b/themes/bootstrap3/templates/layout/js-icons.phtml index 5838c1c6293..35daa731945 100644 --- a/themes/bootstrap3/templates/layout/js-icons.phtml +++ b/themes/bootstrap3/templates/layout/js-icons.phtml @@ -27,6 +27,7 @@ $list = [ 'status-pending', 'status-ready', 'status-unavailable', + 'status-uncertain', 'status-unknown', 'ui-failure', 'ui-success', diff --git a/themes/bootstrap5/templates/layout/js-icons.phtml b/themes/bootstrap5/templates/layout/js-icons.phtml index 5838c1c6293..35daa731945 100644 --- a/themes/bootstrap5/templates/layout/js-icons.phtml +++ b/themes/bootstrap5/templates/layout/js-icons.phtml @@ -27,6 +27,7 @@ $list = [ 'status-pending', 'status-ready', 'status-unavailable', + 'status-uncertain', 'status-unknown', 'ui-failure', 'ui-success', From 239c360c2a014d46c494216f3243acb00a8a4a8b Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Fri, 6 Sep 2024 11:13:01 -0400 Subject: [PATCH 10/29] Fix broken tests. --- .../src/VuFindTest/Mink/HoldingsTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/HoldingsTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/HoldingsTest.php index 6a48e8e428d..723f62560da 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/HoldingsTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/HoldingsTest.php @@ -184,7 +184,10 @@ public function testItemStatus( ); $this->assertEquals( 'Main Library', - $this->findCssAndGetText($page, '.result-body .callnumAndLocation .groupLocation .text-success') + $this->findCssAndGetText( + $page, + '.result-body .callnumAndLocation .groupLocation .text-' . $expectedType + ) ); } } else { @@ -196,8 +199,8 @@ public function testItemStatus( } else { // No extra items to care for: if ('group' === $multipleLocations) { - // Unknown status displays as warning: - $type = null === $availability ? 'warning' : 'danger'; + // Unknown status displays as muted: + $type = null === $availability ? 'muted' : 'danger'; $selector = ".result-body .callnumAndLocation .groupLocation .text-$type"; } else { $selector = '.result-body .callnumAndLocation .location'; From cfaa055c585bef1635017de0c13870da6b830e29 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Mon, 9 Sep 2024 11:58:58 +0200 Subject: [PATCH 11/29] Return location list's icons and classes in ajax response. --- .../VuFind/AjaxHandler/GetItemStatuses.php | 2 + .../View/Helper/Root/AvailabilityStatus.php | 49 +++++++++++++++++++ themes/bootstrap3/js/check_item_statuses.js | 10 +--- .../templates/search/results-scripts.phtml | 19 ------- themes/bootstrap5/js/check_item_statuses.js | 10 +--- .../templates/search/results-scripts.phtml | 19 ------- 6 files changed, 55 insertions(+), 54 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index a02562e2d6a..c4ecdff2984 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -368,6 +368,8 @@ protected function getItemStatusGroup($record, $callnumberSetting) 'callnumbers' => htmlentities($locationCallnumbers, ENT_COMPAT, 'UTF-8'), 'callnumber_handler' => $callnumberHandler, + 'icon' => $this->renderer->availabilityStatus()->getIcon($locationAvailability), + 'class' => $this->renderer->availabilityStatus()->getClass($locationAvailability), ]; $locationList[] = $locationInfo; } diff --git a/module/VuFind/src/VuFind/View/Helper/Root/AvailabilityStatus.php b/module/VuFind/src/VuFind/View/Helper/Root/AvailabilityStatus.php index dcd147d216b..f7892d88c4b 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/AvailabilityStatus.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/AvailabilityStatus.php @@ -70,6 +70,34 @@ class AvailabilityStatus extends \Laminas\View\Helper\AbstractHelper */ protected string $classUnknown = 'text-muted'; + /** + * Icon for available items. + * + * @var string + */ + protected string $iconAvailable = 'status-available'; + + /** + * Icon for unavailable items. + * + * @var string + */ + protected string $iconUnavailable = 'status-unavailable'; + + /** + * Icon for items where status is uncertain. + * + * @var string + */ + protected string $iconUncertain = 'status-uncertain'; + + /** + * Icon for items where status is unknown. + * + * @var string + */ + protected string $iconUnknown = 'status-unknown'; + /** * Message cache * @@ -98,6 +126,27 @@ public function getClass(AvailabilityStatusInterface $availabilityStatus): strin return $this->classUncertain; } + /** + * Get icon name for availability status. + * + * @param AvailabilityStatusInterface $availabilityStatus Availability Status + * + * @return string + */ + public function getIcon(AvailabilityStatusInterface $availabilityStatus): string + { + if ($availabilityStatus->is(\VuFind\ILS\Logic\AvailabilityStatusInterface::STATUS_UNAVAILABLE)) { + return $this->iconUnavailable; + } + if ($availabilityStatus->is(\VuFind\ILS\Logic\AvailabilityStatusInterface::STATUS_AVAILABLE)) { + return $this->iconAvailable; + } + if ($availabilityStatus->is(\VuFind\ILS\Logic\AvailabilityStatusInterface::STATUS_UNKNOWN)) { + return $this->iconUnknown; + } + return $this->iconUncertain; + } + /** * Render ajax status. * diff --git a/themes/bootstrap3/js/check_item_statuses.js b/themes/bootstrap3/js/check_item_statuses.js index 47c6191c66a..688a13a3289 100644 --- a/themes/bootstrap3/js/check_item_statuses.js +++ b/themes/bootstrap3/js/check_item_statuses.js @@ -61,15 +61,9 @@ VuFind.register('itemStatuses', function ItemStatuses() { el.querySelectorAll('.callnumber,.hideIfDetailed,.location').forEach((e) => e.classList.add('hidden')); var locationListHTML = ""; for (var x = 0; x < result.locationList.length; x++) { - var availability = result.locationList[x].availability; - var statusIcon = - availability === 'true' ? 'available' - : availability === 'false' ? 'unavailable' - : availability; - locationListHTML += '
'; - locationListHTML += '' - + VuFind.icon('status-' + statusIcon) + locationListHTML += '' + + VuFind.icon(result.locationList[x].icon) + result.locationList[x].location + ' '; locationListHTML += '
'; diff --git a/themes/bootstrap3/templates/search/results-scripts.phtml b/themes/bootstrap3/templates/search/results-scripts.phtml index 7d8e2e4ad56..a18328cd41e 100644 --- a/themes/bootstrap3/templates/search/results-scripts.phtml +++ b/themes/bootstrap3/templates/search/results-scripts.phtml @@ -14,22 +14,3 @@ if (($this->listViewOption ?? 'full') !== 'full') { if ($this->jsResults ?? false) { $this->headScript()->appendFile('search.js'); } - -$statuses = [ - \VuFind\ILS\Logic\AvailabilityStatus::STATUS_AVAILABLE, - \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNAVAILABLE, - \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNKNOWN, - \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNCERTAIN, -]; - -$availabilityStatuses = []; -foreach ($statuses as $status) { - $status = new \VuFind\ILS\Logic\AvailabilityStatus($status); - $availabilityClasses[$status->availabilityAsString()] = - $this->availabilityStatus()->getClass($status); -} - -$availabilityClassesJson = json_encode($availabilityClasses); -$this->headScript()->appendScript(<< e.classList.add('hidden')); var locationListHTML = ""; for (var x = 0; x < result.locationList.length; x++) { - var availability = result.locationList[x].availability; - var statusIcon = - availability === 'true' ? 'available' - : availability === 'false' ? 'unavailable' - : availability; - locationListHTML += '
'; - locationListHTML += '' - + VuFind.icon('status-' + statusIcon) + locationListHTML += '' + + VuFind.icon(result.locationList[x].icon) + result.locationList[x].location + ' '; locationListHTML += '
'; diff --git a/themes/bootstrap5/templates/search/results-scripts.phtml b/themes/bootstrap5/templates/search/results-scripts.phtml index 7d8e2e4ad56..a18328cd41e 100644 --- a/themes/bootstrap5/templates/search/results-scripts.phtml +++ b/themes/bootstrap5/templates/search/results-scripts.phtml @@ -14,22 +14,3 @@ if (($this->listViewOption ?? 'full') !== 'full') { if ($this->jsResults ?? false) { $this->headScript()->appendFile('search.js'); } - -$statuses = [ - \VuFind\ILS\Logic\AvailabilityStatus::STATUS_AVAILABLE, - \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNAVAILABLE, - \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNKNOWN, - \VuFind\ILS\Logic\AvailabilityStatus::STATUS_UNCERTAIN, -]; - -$availabilityStatuses = []; -foreach ($statuses as $status) { - $status = new \VuFind\ILS\Logic\AvailabilityStatus($status); - $availabilityClasses[$status->availabilityAsString()] = - $this->availabilityStatus()->getClass($status); -} - -$availabilityClassesJson = json_encode($availabilityClasses); -$this->headScript()->appendScript(<< Date: Mon, 9 Sep 2024 13:47:05 +0200 Subject: [PATCH 12/29] Removed unused 'availabilityClasses' declaration from check_item_statuses.js --- themes/bootstrap3/js/check_item_statuses.js | 2 +- themes/bootstrap5/js/check_item_statuses.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/bootstrap3/js/check_item_statuses.js b/themes/bootstrap3/js/check_item_statuses.js index 688a13a3289..867c78a39ad 100644 --- a/themes/bootstrap3/js/check_item_statuses.js +++ b/themes/bootstrap3/js/check_item_statuses.js @@ -1,4 +1,4 @@ -/*global AjaxRequestQueue, VuFind, availabilityClasses */ +/*global AjaxRequestQueue, VuFind */ VuFind.register('itemStatuses', function ItemStatuses() { var _checkItemHandlers = {}; diff --git a/themes/bootstrap5/js/check_item_statuses.js b/themes/bootstrap5/js/check_item_statuses.js index 688a13a3289..867c78a39ad 100644 --- a/themes/bootstrap5/js/check_item_statuses.js +++ b/themes/bootstrap5/js/check_item_statuses.js @@ -1,4 +1,4 @@ -/*global AjaxRequestQueue, VuFind, availabilityClasses */ +/*global AjaxRequestQueue, VuFind */ VuFind.register('itemStatuses', function ItemStatuses() { var _checkItemHandlers = {}; From 34cc7bea178c121abf08bf0b442373203b12cbc3 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Fri, 13 Sep 2024 15:03:46 +0200 Subject: [PATCH 13/29] Server side rendering of location list and callnumbers. --- .../VuFind/AjaxHandler/GetItemStatuses.php | 62 +++++++++++++------ .../VuFind/ILS/Logic/AvailabilityStatus.php | 4 +- themes/bootstrap3/js/check_item_statuses.js | 39 +----------- .../templates/ajax/itemCallnumber.phtml | 5 ++ .../templates/ajax/itemLocationList.phtml | 12 ++++ themes/bootstrap5/js/check_item_statuses.js | 39 +----------- .../templates/ajax/itemCallnumber.phtml | 5 ++ .../templates/ajax/itemLocationList.phtml | 12 ++++ 8 files changed, 84 insertions(+), 94 deletions(-) create mode 100644 themes/bootstrap3/templates/ajax/itemCallnumber.phtml create mode 100644 themes/bootstrap3/templates/ajax/itemLocationList.phtml create mode 100644 themes/bootstrap5/templates/ajax/itemCallnumber.phtml create mode 100644 themes/bootstrap5/templates/ajax/itemLocationList.phtml diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index c4ecdff2984..bb6caba4b50 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -232,6 +232,43 @@ protected function formatCallNo($prefix, $callnumber) return !empty($prefix) ? $prefix . '::::' . $callnumber : $callnumber; } + /** + * Render the callnumber HTML. + * + * @param string $callnumberSetting The callnumber mode setting + * @param string|array $callnumbers Callnumbers to render + * + * @return string + */ + protected function renderCallnumbers(string $callnumberSetting, string|array $callnumbers) : string + { + $html = []; + if(is_string($callnumbers)) { + $callnumbers = explode(",\t", $callnumbers); + } + + $callnumberHandler = $this->getCallnumberHandler($callnumbers, $callnumberSetting); + foreach($callnumbers as $number) { + // @TODO: evaluate usage of pickValue() and formatCallNo() + // > are these explodes needed here or is refactoring possible? + $displayCallNumber = $actualCallNumber = $number; + + $parts = explode('::::', $number); + if (count($parts) > 1) { + $displayCallNumber = $parts[0] . ' ' . $parts[1]; + $actualCallNumber = $parts[1]; + } + + $html[] = $this->renderer->render('ajax/itemCallnumber', [ + 'actualCallNumber' => $actualCallNumber, + 'displayCallNumber' => $displayCallNumber, + 'callnumberHandler' => $callnumberHandler, + ]); + } + + return implode(",\t", $html); + } + /** * Support method for getItemStatuses() -- process a single bibliographic record * for location settings other than "group". @@ -267,11 +304,6 @@ protected function getItemStatus( } } - $callnumberHandler = $this->getCallnumberHandler( - $callNumbers, - $callnumberSetting - ); - // Determine call number string based on findings: $callNumber = $this->pickValue( $callNumbers, @@ -309,8 +341,7 @@ protected function getItemStatus( 'reserve' => $reserve ? 'true' : 'false', 'reserve_message' => $this->translate($reserve ? 'on_reserve' : 'Not On Reserve'), - 'callnumber' => htmlentities($callNumber, ENT_COMPAT, 'UTF-8'), - 'callnumber_handler' => $callnumberHandler, + 'callnumber' => $this->renderCallnumbers($callnumberSetting, $callNumber), ]; } @@ -343,10 +374,6 @@ protected function getItemStatusGroup($record, $callnumberSetting) foreach ($locations as $location => $details) { $locationCallnumbers = array_unique($details['callnumbers']); // Determine call number string based on findings: - $callnumberHandler = $this->getCallnumberHandler( - $locationCallnumbers, - $callnumberSetting - ); $locationCallnumbers = $this->pickValue( $locationCallnumbers, $callnumberSetting, @@ -355,21 +382,16 @@ protected function getItemStatusGroup($record, $callnumberSetting) // Get combined availability for location $locationStatus = $this->availabilityStatusManager->combine($details['items']); - $locationAvailability = $locationStatus['availability']; $locationInfo = [ - 'availability' => - $locationAvailability->availabilityAsString(), + 'availability' => $locationStatus['availability'], 'location' => htmlentities( $this->translateWithPrefix('location_', $location), ENT_COMPAT, 'UTF-8' ), - 'callnumbers' => - htmlentities($locationCallnumbers, ENT_COMPAT, 'UTF-8'), - 'callnumber_handler' => $callnumberHandler, - 'icon' => $this->renderer->availabilityStatus()->getIcon($locationAvailability), - 'class' => $this->renderer->availabilityStatus()->getClass($locationAvailability), + 'callnumber' => + $this->renderCallnumbers($callnumberSetting, $locationCallnumbers), ]; $locationList[] = $locationInfo; } @@ -386,7 +408,7 @@ protected function getItemStatusGroup($record, $callnumberSetting) 'availability' => $combinedAvailability->availabilityAsString(), 'availability_message' => $this->getAvailabilityMessage($combinedAvailability), 'location' => false, - 'locationList' => $locationList, + 'locationList' => $this->renderer->render('ajax/itemLocationList', ['locationList' => $locationList]), 'reserve' => $reserve ? 'true' : 'false', 'reserve_message' => $this->translate($reserve ? 'on_reserve' : 'Not On Reserve'), diff --git a/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php b/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php index 34067c693c5..0c7f778edfe 100644 --- a/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php +++ b/module/VuFind/src/VuFind/ILS/Logic/AvailabilityStatus.php @@ -171,9 +171,9 @@ public function availabilityAsString(): string { switch ($this->availability) { case AvailabilityStatusInterface::STATUS_UNAVAILABLE: - return 'false'; + return 'unavailable'; case AvailabilityStatusInterface::STATUS_AVAILABLE: - return 'true'; + return 'available'; case AvailabilityStatusInterface::STATUS_UNKNOWN: return 'unknown'; default: diff --git a/themes/bootstrap3/js/check_item_statuses.js b/themes/bootstrap3/js/check_item_statuses.js index 867c78a39ad..0cc89e78aad 100644 --- a/themes/bootstrap3/js/check_item_statuses.js +++ b/themes/bootstrap3/js/check_item_statuses.js @@ -4,26 +4,6 @@ VuFind.register('itemStatuses', function ItemStatuses() { var _checkItemHandlers = {}; var _handlerUrls = {}; - function formatCallnumbers(callnumber, callnumber_handler) { - var cns = callnumber.split(',\t'); - for (var i = 0; i < cns.length; i++) { - // If the call number has a special delimiter, it indicates a prefix that - // should be used for display but not for sorting/searching. - var actualCallNumber = cns[i]; - var displayCallNumber = cns[i]; - var parts = cns[i].split('::::'); - if (parts.length > 1) { - displayCallNumber = parts[0] + " " + parts[1]; - actualCallNumber = parts[1]; - } - - cns[i] = callnumber_handler - ? '' + displayCallNumber + '' - : displayCallNumber; - } - return cns.join(',\t'); - } - function displayItemStatus(result, el) { el.querySelectorAll('.status').forEach((status) => { status.innerHTML = result.availability_message; @@ -57,29 +37,16 @@ VuFind.register('itemStatuses', function ItemStatuses() { // No data is available -- hide the entire status area: el.querySelectorAll('.callnumAndLocation,.status').forEach((e) => e.classList.add('hidden')); } else if (result.locationList) { - // We have multiple locations -- build appropriate HTML and hide unwanted labels: + // We have multiple locations - hide unwanted labels and display HTML from response: el.querySelectorAll('.callnumber,.hideIfDetailed,.location').forEach((e) => e.classList.add('hidden')); - var locationListHTML = ""; - for (var x = 0; x < result.locationList.length; x++) { - locationListHTML += '
'; - locationListHTML += '' - + VuFind.icon(result.locationList[x].icon) - + result.locationList[x].location - + ' '; - locationListHTML += '
'; - locationListHTML += '
'; - locationListHTML += (result.locationList[x].callnumbers) - ? formatCallnumbers(result.locationList[x].callnumbers, result.locationList[x].callnumber_handler) : ''; - locationListHTML += '
'; - } el.querySelectorAll('.locationDetails').forEach((locationDetails) => { locationDetails.classList.remove('hidden'); - locationDetails.innerHTML = locationListHTML; + locationDetails.innerHTML = result.locationList; }); } else { // Default case -- load call number and location into appropriate containers: el.querySelectorAll('.callnumber').forEach((callnumber) => { - callnumber.innerHTML = formatCallnumbers(result.callnumber, result.callnumber_handler) + '
'; + callnumber.innerHTML = result.callnumber + '
'; }); el.querySelectorAll('.location').forEach((location) => { location.innerHTML = result.reserve === 'true' diff --git a/themes/bootstrap3/templates/ajax/itemCallnumber.phtml b/themes/bootstrap3/templates/ajax/itemCallnumber.phtml new file mode 100644 index 00000000000..94cbf14bbc5 --- /dev/null +++ b/themes/bootstrap3/templates/ajax/itemCallnumber.phtml @@ -0,0 +1,5 @@ +callnumberHandler): ?> + escapeHtml($this->displayCallNumber)?> + + displayCallNumber?> + diff --git a/themes/bootstrap3/templates/ajax/itemLocationList.phtml b/themes/bootstrap3/templates/ajax/itemLocationList.phtml new file mode 100644 index 00000000000..35cf01c2042 --- /dev/null +++ b/themes/bootstrap3/templates/ajax/itemLocationList.phtml @@ -0,0 +1,12 @@ +availabilityStatus(); ?> +locationList as $location): ?> +
+ + icon($availabilityStatus->getIcon($location['availability']))?> + escapeHtml($location['location'])?> + +
+
+ +
+ \ No newline at end of file diff --git a/themes/bootstrap5/js/check_item_statuses.js b/themes/bootstrap5/js/check_item_statuses.js index 867c78a39ad..0cc89e78aad 100644 --- a/themes/bootstrap5/js/check_item_statuses.js +++ b/themes/bootstrap5/js/check_item_statuses.js @@ -4,26 +4,6 @@ VuFind.register('itemStatuses', function ItemStatuses() { var _checkItemHandlers = {}; var _handlerUrls = {}; - function formatCallnumbers(callnumber, callnumber_handler) { - var cns = callnumber.split(',\t'); - for (var i = 0; i < cns.length; i++) { - // If the call number has a special delimiter, it indicates a prefix that - // should be used for display but not for sorting/searching. - var actualCallNumber = cns[i]; - var displayCallNumber = cns[i]; - var parts = cns[i].split('::::'); - if (parts.length > 1) { - displayCallNumber = parts[0] + " " + parts[1]; - actualCallNumber = parts[1]; - } - - cns[i] = callnumber_handler - ? '' + displayCallNumber + '' - : displayCallNumber; - } - return cns.join(',\t'); - } - function displayItemStatus(result, el) { el.querySelectorAll('.status').forEach((status) => { status.innerHTML = result.availability_message; @@ -57,29 +37,16 @@ VuFind.register('itemStatuses', function ItemStatuses() { // No data is available -- hide the entire status area: el.querySelectorAll('.callnumAndLocation,.status').forEach((e) => e.classList.add('hidden')); } else if (result.locationList) { - // We have multiple locations -- build appropriate HTML and hide unwanted labels: + // We have multiple locations - hide unwanted labels and display HTML from response: el.querySelectorAll('.callnumber,.hideIfDetailed,.location').forEach((e) => e.classList.add('hidden')); - var locationListHTML = ""; - for (var x = 0; x < result.locationList.length; x++) { - locationListHTML += '
'; - locationListHTML += '' - + VuFind.icon(result.locationList[x].icon) - + result.locationList[x].location - + ' '; - locationListHTML += '
'; - locationListHTML += '
'; - locationListHTML += (result.locationList[x].callnumbers) - ? formatCallnumbers(result.locationList[x].callnumbers, result.locationList[x].callnumber_handler) : ''; - locationListHTML += '
'; - } el.querySelectorAll('.locationDetails').forEach((locationDetails) => { locationDetails.classList.remove('hidden'); - locationDetails.innerHTML = locationListHTML; + locationDetails.innerHTML = result.locationList; }); } else { // Default case -- load call number and location into appropriate containers: el.querySelectorAll('.callnumber').forEach((callnumber) => { - callnumber.innerHTML = formatCallnumbers(result.callnumber, result.callnumber_handler) + '
'; + callnumber.innerHTML = result.callnumber + '
'; }); el.querySelectorAll('.location').forEach((location) => { location.innerHTML = result.reserve === 'true' diff --git a/themes/bootstrap5/templates/ajax/itemCallnumber.phtml b/themes/bootstrap5/templates/ajax/itemCallnumber.phtml new file mode 100644 index 00000000000..94cbf14bbc5 --- /dev/null +++ b/themes/bootstrap5/templates/ajax/itemCallnumber.phtml @@ -0,0 +1,5 @@ +callnumberHandler): ?> + escapeHtml($this->displayCallNumber)?> + + displayCallNumber?> + diff --git a/themes/bootstrap5/templates/ajax/itemLocationList.phtml b/themes/bootstrap5/templates/ajax/itemLocationList.phtml new file mode 100644 index 00000000000..35cf01c2042 --- /dev/null +++ b/themes/bootstrap5/templates/ajax/itemLocationList.phtml @@ -0,0 +1,12 @@ +availabilityStatus(); ?> +locationList as $location): ?> +
+ + icon($availabilityStatus->getIcon($location['availability']))?> + escapeHtml($location['location'])?> + +
+
+ +
+ \ No newline at end of file From 3f6a1fbd430a9bd4480872c40561b81703971e98 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Fri, 13 Sep 2024 15:09:32 +0200 Subject: [PATCH 14/29] Fixed code style --- module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 8 ++++---- themes/bootstrap3/templates/ajax/itemLocationList.phtml | 2 +- themes/bootstrap5/templates/ajax/itemLocationList.phtml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index bb6caba4b50..fbf22fcde5a 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -236,19 +236,19 @@ protected function formatCallNo($prefix, $callnumber) * Render the callnumber HTML. * * @param string $callnumberSetting The callnumber mode setting - * @param string|array $callnumbers Callnumbers to render + * @param string|array $callnumbers Callnumbers to render * * @return string */ - protected function renderCallnumbers(string $callnumberSetting, string|array $callnumbers) : string + protected function renderCallnumbers(string $callnumberSetting, string|array $callnumbers): string { $html = []; - if(is_string($callnumbers)) { + if (is_string($callnumbers)) { $callnumbers = explode(",\t", $callnumbers); } $callnumberHandler = $this->getCallnumberHandler($callnumbers, $callnumberSetting); - foreach($callnumbers as $number) { + foreach ($callnumbers as $number) { // @TODO: evaluate usage of pickValue() and formatCallNo() // > are these explodes needed here or is refactoring possible? $displayCallNumber = $actualCallNumber = $number; diff --git a/themes/bootstrap3/templates/ajax/itemLocationList.phtml b/themes/bootstrap3/templates/ajax/itemLocationList.phtml index 35cf01c2042..2fe2a38a6f1 100644 --- a/themes/bootstrap3/templates/ajax/itemLocationList.phtml +++ b/themes/bootstrap3/templates/ajax/itemLocationList.phtml @@ -1,5 +1,5 @@ availabilityStatus(); ?> -locationList as $location): ?> +locationList as $location): ?>
icon($availabilityStatus->getIcon($location['availability']))?> diff --git a/themes/bootstrap5/templates/ajax/itemLocationList.phtml b/themes/bootstrap5/templates/ajax/itemLocationList.phtml index 35cf01c2042..2fe2a38a6f1 100644 --- a/themes/bootstrap5/templates/ajax/itemLocationList.phtml +++ b/themes/bootstrap5/templates/ajax/itemLocationList.phtml @@ -1,5 +1,5 @@ availabilityStatus(); ?> -locationList as $location): ?> +locationList as $location): ?>
icon($availabilityStatus->getIcon($location['availability']))?> From c3d3ef61ffdef115e366dee86bd5a7d22ae64aa7 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Fri, 13 Sep 2024 15:14:39 +0200 Subject: [PATCH 15/29] Fixed code styling --- module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index fbf22fcde5a..76562dba563 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -255,7 +255,7 @@ protected function renderCallnumbers(string $callnumberSetting, string|array $ca $parts = explode('::::', $number); if (count($parts) > 1) { - $displayCallNumber = $parts[0] . ' ' . $parts[1]; + $displayCallNumber = $parts[0] . ' ' . $parts[1]; $actualCallNumber = $parts[1]; } From cc0019902fe91654dcd6853ae0428aa3acd32816 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Fri, 13 Sep 2024 15:22:30 +0200 Subject: [PATCH 16/29] code style fix --- Vagrantfile | 8 ++++---- config/vufind/Demo.ini | 3 ++- module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 5023ac393eb..64a142e0254 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -27,7 +27,7 @@ Vagrant.configure("2") do |config| # Network configuration to forward ports. config.vm.network :forwarded_port, guest: 80, host: 4567 config.vm.network :forwarded_port, guest: 8983, host: 4568 - config.vm.synced_folder ".", "/vagrant", :owner => 'vagrant' +# config.vm.synced_folder ".", "/vagrant", :owner => 'vagrant' # Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the @@ -55,7 +55,7 @@ Vagrant.configure("2") do |config| # Check out and set up VuFind. mkdir -p /vufindlocal/cache/cli /vufindlocal/config/vufind chown -R vagrant:vagrant /vufindlocal - su - vagrant -c 'cd /vagrant && composer install && php install.php --non-interactive --overridedir=/vufindlocal' + su - vagrant -c 'cd /usr/local/vufind/vufind_fork && composer install && php install.php --non-interactive --overridedir=/vufindlocal' ln -s /vufindlocal/httpd-vufind.conf /etc/apache2/conf-enabled/vufind.conf a2enmod rewrite systemctl restart apache2 @@ -65,7 +65,7 @@ Vagrant.configure("2") do |config| chmod 777 /vufindlocal/cache/cli # Set up profile for command line. - echo export VUFIND_HOME=/vagrant > /etc/profile.d/vufind.sh - echo export VUFIND_LOCAL_DIR=/vufindlocal >> /etc/profile.d/vufind.sh + sudo echo export VUFIND_HOME=/usr/local/vufind/vufind_fork > /etc/profile.d/vufind.sh + sudo echo export VUFIND_LOCAL_DIR=/vufindlocal >> /etc/profile.d/vufind.sh SHELL end diff --git a/config/vufind/Demo.ini b/config/vufind/Demo.ini index 072695824ce..27b4f9f617c 100644 --- a/config/vufind/Demo.ini +++ b/config/vufind/Demo.ini @@ -91,8 +91,9 @@ services[] = 'custom' ; with locations of "foo" and "bar" respectively. For the second item the availability will be ; returned as an instance of AvailabilityStatus and with the extra status information "{"extraInfo": true}"; ; All other details will be randomized. -;[StaticHoldings] +[StaticHoldings] ;1234 = '[{"location": "foo"}, {"location": "bar", "use_status_class": true, "extraStatusInformation": {"extraInfo": true}}]' +testsample1 = "[{\"barcode\":\"12345678\",\"availability\":0,\"status\":\"Foo\",\"location\":\"Test Location\",\"locationhref\":false,\"reserve\":\"N\",\"callnumber\":\"Test Call Number\",\"duedate\":\"\",\"is_holdable\":true,\"addLink\":true,\"addStorageRetrievalRequestLink\":\"check\",\"addILLRequestLink\":\"check\",\"__electronic__\":false},{\"barcode\":\"12345678\",\"availability\":0,\"status\":\"Foo\",\"location\":\"main\",\"locationhref\":false,\"reserve\":\"N\",\"callnumber\":\"Test Call Number\",\"duedate\":\"\",\"is_holdable\":true,\"addLink\":true,\"addStorageRetrievalRequestLink\":\"check\",\"addILLRequestLink\":\"check\",\"__electronic__\":false},{\"barcode\":\"12345678\",\"availability\":2,\"status\":\"Check with Staff\",\"location\":\"main\",\"locationhref\":false,\"reserve\":\"N\",\"callnumber\":\"Test Call Number\",\"duedate\":\"\",\"is_holdable\":true,\"addLink\":true,\"addStorageRetrievalRequestLink\":\"check\",\"addILLRequestLink\":\"check\",\"__electronic__\":false}]" ; This section controls how often the Demo driver simulates failure for various ; features. The key is the method name that might fail; the value is the probability diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 76562dba563..01fe4bef3ac 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -47,6 +47,7 @@ use function count; use function in_array; use function is_array; +use function is_string; /** * "Get Item Status" AJAX handler From 264487bcc981e1a12bc15da088b7ec403ae134a0 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Mon, 23 Sep 2024 09:06:43 +0200 Subject: [PATCH 17/29] Revert unwanted changes --- Vagrantfile | 6 +++--- config/vufind/Demo.ini | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 64a142e0254..9418ac788ef 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -27,7 +27,7 @@ Vagrant.configure("2") do |config| # Network configuration to forward ports. config.vm.network :forwarded_port, guest: 80, host: 4567 config.vm.network :forwarded_port, guest: 8983, host: 4568 -# config.vm.synced_folder ".", "/vagrant", :owner => 'vagrant' + config.vm.synced_folder ".", "/vagrant", :owner => 'vagrant' # Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the @@ -55,7 +55,7 @@ Vagrant.configure("2") do |config| # Check out and set up VuFind. mkdir -p /vufindlocal/cache/cli /vufindlocal/config/vufind chown -R vagrant:vagrant /vufindlocal - su - vagrant -c 'cd /usr/local/vufind/vufind_fork && composer install && php install.php --non-interactive --overridedir=/vufindlocal' + su - vagrant -c 'cd /vagrant && composer install && php install.php --non-interactive --overridedir=/vufindlocal' ln -s /vufindlocal/httpd-vufind.conf /etc/apache2/conf-enabled/vufind.conf a2enmod rewrite systemctl restart apache2 @@ -65,7 +65,7 @@ Vagrant.configure("2") do |config| chmod 777 /vufindlocal/cache/cli # Set up profile for command line. - sudo echo export VUFIND_HOME=/usr/local/vufind/vufind_fork > /etc/profile.d/vufind.sh + sudo echo export VUFIND_HOME=/vagrant > /etc/profile.d/vufind.sh sudo echo export VUFIND_LOCAL_DIR=/vufindlocal >> /etc/profile.d/vufind.sh SHELL end diff --git a/config/vufind/Demo.ini b/config/vufind/Demo.ini index 27b4f9f617c..072695824ce 100644 --- a/config/vufind/Demo.ini +++ b/config/vufind/Demo.ini @@ -91,9 +91,8 @@ services[] = 'custom' ; with locations of "foo" and "bar" respectively. For the second item the availability will be ; returned as an instance of AvailabilityStatus and with the extra status information "{"extraInfo": true}"; ; All other details will be randomized. -[StaticHoldings] +;[StaticHoldings] ;1234 = '[{"location": "foo"}, {"location": "bar", "use_status_class": true, "extraStatusInformation": {"extraInfo": true}}]' -testsample1 = "[{\"barcode\":\"12345678\",\"availability\":0,\"status\":\"Foo\",\"location\":\"Test Location\",\"locationhref\":false,\"reserve\":\"N\",\"callnumber\":\"Test Call Number\",\"duedate\":\"\",\"is_holdable\":true,\"addLink\":true,\"addStorageRetrievalRequestLink\":\"check\",\"addILLRequestLink\":\"check\",\"__electronic__\":false},{\"barcode\":\"12345678\",\"availability\":0,\"status\":\"Foo\",\"location\":\"main\",\"locationhref\":false,\"reserve\":\"N\",\"callnumber\":\"Test Call Number\",\"duedate\":\"\",\"is_holdable\":true,\"addLink\":true,\"addStorageRetrievalRequestLink\":\"check\",\"addILLRequestLink\":\"check\",\"__electronic__\":false},{\"barcode\":\"12345678\",\"availability\":2,\"status\":\"Check with Staff\",\"location\":\"main\",\"locationhref\":false,\"reserve\":\"N\",\"callnumber\":\"Test Call Number\",\"duedate\":\"\",\"is_holdable\":true,\"addLink\":true,\"addStorageRetrievalRequestLink\":\"check\",\"addILLRequestLink\":\"check\",\"__electronic__\":false}]" ; This section controls how often the Demo driver simulates failure for various ; features. The key is the method name that might fail; the value is the probability From 47d57daa7ec64ceebf6c9b10ed4c0b48f17b23f5 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Fri, 4 Oct 2024 12:45:37 +0200 Subject: [PATCH 18/29] Refactored pickValue() to return an array. Use associative array for callnumbers instead of a formatted string. --- .../VuFind/AjaxHandler/GetItemStatuses.php | 92 +++++++------------ .../templates/ajax/itemCallnumber.phtml | 4 +- 2 files changed, 37 insertions(+), 59 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 01fe4bef3ac..c3b9a172466 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -128,7 +128,7 @@ protected function translateList($transPrefix, $list) { $transList = []; foreach ($list as $current) { - $transList[] = $this->translateWithPrefix($transPrefix, $current); + $transList[] = is_string($current) ? $this->translateWithPrefix($transPrefix, $current) : $current; } return $transList; } @@ -141,36 +141,27 @@ protected function translateList($transPrefix, $list) * @param string $mode config.ini setting -- first, all or msg * @param string $msg Message to display if $mode == "msg" * @param string $transPrefix Translator prefix to apply to values (false to - * omit translation of values) + * omit translation of values) * - * @return string + * @return array */ protected function pickValue($rawList, $mode, $msg, $transPrefix = false) { // Make sure array contains only unique values: - $list = array_unique($rawList); - - // If there is only one value in the list, or if we're in "first" mode, - // send back the first list value: - if ($mode == 'first' || count($list) == 1) { - if ($transPrefix) { - return $this->translateWithPrefix($transPrefix, $list[0]); - } - return $list[0]; - } elseif (count($list) == 0) { - // Empty list? Return a blank string: - return ''; - } elseif ($mode == 'all') { - // All values mode? Return comma-separated values: - return implode( - ",\t", - $transPrefix ? $this->translateList($transPrefix, $list) : $list - ); - } else { + // array unique for multidimensional arrays due to callnumber array, + // can be slow for larger/more complex arrays + $list = array_map("unserialize", array_unique(array_map("serialize", $rawList))); + + // If we're in "first" mode, reduce list to first list value: + if ($mode == 'first' && count($list) > 0) { + $list = [$list[0]]; + } elseif ($mode == 'msg' && count($list) > 1){ // Message mode? Return the specified message, translated to the // appropriate language. - return $this->translate($msg); + return [$this->translate($msg)]; } + + return $transPrefix ? $this->translateList($transPrefix, $list) : $list; } /** @@ -220,49 +211,43 @@ protected function reduceServices(array $rawServices) } /** - * Create a delimited version of the call number to allow the Javascript code - * to handle the prefix appropriately. + * Create an array with the callnumber and prefix of the given item. * - * @param string $prefix Callnumber prefix or empty string. - * @param string $callnumber Main call number. + * @param array $item Item's holding data. * - * @return string + * @return array Associative array with the keys 'prefix' and 'callnumber' */ - protected function formatCallNo($prefix, $callnumber) + protected function getCallNumberArray(array $item): array { - return !empty($prefix) ? $prefix . '::::' . $callnumber : $callnumber; + return [ + 'prefix' => $item['callnumber_prefix'] ?? '', + 'callnumber' => $item['callnumber'] + ]; } /** * Render the callnumber HTML. * - * @param string $callnumberSetting The callnumber mode setting - * @param string|array $callnumbers Callnumbers to render + * @param string $callnumberSetting The callnumber mode setting + * @param array $callnumbers Callnumbers to render * * @return string */ - protected function renderCallnumbers(string $callnumberSetting, string|array $callnumbers): string + protected function renderCallnumbers(string $callnumberSetting, array $callnumbers): string { $html = []; - if (is_string($callnumbers)) { - $callnumbers = explode(",\t", $callnumbers); - } $callnumberHandler = $this->getCallnumberHandler($callnumbers, $callnumberSetting); foreach ($callnumbers as $number) { - // @TODO: evaluate usage of pickValue() and formatCallNo() - // > are these explodes needed here or is refactoring possible? - $displayCallNumber = $actualCallNumber = $number; - - $parts = explode('::::', $number); - if (count($parts) > 1) { - $displayCallNumber = $parts[0] . ' ' . $parts[1]; - $actualCallNumber = $parts[1]; + $displayCallnumber = $actualCallnumber = $number['callnumber']; + + if (!empty($number['prefix'])) { + $displayCallnumber = $number['prefix'] . ' ' . $displayCallnumber; } $html[] = $this->renderer->render('ajax/itemCallnumber', [ - 'actualCallNumber' => $actualCallNumber, - 'displayCallNumber' => $displayCallNumber, + 'actualCallnumber' => $actualCallnumber, + 'displayCallnumber' => $displayCallnumber, 'callnumberHandler' => $callnumberHandler, ]); } @@ -293,10 +278,7 @@ protected function getItemStatus( $services = []; foreach ($record as $info) { // Store call number/location info: - $callNumbers[] = $this->formatCallNo( - $info['callnumber_prefix'] ?? '', - $info['callnumber'] - ); + $callNumbers[] = $this->getCallNumberArray($info); $locations[] = $info['location']; // Store all available services @@ -337,7 +319,7 @@ protected function getItemStatus( 'id' => $record[0]['id'], 'availability' => $combinedAvailability->availabilityAsString(), 'availability_message' => $availabilityMessage, - 'location' => htmlentities($location, ENT_COMPAT, 'UTF-8'), + 'location' => htmlentities(implode(",\t", $location), ENT_COMPAT, 'UTF-8'), 'locationList' => false, 'reserve' => $reserve ? 'true' : 'false', 'reserve_message' @@ -363,20 +345,16 @@ protected function getItemStatusGroup($record, $callnumberSetting) $locations = []; foreach ($record as $info) { // Store call number/location info: - $locations[$info['location']]['callnumbers'][] = $this->formatCallNo( - $info['callnumber_prefix'] ?? '', - $info['callnumber'] - ); + $locations[$info['location']]['callnumbers'][] = $this->getCallNumberArray($info); $locations[$info['location']]['items'][] = $info; } // Build list split out by location: $locationList = []; foreach ($locations as $location => $details) { - $locationCallnumbers = array_unique($details['callnumbers']); // Determine call number string based on findings: $locationCallnumbers = $this->pickValue( - $locationCallnumbers, + $details['callnumbers'], $callnumberSetting, 'Multiple Call Numbers' ); diff --git a/themes/bootstrap5/templates/ajax/itemCallnumber.phtml b/themes/bootstrap5/templates/ajax/itemCallnumber.phtml index 94cbf14bbc5..b889445c7c5 100644 --- a/themes/bootstrap5/templates/ajax/itemCallnumber.phtml +++ b/themes/bootstrap5/templates/ajax/itemCallnumber.phtml @@ -1,5 +1,5 @@ callnumberHandler): ?> - escapeHtml($this->displayCallNumber)?> + escapeHtml($this->displayCallnumber)?> - displayCallNumber?> + displayCallnumber?> From 4d5522b2f70f5d42d13e6cf26cfe55682e12f1f9 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Fri, 4 Oct 2024 14:01:57 +0200 Subject: [PATCH 19/29] Added changes to bootstrap3 theme. Fixed code styling. --- module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 2 +- themes/bootstrap3/templates/ajax/itemCallnumber.phtml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index c3b9a172466..8b3ad71b911 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -155,7 +155,7 @@ protected function pickValue($rawList, $mode, $msg, $transPrefix = false) // If we're in "first" mode, reduce list to first list value: if ($mode == 'first' && count($list) > 0) { $list = [$list[0]]; - } elseif ($mode == 'msg' && count($list) > 1){ + } elseif ($mode == 'msg' && count($list) > 1) { // Message mode? Return the specified message, translated to the // appropriate language. return [$this->translate($msg)]; diff --git a/themes/bootstrap3/templates/ajax/itemCallnumber.phtml b/themes/bootstrap3/templates/ajax/itemCallnumber.phtml index 94cbf14bbc5..b889445c7c5 100644 --- a/themes/bootstrap3/templates/ajax/itemCallnumber.phtml +++ b/themes/bootstrap3/templates/ajax/itemCallnumber.phtml @@ -1,5 +1,5 @@ callnumberHandler): ?> - escapeHtml($this->displayCallNumber)?> + escapeHtml($this->displayCallnumber)?> - displayCallNumber?> + displayCallnumber?> From 72ad7e479233dc43ef793fb538d1228b407e541b Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Fri, 4 Oct 2024 14:17:15 +0200 Subject: [PATCH 20/29] Fixed code styling. --- module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 8b3ad71b911..5ffd9122c21 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -44,10 +44,14 @@ use VuFind\ILS\Logic\Holds; use VuFind\Session\Settings as SessionSettings; +use function array_map; +use function array_unique; use function count; use function in_array; use function is_array; use function is_string; +use function serialize; +use function unserialize; /** * "Get Item Status" AJAX handler From d1711b71d05110adf46f7dc4d3b998f453566ac7 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Fri, 4 Oct 2024 14:21:41 +0200 Subject: [PATCH 21/29] Fixed code styling. --- module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 5ffd9122c21..df64da60671 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -50,8 +50,6 @@ use function in_array; use function is_array; use function is_string; -use function serialize; -use function unserialize; /** * "Get Item Status" AJAX handler @@ -154,7 +152,7 @@ protected function pickValue($rawList, $mode, $msg, $transPrefix = false) // Make sure array contains only unique values: // array unique for multidimensional arrays due to callnumber array, // can be slow for larger/more complex arrays - $list = array_map("unserialize", array_unique(array_map("serialize", $rawList))); + $list = array_map('unserialize', array_unique(array_map('serialize', $rawList))); // If we're in "first" mode, reduce list to first list value: if ($mode == 'first' && count($list) > 0) { @@ -225,7 +223,7 @@ protected function getCallNumberArray(array $item): array { return [ 'prefix' => $item['callnumber_prefix'] ?? '', - 'callnumber' => $item['callnumber'] + 'callnumber' => $item['callnumber'], ]; } From 2da98bbd5a5b5ab3156e602ce81cbb2902355f62 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Thu, 10 Oct 2024 14:36:28 +0200 Subject: [PATCH 22/29] Added missing escapeHtml calls in templates. Code style update. --- Vagrantfile | 2 +- .../VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 10 +++++----- themes/bootstrap3/templates/ajax/itemCallnumber.phtml | 4 ++-- .../bootstrap3/templates/ajax/itemLocationList.phtml | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 9418ac788ef..3c89601d481 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -27,7 +27,7 @@ Vagrant.configure("2") do |config| # Network configuration to forward ports. config.vm.network :forwarded_port, guest: 80, host: 4567 config.vm.network :forwarded_port, guest: 8983, host: 4568 - config.vm.synced_folder ".", "/vagrant", :owner => 'vagrant' + config.vm.synced_folder ".", "/vagrant", :owner => 'vagrant' # Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index df64da60671..4a21b4d28e1 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -130,6 +130,7 @@ protected function translateList($transPrefix, $list) { $transList = []; foreach ($list as $current) { + // $current can be an array if pickValues() is called with callnumbers and a translation prefix $transList[] = is_string($current) ? $this->translateWithPrefix($transPrefix, $current) : $current; } return $transList; @@ -247,11 +248,10 @@ protected function renderCallnumbers(string $callnumberSetting, array $callnumbe $displayCallnumber = $number['prefix'] . ' ' . $displayCallnumber; } - $html[] = $this->renderer->render('ajax/itemCallnumber', [ - 'actualCallnumber' => $actualCallnumber, - 'displayCallnumber' => $displayCallnumber, - 'callnumberHandler' => $callnumberHandler, - ]); + $html[] = $this->renderer->render( + 'ajax/itemCallnumber', + compact($actualCallnumber, $displayCallnumber, $callnumberHandler) + ); } return implode(",\t", $html); diff --git a/themes/bootstrap3/templates/ajax/itemCallnumber.phtml b/themes/bootstrap3/templates/ajax/itemCallnumber.phtml index b889445c7c5..1bd79bcc59f 100644 --- a/themes/bootstrap3/templates/ajax/itemCallnumber.phtml +++ b/themes/bootstrap3/templates/ajax/itemCallnumber.phtml @@ -1,5 +1,5 @@ callnumberHandler): ?> - escapeHtml($this->displayCallnumber)?> + escapeHtml($this->displayCallnumber)?> - displayCallnumber?> + escapeHtml($this->displayCallnumber)?> diff --git a/themes/bootstrap3/templates/ajax/itemLocationList.phtml b/themes/bootstrap3/templates/ajax/itemLocationList.phtml index 2fe2a38a6f1..5b31a060e28 100644 --- a/themes/bootstrap3/templates/ajax/itemLocationList.phtml +++ b/themes/bootstrap3/templates/ajax/itemLocationList.phtml @@ -2,11 +2,11 @@ locationList as $location): ?>
- icon($availabilityStatus->getIcon($location['availability']))?> - escapeHtml($location['location'])?> + icon($availabilityStatus->getIcon($location['availability']))?> + escapeHtml($location['location'])?>
- + escapeHtml($location['callnumber'])?>
- \ No newline at end of file + From 869aee3a4c249082717b39fd30ec42e0e0ed3429 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Thu, 10 Oct 2024 14:51:37 +0200 Subject: [PATCH 23/29] Vagrantfile fix --- Vagrantfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 3c89601d481..5023ac393eb 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -65,7 +65,7 @@ Vagrant.configure("2") do |config| chmod 777 /vufindlocal/cache/cli # Set up profile for command line. - sudo echo export VUFIND_HOME=/vagrant > /etc/profile.d/vufind.sh - sudo echo export VUFIND_LOCAL_DIR=/vufindlocal >> /etc/profile.d/vufind.sh + echo export VUFIND_HOME=/vagrant > /etc/profile.d/vufind.sh + echo export VUFIND_LOCAL_DIR=/vufindlocal >> /etc/profile.d/vufind.sh SHELL end From 9d88e3f95e3b32fccef4abd052bd9093f12d2672 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Thu, 10 Oct 2024 16:46:52 +0200 Subject: [PATCH 24/29] Syntax fix --- module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 4a21b4d28e1..32e704d1295 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -130,7 +130,7 @@ protected function translateList($transPrefix, $list) { $transList = []; foreach ($list as $current) { - // $current can be an array if pickValues() is called with callnumbers and a translation prefix + // $current can be an array if pickValue() is called with callnumbers and a translation prefix $transList[] = is_string($current) ? $this->translateWithPrefix($transPrefix, $current) : $current; } return $transList; @@ -250,7 +250,7 @@ protected function renderCallnumbers(string $callnumberSetting, array $callnumbe $html[] = $this->renderer->render( 'ajax/itemCallnumber', - compact($actualCallnumber, $displayCallnumber, $callnumberHandler) + compact('actualCallnumber', 'displayCallnumber', 'callnumberHandler') ); } From 54f02e002c475a2d50535e0ffff7461709388666 Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Thu, 10 Oct 2024 16:53:32 +0200 Subject: [PATCH 25/29] Sync bs3 and bs5 themes --- themes/bootstrap5/templates/ajax/itemCallnumber.phtml | 4 ++-- themes/bootstrap5/templates/ajax/itemLocationList.phtml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/themes/bootstrap5/templates/ajax/itemCallnumber.phtml b/themes/bootstrap5/templates/ajax/itemCallnumber.phtml index b889445c7c5..1bd79bcc59f 100644 --- a/themes/bootstrap5/templates/ajax/itemCallnumber.phtml +++ b/themes/bootstrap5/templates/ajax/itemCallnumber.phtml @@ -1,5 +1,5 @@ callnumberHandler): ?> - escapeHtml($this->displayCallnumber)?> + escapeHtml($this->displayCallnumber)?> - displayCallnumber?> + escapeHtml($this->displayCallnumber)?> diff --git a/themes/bootstrap5/templates/ajax/itemLocationList.phtml b/themes/bootstrap5/templates/ajax/itemLocationList.phtml index 2fe2a38a6f1..5b31a060e28 100644 --- a/themes/bootstrap5/templates/ajax/itemLocationList.phtml +++ b/themes/bootstrap5/templates/ajax/itemLocationList.phtml @@ -2,11 +2,11 @@ locationList as $location): ?>
- icon($availabilityStatus->getIcon($location['availability']))?> - escapeHtml($location['location'])?> + icon($availabilityStatus->getIcon($location['availability']))?> + escapeHtml($location['location'])?>
- + escapeHtml($location['callnumber'])?>
- \ No newline at end of file + From d857623c4079dbd7db2e824990034aae3c325dba Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Wed, 30 Oct 2024 12:23:52 +0100 Subject: [PATCH 26/29] Fixed callnumbers in location lists --- themes/bootstrap3/templates/ajax/itemLocationList.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/bootstrap3/templates/ajax/itemLocationList.phtml b/themes/bootstrap3/templates/ajax/itemLocationList.phtml index 5b31a060e28..6e1d9e5d645 100644 --- a/themes/bootstrap3/templates/ajax/itemLocationList.phtml +++ b/themes/bootstrap3/templates/ajax/itemLocationList.phtml @@ -7,6 +7,6 @@
- escapeHtml($location['callnumber'])?> +
From c0334010ba76fc22575053d087ad7c98db283c2d Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Wed, 30 Oct 2024 12:27:51 +0100 Subject: [PATCH 27/29] Fixed callnumbers in location lists --- themes/bootstrap5/templates/ajax/itemLocationList.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/bootstrap5/templates/ajax/itemLocationList.phtml b/themes/bootstrap5/templates/ajax/itemLocationList.phtml index 5b31a060e28..6e1d9e5d645 100644 --- a/themes/bootstrap5/templates/ajax/itemLocationList.phtml +++ b/themes/bootstrap5/templates/ajax/itemLocationList.phtml @@ -7,6 +7,6 @@
- escapeHtml($location['callnumber'])?> +
From c5fbe18142b597440de30275e1e0b5e8da070e1e Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Mon, 4 Nov 2024 14:49:05 +0100 Subject: [PATCH 28/29] Updated PHPDoc and comment --- module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 722286f8b2e..4ca2a5f3500 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -130,7 +130,7 @@ protected function translateList($transPrefix, $list) { $transList = []; foreach ($list as $current) { - // $current can be an array if pickValue() is called with callnumbers and a translation prefix + // $current can be an array if pickValue() is called with callnumbers $transList[] = is_string($current) ? $this->translateWithPrefix($transPrefix, $current) : $current; } return $transList; @@ -143,8 +143,7 @@ protected function translateList($transPrefix, $list) * @param array $rawList Array of values to choose from. * @param string $mode config.ini setting -- first, all or msg * @param string $msg Message to display if $mode == "msg" - * @param string $transPrefix Translator prefix to apply to values (false to - * omit translation of values) + * @param string $transPrefix Translator prefix to apply to values (false to omit translation of values) * * @return array */ From 61154763d561072fc9e1b75aa53aadb7a0a7eb5d Mon Sep 17 00:00:00 2001 From: Tobias Groth Date: Thu, 7 Nov 2024 13:35:54 +0100 Subject: [PATCH 29/29] Renamed callnumber variable. Escape html attributes. --- module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php | 6 +++--- themes/bootstrap3/js/check_item_statuses.js | 4 +++- themes/bootstrap3/templates/ajax/itemCallnumber.phtml | 8 +++++++- themes/bootstrap3/templates/ajax/itemLocationList.phtml | 4 ++-- themes/bootstrap5/js/check_item_statuses.js | 4 +++- themes/bootstrap5/templates/ajax/itemCallnumber.phtml | 8 +++++++- themes/bootstrap5/templates/ajax/itemLocationList.phtml | 4 ++-- 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 4ca2a5f3500..c092599912b 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -325,7 +325,7 @@ protected function getItemStatus( 'reserve' => $reserve ? 'true' : 'false', 'reserve_message' => $this->translate($reserve ? 'on_reserve' : 'Not On Reserve'), - 'callnumber' => $this->renderCallnumbers($callnumberSetting, $callNumber), + 'callnumberHtml' => $this->renderCallnumbers($callnumberSetting, $callNumber), ]; } @@ -370,7 +370,7 @@ protected function getItemStatusGroup($record, $callnumberSetting) ENT_COMPAT, 'UTF-8' ), - 'callnumber' => + 'callnumberHtml' => $this->renderCallnumbers($callnumberSetting, $locationCallnumbers), ]; $locationList[] = $locationInfo; @@ -392,7 +392,7 @@ protected function getItemStatusGroup($record, $callnumberSetting) 'reserve' => $reserve ? 'true' : 'false', 'reserve_message' => $this->translate($reserve ? 'on_reserve' : 'Not On Reserve'), - 'callnumber' => false, + 'callnumberHtml' => false, ]; } diff --git a/themes/bootstrap3/js/check_item_statuses.js b/themes/bootstrap3/js/check_item_statuses.js index 0cc89e78aad..7d7fd509947 100644 --- a/themes/bootstrap3/js/check_item_statuses.js +++ b/themes/bootstrap3/js/check_item_statuses.js @@ -46,7 +46,9 @@ VuFind.register('itemStatuses', function ItemStatuses() { } else { // Default case -- load call number and location into appropriate containers: el.querySelectorAll('.callnumber').forEach((callnumber) => { - callnumber.innerHTML = result.callnumber + '
'; + callnumber.innerHTML = typeof(result.callnumberHtml) !== 'undefined' && result.callnumberHtml + ? result.callnumberHtml + '
' + : ''; }); el.querySelectorAll('.location').forEach((location) => { location.innerHTML = result.reserve === 'true' diff --git a/themes/bootstrap3/templates/ajax/itemCallnumber.phtml b/themes/bootstrap3/templates/ajax/itemCallnumber.phtml index 1bd79bcc59f..e901da35192 100644 --- a/themes/bootstrap3/templates/ajax/itemCallnumber.phtml +++ b/themes/bootstrap3/templates/ajax/itemCallnumber.phtml @@ -1,5 +1,11 @@ callnumberHandler): ?> - escapeHtml($this->displayCallnumber)?> + url('alphabrowse-home') . '?' . http_build_query([ + 'source' => $this->callnumberHandler, + 'from' => $this->actualCallnumber, + ]); + ?> + escapeHtml($this->displayCallnumber)?> escapeHtml($this->displayCallnumber)?> diff --git a/themes/bootstrap3/templates/ajax/itemLocationList.phtml b/themes/bootstrap3/templates/ajax/itemLocationList.phtml index 6e1d9e5d645..43783196682 100644 --- a/themes/bootstrap3/templates/ajax/itemLocationList.phtml +++ b/themes/bootstrap3/templates/ajax/itemLocationList.phtml @@ -1,12 +1,12 @@ availabilityStatus(); ?> locationList as $location): ?>
- + icon($availabilityStatus->getIcon($location['availability']))?> escapeHtml($location['location'])?>
- +
diff --git a/themes/bootstrap5/js/check_item_statuses.js b/themes/bootstrap5/js/check_item_statuses.js index 0cc89e78aad..7d7fd509947 100644 --- a/themes/bootstrap5/js/check_item_statuses.js +++ b/themes/bootstrap5/js/check_item_statuses.js @@ -46,7 +46,9 @@ VuFind.register('itemStatuses', function ItemStatuses() { } else { // Default case -- load call number and location into appropriate containers: el.querySelectorAll('.callnumber').forEach((callnumber) => { - callnumber.innerHTML = result.callnumber + '
'; + callnumber.innerHTML = typeof(result.callnumberHtml) !== 'undefined' && result.callnumberHtml + ? result.callnumberHtml + '
' + : ''; }); el.querySelectorAll('.location').forEach((location) => { location.innerHTML = result.reserve === 'true' diff --git a/themes/bootstrap5/templates/ajax/itemCallnumber.phtml b/themes/bootstrap5/templates/ajax/itemCallnumber.phtml index 1bd79bcc59f..e901da35192 100644 --- a/themes/bootstrap5/templates/ajax/itemCallnumber.phtml +++ b/themes/bootstrap5/templates/ajax/itemCallnumber.phtml @@ -1,5 +1,11 @@ callnumberHandler): ?> - escapeHtml($this->displayCallnumber)?> + url('alphabrowse-home') . '?' . http_build_query([ + 'source' => $this->callnumberHandler, + 'from' => $this->actualCallnumber, + ]); + ?> + escapeHtml($this->displayCallnumber)?> escapeHtml($this->displayCallnumber)?> diff --git a/themes/bootstrap5/templates/ajax/itemLocationList.phtml b/themes/bootstrap5/templates/ajax/itemLocationList.phtml index 6e1d9e5d645..43783196682 100644 --- a/themes/bootstrap5/templates/ajax/itemLocationList.phtml +++ b/themes/bootstrap5/templates/ajax/itemLocationList.phtml @@ -1,12 +1,12 @@ availabilityStatus(); ?> locationList as $location): ?>
- + icon($availabilityStatus->getIcon($location['availability']))?> escapeHtml($location['location'])?>
- +