diff --git a/module/fid/src/Validator/SubitoPartialCopyPageBounds.php b/module/fid/src/Validator/SubitoPartialCopyPageBounds.php index 35bc8a99f5372974f73ec0dbfafe0cafcd82692f..c3fb3f86f3eef77757b5a89395f2d55ddaa0d7fd 100644 --- a/module/fid/src/Validator/SubitoPartialCopyPageBounds.php +++ b/module/fid/src/Validator/SubitoPartialCopyPageBounds.php @@ -1,7 +1,11 @@ <?php /** + * Subito partial copy page bounds validator + * * Copyright (C) 2020 Leipzig University Library * + * PHP Version 7 + * * 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. @@ -15,13 +19,25 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Alexander Purr <purr@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Validator; use Zend\Validator\AbstractValidator; +/** + * Subito partial copy page bounds validator + * + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ class SubitoPartialCopyPageBounds extends AbstractValidator { use SubitoPartialCopyPageRangeValidatorTrait; @@ -37,14 +53,23 @@ class SubitoPartialCopyPageBounds extends AbstractValidator self::PAGE_BOUNDS => "acquisition_error_page_bounds", ]; - public function isValid($value) + /** + * Validate if given page range is beetween first and last page of a record + * + * @param string $value From to page range + * + * @return bool + */ + public function isValid(string $value) : bool { if ($this->options['numberPages'] == null) { return false; } - $this->extractPages($value); + $this->_extractPages($value); - if (($this->pageEnd > $this->options['numberPages']) || ($this->pageStart < 1)) { + if (($this->_pageEnd > $this->options['numberPages']) + || ($this->_pageStart < 1) + ) { $this->error(self::PAGE_BOUNDS); return false; } else { diff --git a/module/fid/src/Validator/SubitoPartialCopyPageOrder.php b/module/fid/src/Validator/SubitoPartialCopyPageOrder.php index 0415c5a348decedb3bc25eb9ce008bc2b1d67d57..891087e3f7c06b33b53c9adf3a4bd3128aee15fe 100644 --- a/module/fid/src/Validator/SubitoPartialCopyPageOrder.php +++ b/module/fid/src/Validator/SubitoPartialCopyPageOrder.php @@ -1,7 +1,11 @@ <?php /** + * Subito partial copy page order validator + * * Copyright (C) 2020 Leipzig University Library * + * PHP Version 7 + * * 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. @@ -15,13 +19,25 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Alexander Purr <purr@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Validator; use Zend\Validator\AbstractValidator; +/** + * Subito partial copy page order validator + * + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ class SubitoPartialCopyPageOrder extends AbstractValidator { use SubitoPartialCopyPageRangeValidatorTrait; @@ -32,11 +48,18 @@ class SubitoPartialCopyPageOrder extends AbstractValidator self::PAGES_ORDER => "acquisition_error_page_order", ]; - public function isValid($value) + /** + * Validate if given page range is ordered correctly + * + * @param string $value From to page range + * + * @return bool + */ + public function isValid(string $value) : bool { - $this->extractPages($value); + $this->_extractPages($value); - if ($this->pageStart > $this->pageEnd) { + if ($this->_pageStart > $this->_pageEnd) { $this->error(self::PAGES_ORDER); return false; } else { diff --git a/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php b/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php index ee91dbc6a10d4366d49b771cd921d22493defd55..87a4551c814075bf7038260b99971a74e4695369 100644 --- a/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php +++ b/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php @@ -1,7 +1,11 @@ <?php /** + * Subito partial copy page range validator trait + * * Copyright (C) 2020 Leipzig University Library * + * PHP Version 7 + * * 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. @@ -15,23 +19,42 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Alexander Purr <purr@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Validator; use fid\Controller\RecordController; +/** + * Subito partial copy page range validator trait + * + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ trait SubitoPartialCopyPageRangeValidatorTrait { - private $pageStart = null; + private $_pageStart = null; - private $pageEnd = null; + private $_pageEnd = null; - private function extractPages($value) + /** + * Extract start and end page of a page range (string like '12-123') + * + * @param string $value From to page range + * + * @return void + */ + private function _extractPages(string $value) { preg_match(RecordController::PAGE_RANGE_PATTERN, $value, $matches); - $this->pageStart = (int)$matches[1]; - $this->pageEnd = (int)$matches[2]; + $this->_pageStart = (int)$matches[1]; + $this->_pageEnd = (int)$matches[2]; } } diff --git a/module/fid/src/Validator/SubitoPartialCopyPageSelection.php b/module/fid/src/Validator/SubitoPartialCopyPageSelection.php index 00f5be4679e4718861cef7d83cde59568965f266..41dabd58c0b7003d536ff148900069e4d8269ec2 100644 --- a/module/fid/src/Validator/SubitoPartialCopyPageSelection.php +++ b/module/fid/src/Validator/SubitoPartialCopyPageSelection.php @@ -1,7 +1,11 @@ <?php /** + * Subito partial copy page selection validator + * * Copyright (C) 2020 Leipzig University Library * + * PHP Version 7 + * * 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. @@ -15,13 +19,25 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Alexander Purr <purr@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Validator; use Zend\Validator\AbstractValidator; +/** + * Subito partial copy page selection validator + * + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ class SubitoPartialCopyPageSelection extends AbstractValidator { use SubitoPartialCopyPageRangeValidatorTrait; @@ -39,15 +55,26 @@ class SubitoPartialCopyPageSelection extends AbstractValidator 'percentagedLimit' => 10 ]; - public function isValid($value) + /** + * Validate if given page selection does not exceed percentaged limit of a record + * + * @param string $value From to page range + * + * @return bool + */ + public function isValid(string $value) : bool { if ($this->options['numberPages'] == null) { return false; } - $this->extractPages($value); + $this->_extractPages($value); - $selection = $this->pageEnd - $this->pageStart; - $permittedSelection = (($this->options['percentagedLimit'] / 100) * $this->options['numberPages']) + $this->options['tolerancePages']; + $selection = $this->_pageEnd - $this->_pageStart; + $permittedSelection = ( + ($this->options['percentagedLimit'] / 100) + * $this->options['numberPages'] + ) + + $this->options['tolerancePages']; if ($selection > $permittedSelection) { $this->error(self::PAGE_SELECTION); return false;