Skip to content
Snippets Groups Projects
Commit 68a1f311 authored by Alexander Purr's avatar Alexander Purr Committed by Dorian Merz
Browse files

refs #17176 [fid] add advanced subito partial copy page selection validaton

* add new validators
** page selection: correct page order
** page selection: highest selected page can not exceed number of pages
** page selection: can not not exceed a certain percentaged part of whole record
* add first validator to form configuration
* add other validators within controller trait to from
* add hyphen filter to form configuration
* add dynamic page selection validators
** add session to RecordController via DelegatorFactory
** adjust behavior to handle false page selection warning with session parameter
* add fid translation
* display number of record pages in summary of subito partial copy
** changes in RecordDataFormatterFactory
*** add general spec builder function
*** extend general specs for subito partial copy
parent 946e9421
No related merge requests found
Showing
with 298 additions and 24 deletions
...@@ -19,7 +19,11 @@ ...@@ -19,7 +19,11 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/ */
use fid\Controller\RecordController;
use fid\Hydrator\OrderHydrator; use fid\Hydrator\OrderHydrator;
use fid\Validator\SubitoPartialCopyPageLimit;
use fid\Validator\SubitoPartialCopyPageOrder;
use Zend\Filter\PregReplace;
use Zend\Filter\StringTrim; use Zend\Filter\StringTrim;
use Zend\Form\Element\Submit; use Zend\Form\Element\Submit;
use Zend\Form\Element\Text; use Zend\Form\Element\Text;
...@@ -59,6 +63,13 @@ return [ ...@@ -59,6 +63,13 @@ return [
StringTrim::class => [ StringTrim::class => [
'name' => StringTrim::class, 'name' => StringTrim::class,
], ],
PregReplace::class => [
'name' => PregReplace::class,
'options' => [
'pattern' => '/(-|–|—|−)/',
'replacement' => '-'
]
],
], ],
'validators' => [ 'validators' => [
StringLength::class => [ StringLength::class => [
...@@ -74,6 +85,7 @@ return [ ...@@ -74,6 +85,7 @@ return [
], ],
Regex::class => [ Regex::class => [
'name' => Regex::class, 'name' => Regex::class,
'break_chain_on_failure' => true,
'options' => [ 'options' => [
'pattern' => '/^(0|[1-9]\d*)-([1-9]\d*)$/', 'pattern' => '/^(0|[1-9]\d*)-([1-9]\d*)$/',
'messages' => [ 'messages' => [
...@@ -81,6 +93,14 @@ return [ ...@@ -81,6 +93,14 @@ return [
], ],
], ],
], ],
SubitoPartialCopyPageOrder::class => [
'name' => SubitoPartialCopyPageOrder::class,
'options' => [
'messages' => [
SubitoPartialCopyPageOrder::PAGES_ORDER => 'acquisition_error_page_order',
],
],
],
], ],
], ],
'submit' => [ 'submit' => [
......
...@@ -29,6 +29,8 @@ namespace fid\Controller\CustomTraits; ...@@ -29,6 +29,8 @@ namespace fid\Controller\CustomTraits;
use fid\Service\Client; use fid\Service\Client;
use fid\Service\DataTransferObject\Order; use fid\Service\DataTransferObject\Order;
use fid\Validator\SubitoPartialCopyPageBounds;
use fid\Validator\SubitoPartialCopyPageSelection;
use finc\View\Helper\Root\Citation; use finc\View\Helper\Root\Citation;
use Zend\Form\Form; use Zend\Form\Form;
use Zend\Http\PhpEnvironment\Request; use Zend\Http\PhpEnvironment\Request;
...@@ -154,13 +156,28 @@ trait FidAcquisitionTrait ...@@ -154,13 +156,28 @@ trait FidAcquisitionTrait
$request = $this->getRequest(); $request = $this->getRequest();
$form = $this->serviceLocator->get('fid-acquisition-subito-partial-copy-form'); $form = $this->serviceLocator->get('fid-acquisition-subito-partial-copy-form');
// add number of pages specific validators
$recordPages = $driver->tryMethod('getNumberOfPages');
if ($recordPages)
{
$form->getInputFilter()->get('pages')->getValidatorChain()->attach(
new SubitoPartialCopyPageBounds(['numberPages' => $recordPages]),
true
);
$form->getInputFilter()->get('pages')->getValidatorChain()->attach(
new SubitoPartialCopyPageSelection(['numberPages' => $recordPages])
);
}
if ($submitted = $this->formWasSubmitted()) { if ($submitted = $this->formWasSubmitted()) {
$form->setData($request->getPost()); $form->setData($request->getPost());
if ($form->isValid()) { if ($form->isValid()) {
$url = $this->getRecordUrl($recordId); $url = $this->getRecordUrl($recordId);
$label = $this->getOrderLabel($driver); $label = $this->getOrderLabel($driver);
$pages = $form->getData()['pages']; $subitoPartialCopy = [
$form->getHydrator()->hydrate(compact('driver','user', 'type', 'url', 'label', 'pages'), $order = new Order()); 'selection' => $form->getData()['pages']
];
$form->getHydrator()->hydrate(compact('driver','user', 'type', 'url', 'label', 'subitoPartialCopy'), $order = new Order());
$this->client->requestOrderCreation($order); $this->client->requestOrderCreation($order);
$message = $this->translate('fid::acquisition_success'); $message = $this->translate('fid::acquisition_success');
$messenger->addSuccessMessage($message); $messenger->addSuccessMessage($message);
...@@ -168,10 +185,6 @@ trait FidAcquisitionTrait ...@@ -168,10 +185,6 @@ trait FidAcquisitionTrait
} }
} }
$patron = $this->catalogLogin();
$catalog = $this->getILS();
$profile = $catalog->getMyProfile($patron);
$action = $this->url()->fromRoute('record-fidsubitopartialcopy',['id' => $recordId]); $action = $this->url()->fromRoute('record-fidsubitopartialcopy',['id' => $recordId]);
$form->setAttribute('action', $action); $form->setAttribute('action', $action);
$form->prepare(); $form->prepare();
......
...@@ -29,4 +29,6 @@ namespace fid\Controller; ...@@ -29,4 +29,6 @@ namespace fid\Controller;
class RecordController extends \finc\Controller\RecordController class RecordController extends \finc\Controller\RecordController
{ {
use CustomTraits\FidAcquisitionTrait; use CustomTraits\FidAcquisitionTrait;
const PAGE_RANGE_PATTERN = '/^(0|[1-9]\d*)-([1-9]\d*)$/';
} }
...@@ -12,7 +12,6 @@ class RecordControllerDelegatorFactory implements DelegatorFactoryInterface ...@@ -12,7 +12,6 @@ class RecordControllerDelegatorFactory implements DelegatorFactoryInterface
/** @var RecordController $instance */ /** @var RecordController $instance */
$instance = call_user_func($callback); $instance = call_user_func($callback);
$instance->setClient($container->get(Client::class)); $instance->setClient($container->get(Client::class));
return $instance; return $instance;
} }
} }
\ No newline at end of file
...@@ -27,7 +27,7 @@ class OrderHydrator extends AbstractHydrator { ...@@ -27,7 +27,7 @@ class OrderHydrator extends AbstractHydrator {
$object->setType($data['type']); $object->setType($data['type']);
$object->setUser($data['user']); $object->setUser($data['user']);
$partialCopyPages = array_key_exists('pages',$data) ? $data['pages'] : null; $partialCopy = array_key_exists('subitoPartialCopy', $data) ? $data['subitoPartialCopy'] : null;
/* Collect needed record data */ /* Collect needed record data */
$id = $driver->tryMethod('getUniqueID'); $id = $driver->tryMethod('getUniqueID');
...@@ -64,7 +64,7 @@ class OrderHydrator extends AbstractHydrator { ...@@ -64,7 +64,7 @@ class OrderHydrator extends AbstractHydrator {
'url' 'url'
); );
$object->setData(compact('record','partialCopyPages')); $object->setData(compact('record','partialCopy'));
$object->setLabel($data['label']); $object->setLabel($data['label']);
return; return;
} }
......
<?php
/**
* Copyright (C) 2020 Leipzig University Library
*
* 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.
*
* @author Alexander Purr <purr@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/
namespace fid\Validator;
use Zend\Validator\AbstractValidator;
class SubitoPartialCopyPageBounds extends AbstractValidator
{
use SubitoPartialCopyPageRangeValidatorTrait;
public const PAGE_BOUNDS = 'subitoPartialCopyPageBounds';
// Available validator options.
protected $options = [
'numberPages' => null
];
protected $messageTemplates = [
self::PAGE_BOUNDS => "acquisition_error_page_bounds",
];
public function isValid($value)
{
if ($this->options['numberPages'] == null)
{
return false;
}
$this->extractPages($value);
if (($this->pageEnd > $this->options['numberPages']) || ($this->pageStart < 1))
{
$this->error(self::PAGE_BOUNDS);
return false;
}
else
{
return true;
}
}
}
<?php
/**
* Copyright (C) 2020 Leipzig University Library
*
* 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.
*
* @author Alexander Purr <purr@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/
namespace fid\Validator;
use Zend\Validator\AbstractValidator;
class SubitoPartialCopyPageOrder extends AbstractValidator
{
use SubitoPartialCopyPageRangeValidatorTrait;
public const PAGES_ORDER = 'subitoPartialCopyPageOrder';
protected $messageTemplates = [
self::PAGES_ORDER => "acquisition_error_page_order",
];
public function isValid($value)
{
$this->extractPages($value);
if($this->pageStart > $this->pageEnd) {
$this->error(self::PAGES_ORDER);
return false;
}
else
{
return true;
}
}
}
<?php
/**
* Copyright (C) 2020 Leipzig University Library
*
* 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.
*
* @author Alexander Purr <purr@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/
namespace fid\Validator;
use fid\Controller\RecordController;
trait SubitoPartialCopyPageRangeValidatorTrait
{
private $pageStart = null;
private $pageEnd = null;
private function extractPages ($value)
{
preg_match(RecordController::PAGE_RANGE_PATTERN, $value, $matches);
$this->pageStart = (int) $matches[1];
$this->pageEnd = (int) $matches[2];
}
}
\ No newline at end of file
<?php
/**
* Copyright (C) 2020 Leipzig University Library
*
* 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.
*
* @author Alexander Purr <purr@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/
namespace fid\Validator;
use Zend\Validator\AbstractValidator;
class SubitoPartialCopyPageSelection extends AbstractValidator
{
use SubitoPartialCopyPageRangeValidatorTrait;
public const PAGE_SELECTION = 'subitoPartialCopyPageSelection';
protected $messageTemplates = [
self::PAGE_SELECTION => "acquisition_error_page_selection",
];
// Available validator options.
protected $options = [
'numberPages' => null,
'tolerancePages' => 1,
'percentagedLimit' => 10
];
public function isValid ($value)
{
if ($this->options['numberPages'] == null)
{
return false;
}
$this->extractPages($value);
$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;
}
else
{
return true;
}
}
}
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
namespace fid\View\Helper\Root; namespace fid\View\Helper\Root;
use VuFind\View\Helper\Root\RecordDataFormatter; use VuFind\View\Helper\Root\RecordDataFormatter;
use VuFind\View\Helper\Root\RecordDataFormatter\SpecBuilder;
class RecordDataFormatterFactory class RecordDataFormatterFactory
{ {
...@@ -40,21 +41,19 @@ class RecordDataFormatterFactory ...@@ -40,21 +41,19 @@ class RecordDataFormatterFactory
$helper = new RecordDataFormatter(); $helper = new RecordDataFormatter();
$helper->setDefaults('fid-acquisition-general', [$this, 'getFidAcquisitionSpecs']); $helper->setDefaults('fid-acquisition-general', [$this, 'getFidAcquisitionSpecs']);
//$helper->setDefaults('fid-pda', [$this, 'getFidPdaSpecs']); $helper->setDefaults('fid-acquisition-subito-partial-copy', [$this, 'getFidAcquisitionSubitoPartialCopySpecs']);
//$helper->setDefaults('fid-subito-articel', [$this, 'getFidSubitoArticelSpecs']);
//$helper->setDefaults('fid-subito-partial-copy', [$this, 'getFidSubitoPartialCopySpecs']);
return $helper; return $helper;
} }
/** /**
* Get specifications for displaying data in fid pda form. * Get general specifications for displaying data in fid pda form.
* *
* @return array * @return array
*/ */
public function getFidAcquisitionSpecs() public function getFidAcquisitionSpecBuilder()
{ {
$spec = new RecordDataFormatter\SpecBuilder(); $spec = new SpecBuilder();
$spec->setLine('Title','getTitle'); $spec->setLine('Title','getTitle');
$spec->setTemplateLine( $spec->setTemplateLine(
'Authors/Corporations', 'Authors/Corporations',
...@@ -80,6 +79,29 @@ class RecordDataFormatterFactory ...@@ -80,6 +79,29 @@ class RecordDataFormatterFactory
'data-price.phtml' 'data-price.phtml'
); );
$spec->setLine('Language','getLanguages'); $spec->setLine('Language','getLanguages');
return $spec;
}
/**
* Get specifications for displaying data in fid pda form.
*
* @return array
*/
public function getFidAcquisitionSpecs()
{
$spec = $this->getFidAcquisitionSpecBuilder();
return $spec->getArray();
}
/**
* Get specifications for displaying data in fid subito partial copy form.
*
* @return array
*/
public function getFidAcquisitionSubitoPartialCopySpecs()
{
$spec = $this->getFidAcquisitionSpecBuilder();
$spec->setLine('fid::number_of_pages','getNumberOfPages');
return $spec->getArray(); return $spec->getArray();
} }
} }
...@@ -144,11 +144,16 @@ acquisition_delivery_to = "Lieferung an" ...@@ -144,11 +144,16 @@ acquisition_delivery_to = "Lieferung an"
acquisition_info_requested_item = "Bestellung" acquisition_info_requested_item = "Bestellung"
acquisition_label_pages = "Seitenzahlen (von-bis)" acquisition_label_pages = "Seitenzahlen (von-bis)"
acquisition_label_submit = "Bestellen" acquisition_label_submit = "Bestellen"
acquisition_error_pages_too_short = "Zu wenig Zeichen" acquisition_error_pages_too_short = "Ihre Eingabe hat zu wenige Zeichen. Bitte geben Sie mind. 3 Zeichen ein."
acquisition_error_pages_too_long = "Zu viele Zeichen" acquisition_error_pages_too_long = "Ihre Eingabe hat zu viele Zeichen. Bitte geben Sie max. 13 Zeichen ein."
acquisition_error_pages_pattern = "Fehlerhaftes oder falsches Format" acquisition_error_pages_pattern = "Falsches Format. Bitte geben Sie die gewünschten Seiten nur im Format VON-BIS ein, z. B. 23-30."
acquisition_error_page_order = "Die Seitenzahlen sind in einer falschen Reihenfolge. Bitte korrigieren Sie Ihre Eingabe."
acquisition_error_page_bounds = "Das Buch hat weniger Seiten als von Ihnen gewünscht. Bitte korrigieren Sie Ihre Eingabe."
acquisition_error_page_selection = "Der von Ihnen angegebene Seitenbereich überschreitet die urheberrechtlich erlaubten 10 Prozent des Gesamtumfangs. Ihre Bestellung kann daher nicht ausgeführt werden. Bitte überprüfen Sie Ihre Angaben."
acquisition_subito_article_confirmation = "Möchten Sie den Artikel bestellen?" acquisition_subito_article_confirmation = "Möchten Sie den Artikel bestellen?"
acquisition_subito_partial_copy_confirmation = "Möchten Sie die Teilkopie bestellen?" acquisition_subito_partial_copy_confirmation = "Möchten Sie die Teilkopie bestellen?"
acquisition_pda_confirmation = "Möchten Sie das Buch bestellen?" acquisition_pda_confirmation = "Möchten Sie das Buch bestellen?"
acquisition_pda_ordered = "Dieser Titel wurde bereits auf Nutzerwunsch durch adlr.link erworben und wird in Kürze verfügbar sein." acquisition_pda_ordered = "Dieser Titel wurde bereits auf Nutzerwunsch durch adlr.link erworben und wird in Kürze verfügbar sein."
acquisition_success = "Ihre Bestellung wurde entgegengenommen und wird nun von uns bearbeitet." acquisition_success = "Ihre Bestellung wurde entgegengenommen und wird nun von uns bearbeitet."
\ No newline at end of file
number_of_pages = "Seiten"
\ No newline at end of file
...@@ -142,11 +142,16 @@ acquisition_delivery_to = "Delivery to" ...@@ -142,11 +142,16 @@ acquisition_delivery_to = "Delivery to"
acquisition_info_requested_item = "Order item" acquisition_info_requested_item = "Order item"
acquisition_label_pages = "Pages (from-to)" acquisition_label_pages = "Pages (from-to)"
acquisition_label_submit = "Order" acquisition_label_submit = "Order"
acquisition_error_pages_too_short = "Too few characters" acquisition_error_pages_too_short = "Your request has too few characters. Please enter at least 3 characters."
acquisition_error_pages_too_long = "Too many characters" acquisition_error_pages_too_long = "Your request has too many characters. Please enter a maximum of 13 characters."
acquisition_error_pages_pattern = "Inaccurate or wrong format" acquisition_error_pages_pattern = "Wrong format. Please enter the required pages only in the FROM-TO format, e.g. 23-30."
acquisition_error_page_order = "The page numbers are in the wrong order. Please correct your order."
acquisition_error_page_bounds = "The book has fewer pages than you requested. Please correct your order."
acquisition_error_page_selection = "The page range you specify exceeds the 10 percent of the total volume permitted by copyright law. Therefore we will not be able to process your order. Please check your order details."
acquisition_subito_article_confirmation = "Do you like to order the article?" acquisition_subito_article_confirmation = "Do you like to order the article?"
acquisition_subito_partial_copy_confirmation = "Do you like to order the partial copy?" acquisition_subito_partial_copy_confirmation = "Do you like to order the partial copy?"
acquisition_pda_confirmation = "Do you like to order the book?" acquisition_pda_confirmation = "Do you like to order the book?"
acquisition_pda_ordered = "This item has been acquired by adlr.link by request of a patron and will be available in a short time." acquisition_pda_ordered = "This item has been acquired by adlr.link by request of a patron and will be available in a short time."
acquisition_success = "Your order is received and will be processed now." acquisition_success = "Your order is received and will be processed now."
number_of_pages = "Pages"
\ No newline at end of file
...@@ -53,7 +53,7 @@ $form->setAttribute('class','fid-acquisition-form'); ...@@ -53,7 +53,7 @@ $form->setAttribute('class','fid-acquisition-form');
<div class="col col-md-6"> <div class="col col-md-6">
<?php <?php
$formatter = $this->recordDataFormatter(); $formatter = $this->recordDataFormatter();
$this->coreFields = $formatter->getData($driver, $formatter->getDefaults('fid-acquisition-general')); $this->coreFields = $formatter->getData($driver, $formatter->getDefaults('fid-acquisition-subito-partial-copy'));
?> ?>
<?= $this->render('fid/record/acquisition-record-details'); ?> <?= $this->render('fid/record/acquisition-record-details'); ?>
</div> </div>
...@@ -69,9 +69,9 @@ $form->setAttribute('class','fid-acquisition-form'); ...@@ -69,9 +69,9 @@ $form->setAttribute('class','fid-acquisition-form');
$elemPages->setAttributes(['class' => 'form-control']); $elemPages->setAttributes(['class' => 'form-control']);
?> ?>
<div class="form-group"> <div class="form-group">
<?= $this->formElementErrors($elemPages) ?>
<?= $this->formLabel($elemPages) ?> <?= $this->formLabel($elemPages) ?>
<?= $this->formElement($elemPages) ?> <?= $this->formElement($elemPages) ?>
<?= $this->formElementErrors($elemPages) ?>
</div> </div>
</div> </div>
</div> </div>
......
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