Skip to content

Commit

Permalink
Add config setting for display of items without barcodes. (#2553)
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz authored Sep 29, 2022
1 parent 856bf22 commit a3264e4
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 2 deletions.
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
@@ -0,0 +1,83 @@
<?php
/**
* Holdings view helper Test Class
*
* 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 Tests
* @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:testing:unit_tests Wiki
*/
namespace VuFindTest\View\Helper\Root;

/**
* Holdings view helper Test Class
*
* @category VuFind
* @package Tests
* @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:testing:unit_tests Wiki
*/
class HoldingsTest extends \PHPUnit\Framework\TestCase
{
/**
* Data provider for testBarcodeVisibilityBehavior()
*
* @return array
*/
public function barcodeVisibilityBehaviorProvider(): array
{
return [
'default' => [[], true, true],
'enabled' => [['display_items_without_barcodes' => true], true, true],
'disabled' => [['display_items_without_barcodes' => false], true, false],
];
}

/**
* Test appropriate barcode display behavior for various configurations.
*
* @param array $config Configuration options to test
* @param bool $expectedBarcodeResult Expected result for items with barcodes
* @param bool $expectedNoBarcodeResult Expected result for items without
* barcodes
*
* @return void
*
* @dataProvider barcodeVisibilityBehaviorProvider
*/
public function testBarcodeVisibilityBehavior(
array $config,
bool $expectedBarcodeResult,
bool $expectedNoBarcodeResult
): void {
// Create a helper object:
$helper = new \VuFind\View\Helper\Root\Holdings($config);
$this->assertEquals(
$expectedBarcodeResult,
$helper->holdingIsVisible(['barcode' => '1234'])
);
$this->assertEquals(
$expectedNoBarcodeResult,
$helper->holdingIsVisible([])
);
}
}
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

0 comments on commit a3264e4

Please sign in to comment.