Skip to content
Snippets Groups Projects
Commit 614bc1c9 authored by Alexander Purr's avatar Alexander Purr
Browse files

refs #21064 [fid] code style fid/Validators

parent 7b47a046
No related merge requests found
<?php <?php
/** /**
* Subito partial copy page bounds validator
*
* Copyright (C) 2020 Leipzig University Library * Copyright (C) 2020 Leipzig University Library
* *
* PHP Version 7
*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
...@@ -15,13 +19,25 @@ ...@@ -15,13 +19,25 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
* @author Alexander Purr <purr@ub.uni-leipzig.de> * @category VuFind
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 * @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; namespace fid\Validator;
use Zend\Validator\AbstractValidator; 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 class SubitoPartialCopyPageBounds extends AbstractValidator
{ {
use SubitoPartialCopyPageRangeValidatorTrait; use SubitoPartialCopyPageRangeValidatorTrait;
...@@ -37,14 +53,23 @@ class SubitoPartialCopyPageBounds extends AbstractValidator ...@@ -37,14 +53,23 @@ class SubitoPartialCopyPageBounds extends AbstractValidator
self::PAGE_BOUNDS => "acquisition_error_page_bounds", 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) { if ($this->options['numberPages'] == null) {
return false; 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); $this->error(self::PAGE_BOUNDS);
return false; return false;
} else { } else {
......
<?php <?php
/** /**
* Subito partial copy page order validator
*
* Copyright (C) 2020 Leipzig University Library * Copyright (C) 2020 Leipzig University Library
* *
* PHP Version 7
*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
...@@ -15,13 +19,25 @@ ...@@ -15,13 +19,25 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
* @author Alexander Purr <purr@ub.uni-leipzig.de> * @category VuFind
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 * @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; namespace fid\Validator;
use Zend\Validator\AbstractValidator; 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 class SubitoPartialCopyPageOrder extends AbstractValidator
{ {
use SubitoPartialCopyPageRangeValidatorTrait; use SubitoPartialCopyPageRangeValidatorTrait;
...@@ -32,11 +48,18 @@ class SubitoPartialCopyPageOrder extends AbstractValidator ...@@ -32,11 +48,18 @@ class SubitoPartialCopyPageOrder extends AbstractValidator
self::PAGES_ORDER => "acquisition_error_page_order", 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); $this->error(self::PAGES_ORDER);
return false; return false;
} else { } else {
......
<?php <?php
/** /**
* Subito partial copy page range validator trait
*
* Copyright (C) 2020 Leipzig University Library * Copyright (C) 2020 Leipzig University Library
* *
* PHP Version 7
*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
...@@ -15,23 +19,42 @@ ...@@ -15,23 +19,42 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
* @author Alexander Purr <purr@ub.uni-leipzig.de> * @category VuFind
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 * @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; namespace fid\Validator;
use fid\Controller\RecordController; 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 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); preg_match(RecordController::PAGE_RANGE_PATTERN, $value, $matches);
$this->pageStart = (int)$matches[1]; $this->_pageStart = (int)$matches[1];
$this->pageEnd = (int)$matches[2]; $this->_pageEnd = (int)$matches[2];
} }
} }
<?php <?php
/** /**
* Subito partial copy page selection validator
*
* Copyright (C) 2020 Leipzig University Library * Copyright (C) 2020 Leipzig University Library
* *
* PHP Version 7
*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
...@@ -15,13 +19,25 @@ ...@@ -15,13 +19,25 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
* @author Alexander Purr <purr@ub.uni-leipzig.de> * @category VuFind
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 * @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; namespace fid\Validator;
use Zend\Validator\AbstractValidator; 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 class SubitoPartialCopyPageSelection extends AbstractValidator
{ {
use SubitoPartialCopyPageRangeValidatorTrait; use SubitoPartialCopyPageRangeValidatorTrait;
...@@ -39,15 +55,26 @@ class SubitoPartialCopyPageSelection extends AbstractValidator ...@@ -39,15 +55,26 @@ class SubitoPartialCopyPageSelection extends AbstractValidator
'percentagedLimit' => 10 '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) { if ($this->options['numberPages'] == null) {
return false; return false;
} }
$this->extractPages($value); $this->_extractPages($value);
$selection = $this->pageEnd - $this->pageStart; $selection = $this->_pageEnd - $this->_pageStart;
$permittedSelection = (($this->options['percentagedLimit'] / 100) * $this->options['numberPages']) + $this->options['tolerancePages']; $permittedSelection = (
($this->options['percentagedLimit'] / 100)
* $this->options['numberPages']
)
+ $this->options['tolerancePages'];
if ($selection > $permittedSelection) { if ($selection > $permittedSelection) {
$this->error(self::PAGE_SELECTION); $this->error(self::PAGE_SELECTION);
return false; return false;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment