-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config setting for display of items without barcodes. (#2553)
- Loading branch information
1 parent
856bf22
commit a3264e4
Showing
7 changed files
with
236 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
70
module/VuFind/src/VuFind/View/Helper/Root/HoldingsFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/HoldingsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([]) | ||
); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
themes/bootstrap3/templates/RecordTab/holdingsils/extended.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
themes/bootstrap3/templates/RecordTab/holdingsils/standard.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters