Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config setting for display of items without barcodes. #2553

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/vufind/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,13 @@ title_level_holds_mode = "disabled"
; Whether to display the item barcode for each loan. Default is false.
;display_checked_out_item_barcode = true

; Whether to display items without barcodes in the Holdings tab. Prior to VuFind
; 9.0, hiding items without barcodes was VuFind's default behavior. The current
; default value is true -- to always display ALL items.
; If you need to apply more complex filtering rules to Holdings display, you
; can extend/override the VuFind\View\Helper\Root\Holdings::holdingIsVisible method.
;display_items_without_barcodes = true

; This section controls features related to user accounts
[Account]
; Allow the user to set a home library through the Profile screen, which will
Expand Down
72 changes: 72 additions & 0 deletions module/VuFind/src/VuFind/View/Helper/Root/Holdings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* View helper to support ILS holdings display
*
* PHP version 7
*
* Copyright (C) Villanova University 2022.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package View_Helpers
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
namespace VuFind\View\Helper\Root;

/**
* View helper to support ILS holdings display
*
* @category VuFind
* @package View_Helpers
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class Holdings extends \Laminas\View\Helper\AbstractHelper
{
/**
* Configuration
*
* @var array
*/
protected $config;

/**
* Constructor
*
* @param array $config Configuration
*/
public function __construct(array $config)
{
$this->config = $config;
}

/**
* Is the provided holdings array (from an ILS driver's getHolding method)
* suitable for display to the end user?
*
* @param array $holding Holding to evaluate
*
* @return bool
*/
public function holdingIsVisible(array $holding): bool
{
$showEmptyBarcodes
= (bool)($this->config['display_items_without_barcodes'] ?? true);
return $showEmptyBarcodes || strlen($holding['barcode'] ?? '') > 0;
}
}
70 changes: 70 additions & 0 deletions module/VuFind/src/VuFind/View/Helper/Root/HoldingsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Holdings helper factory.
*
* PHP version 7
*
* Copyright (C) Villanova University 2022.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package View_Helpers
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
namespace VuFind\View\Helper\Root;

use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerExceptionInterface as ContainerException;
use Psr\Container\ContainerInterface;

/**
* Holdings helper factory.
*
* @category VuFind
* @package View_Helpers
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class HoldingsFactory implements FactoryInterface
{
/**
* Create an object
*
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException&\Throwable if any other error occurs
*/
public function __invoke(
ContainerInterface $container,
$requestedName,
array $options = null
) {
$full = $container->get(\VuFind\Config\PluginManager::class)->get('config');
$config = isset($full->Catalog) ? $full->Catalog->toArray() : [];
return new $requestedName($config);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php if (strlen($holding['barcode'] ?? '') > 0): ?>
<?php if ($this->holdings()->holdingIsVisible($holding)): ?>
<?php
$check = $holding['check'] ?? false;
$checkStorageRetrievalRequest = $holding['checkStorageRetrievalRequest'] ?? false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php if (strlen($holding['barcode'] ?? '') > 0): ?>
<?php if ($this->holdings()->holdingIsVisible($holding)): ?>
<?php
$check = $holding['check'] ?? false;
$checkStorageRetrievalRequest = $holding['checkStorageRetrievalRequest'] ?? false;
Expand Down
2 changes: 2 additions & 0 deletions themes/root/theme.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'VuFind\View\Helper\Root\HelpText' => 'VuFind\View\Helper\Root\HelpTextFactory',
'VuFind\View\Helper\Root\Highlight' => 'Laminas\ServiceManager\Factory\InvokableFactory',
'VuFind\View\Helper\Root\HistoryLabel' => 'VuFind\View\Helper\Root\HistoryLabelFactory',
'VuFind\View\Helper\Root\Holdings' => 'VuFind\View\Helper\Root\HoldingsFactory',
'VuFind\View\Helper\Root\Icon' => 'VuFind\View\Helper\Root\IconFactory',
'VuFind\View\Helper\Root\Ils' => 'VuFind\View\Helper\Root\IlsFactory',
'VuFind\View\Helper\Root\JsIcons' => 'VuFind\View\Helper\Root\JsIconsFactory',
Expand Down Expand Up @@ -114,6 +115,7 @@
'helpText' => 'VuFind\View\Helper\Root\HelpText',
'highlight' => 'VuFind\View\Helper\Root\Highlight',
'historylabel' => 'VuFind\View\Helper\Root\HistoryLabel',
'holdings' => 'VuFind\View\Helper\Root\Holdings',
'ils' => 'VuFind\View\Helper\Root\Ils',
'icon' => 'VuFind\View\Helper\Root\Icon',
'jsIcons' => 'VuFind\View\Helper\Root\JsIcons',
Expand Down