diff --git a/module/fid/config/fid-acquisition-subito-partial-copy-form.php b/module/fid/config/fid-acquisition-subito-partial-copy-form.php index 7bc4339be5696ecf3b5cd2d0304dbb0d86aa393b..bcd36f3f7158f1cd56391a62251de5bda8b8c2d4 100644 --- a/module/fid/config/fid-acquisition-subito-partial-copy-form.php +++ b/module/fid/config/fid-acquisition-subito-partial-copy-form.php @@ -19,7 +19,11 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 */ +use fid\Controller\RecordController; use fid\Hydrator\OrderHydrator; +use fid\Validator\SubitoPartialCopyPageLimit; +use fid\Validator\SubitoPartialCopyPageOrder; +use Zend\Filter\PregReplace; use Zend\Filter\StringTrim; use Zend\Form\Element\Submit; use Zend\Form\Element\Text; @@ -59,6 +63,13 @@ return [ StringTrim::class => [ 'name' => StringTrim::class, ], + PregReplace::class => [ + 'name' => PregReplace::class, + 'options' => [ + 'pattern' => '/(-|–|—|−)/', + 'replacement' => '-' + ] + ], ], 'validators' => [ StringLength::class => [ @@ -74,6 +85,7 @@ return [ ], Regex::class => [ 'name' => Regex::class, + 'break_chain_on_failure' => true, 'options' => [ 'pattern' => '/^(0|[1-9]\d*)-([1-9]\d*)$/', 'messages' => [ @@ -81,6 +93,14 @@ return [ ], ], ], + SubitoPartialCopyPageOrder::class => [ + 'name' => SubitoPartialCopyPageOrder::class, + 'options' => [ + 'messages' => [ + SubitoPartialCopyPageOrder::PAGES_ORDER => 'acquisition_error_page_order', + ], + ], + ], ], ], 'submit' => [ diff --git a/module/fid/src/Controller/CustomTraits/FidAcquisitionTrait.php b/module/fid/src/Controller/CustomTraits/FidAcquisitionTrait.php index 896170bae09bcdf3477bd9d00f9b4da8198a656c..4999b59b5b531db619be86660f0f4fd422183935 100644 --- a/module/fid/src/Controller/CustomTraits/FidAcquisitionTrait.php +++ b/module/fid/src/Controller/CustomTraits/FidAcquisitionTrait.php @@ -29,6 +29,8 @@ namespace fid\Controller\CustomTraits; use fid\Service\Client; use fid\Service\DataTransferObject\Order; +use fid\Validator\SubitoPartialCopyPageBounds; +use fid\Validator\SubitoPartialCopyPageSelection; use finc\View\Helper\Root\Citation; use Zend\Form\Form; use Zend\Http\PhpEnvironment\Request; @@ -154,13 +156,28 @@ trait FidAcquisitionTrait $request = $this->getRequest(); $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()) { $form->setData($request->getPost()); if ($form->isValid()) { $url = $this->getRecordUrl($recordId); $label = $this->getOrderLabel($driver); - $pages = $form->getData()['pages']; - $form->getHydrator()->hydrate(compact('driver','user', 'type', 'url', 'label', 'pages'), $order = new Order()); + $subitoPartialCopy = [ + 'selection' => $form->getData()['pages'] + ]; + $form->getHydrator()->hydrate(compact('driver','user', 'type', 'url', 'label', 'subitoPartialCopy'), $order = new Order()); $this->client->requestOrderCreation($order); $message = $this->translate('fid::acquisition_success'); $messenger->addSuccessMessage($message); @@ -168,10 +185,6 @@ trait FidAcquisitionTrait } } - $patron = $this->catalogLogin(); - $catalog = $this->getILS(); - $profile = $catalog->getMyProfile($patron); - $action = $this->url()->fromRoute('record-fidsubitopartialcopy',['id' => $recordId]); $form->setAttribute('action', $action); $form->prepare(); diff --git a/module/fid/src/Controller/RecordController.php b/module/fid/src/Controller/RecordController.php index 8b9bf816544636298bf28cf90acc60321d5e0ca1..0bd3d654f768c0658db12d129c4b729ff0829426 100644 --- a/module/fid/src/Controller/RecordController.php +++ b/module/fid/src/Controller/RecordController.php @@ -29,4 +29,6 @@ namespace fid\Controller; class RecordController extends \finc\Controller\RecordController { use CustomTraits\FidAcquisitionTrait; + + const PAGE_RANGE_PATTERN = '/^(0|[1-9]\d*)-([1-9]\d*)$/'; } diff --git a/module/fid/src/Controller/RecordControllerDelegatorFactory.php b/module/fid/src/Controller/RecordControllerDelegatorFactory.php index 5a53868764ce15b5144d905afe6abff0f3ad332a..84d8577d46bdc4ab2ada12ab15e7b93daeb14fbd 100644 --- a/module/fid/src/Controller/RecordControllerDelegatorFactory.php +++ b/module/fid/src/Controller/RecordControllerDelegatorFactory.php @@ -12,7 +12,6 @@ class RecordControllerDelegatorFactory implements DelegatorFactoryInterface /** @var RecordController $instance */ $instance = call_user_func($callback); $instance->setClient($container->get(Client::class)); - return $instance; } } \ No newline at end of file diff --git a/module/fid/src/Hydrator/OrderHydrator.php b/module/fid/src/Hydrator/OrderHydrator.php index 244ffcfe7f80c49658a93f2784210b1b231dd896..9edb7e79d937b346cf5298d39db0f31e58465fd3 100644 --- a/module/fid/src/Hydrator/OrderHydrator.php +++ b/module/fid/src/Hydrator/OrderHydrator.php @@ -27,7 +27,7 @@ class OrderHydrator extends AbstractHydrator { $object->setType($data['type']); $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 */ $id = $driver->tryMethod('getUniqueID'); @@ -64,7 +64,7 @@ class OrderHydrator extends AbstractHydrator { 'url' ); - $object->setData(compact('record','partialCopyPages')); + $object->setData(compact('record','partialCopy')); $object->setLabel($data['label']); return; } diff --git a/module/fid/src/Validator/SubitoPartialCopyPageBounds.php b/module/fid/src/Validator/SubitoPartialCopyPageBounds.php new file mode 100644 index 0000000000000000000000000000000000000000..18a68db0487722adb87f0dce19fefb8156738d3e --- /dev/null +++ b/module/fid/src/Validator/SubitoPartialCopyPageBounds.php @@ -0,0 +1,59 @@ +<?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; + } + } +} diff --git a/module/fid/src/Validator/SubitoPartialCopyPageOrder.php b/module/fid/src/Validator/SubitoPartialCopyPageOrder.php new file mode 100644 index 0000000000000000000000000000000000000000..74961ec79e83af7728ab74658f16ccff8bac6b07 --- /dev/null +++ b/module/fid/src/Validator/SubitoPartialCopyPageOrder.php @@ -0,0 +1,49 @@ +<?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; + } + } +} diff --git a/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php b/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..f828b0693901007ab2fa2361b2707b86e696cd2b --- /dev/null +++ b/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php @@ -0,0 +1,37 @@ +<?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 diff --git a/module/fid/src/Validator/SubitoPartialCopyPageSelection.php b/module/fid/src/Validator/SubitoPartialCopyPageSelection.php new file mode 100644 index 0000000000000000000000000000000000000000..2818ab17a8215788a75535c59c4332a9143d1025 --- /dev/null +++ b/module/fid/src/Validator/SubitoPartialCopyPageSelection.php @@ -0,0 +1,63 @@ +<?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; + } + } +} diff --git a/module/fid/src/View/Helper/Root/RecordDataFormatterFactory.php b/module/fid/src/View/Helper/Root/RecordDataFormatterFactory.php index 6b1261732bfb22233391423bb5371071b94b5393..185a746ac8c3583c87bea894c1e135f0e253564f 100644 --- a/module/fid/src/View/Helper/Root/RecordDataFormatterFactory.php +++ b/module/fid/src/View/Helper/Root/RecordDataFormatterFactory.php @@ -27,6 +27,7 @@ namespace fid\View\Helper\Root; use VuFind\View\Helper\Root\RecordDataFormatter; +use VuFind\View\Helper\Root\RecordDataFormatter\SpecBuilder; class RecordDataFormatterFactory { @@ -40,21 +41,19 @@ class RecordDataFormatterFactory $helper = new RecordDataFormatter(); $helper->setDefaults('fid-acquisition-general', [$this, 'getFidAcquisitionSpecs']); - //$helper->setDefaults('fid-pda', [$this, 'getFidPdaSpecs']); - //$helper->setDefaults('fid-subito-articel', [$this, 'getFidSubitoArticelSpecs']); - //$helper->setDefaults('fid-subito-partial-copy', [$this, 'getFidSubitoPartialCopySpecs']); + $helper->setDefaults('fid-acquisition-subito-partial-copy', [$this, 'getFidAcquisitionSubitoPartialCopySpecs']); return $helper; } /** - * Get specifications for displaying data in fid pda form. + * Get general specifications for displaying data in fid pda form. * * @return array */ - public function getFidAcquisitionSpecs() + public function getFidAcquisitionSpecBuilder() { - $spec = new RecordDataFormatter\SpecBuilder(); + $spec = new SpecBuilder(); $spec->setLine('Title','getTitle'); $spec->setTemplateLine( 'Authors/Corporations', @@ -80,6 +79,29 @@ class RecordDataFormatterFactory 'data-price.phtml' ); $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(); } } diff --git a/themes/fid/languages/fid/de.ini b/themes/fid/languages/fid/de.ini index 970c97e4919cd75787dedc7ab4184da1be58ae1b..df6b0f1566347729e8ed9ceb4281da87effa0786 100644 --- a/themes/fid/languages/fid/de.ini +++ b/themes/fid/languages/fid/de.ini @@ -144,11 +144,16 @@ acquisition_delivery_to = "Lieferung an" acquisition_info_requested_item = "Bestellung" acquisition_label_pages = "Seitenzahlen (von-bis)" acquisition_label_submit = "Bestellen" -acquisition_error_pages_too_short = "Zu wenig Zeichen" -acquisition_error_pages_too_long = "Zu viele Zeichen" -acquisition_error_pages_pattern = "Fehlerhaftes oder falsches Format" +acquisition_error_pages_too_short = "Ihre Eingabe hat zu wenige Zeichen. Bitte geben Sie mind. 3 Zeichen ein." +acquisition_error_pages_too_long = "Ihre Eingabe hat zu viele Zeichen. Bitte geben Sie max. 13 Zeichen ein." +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_partial_copy_confirmation = "Möchten Sie die Teilkopie 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_success = "Ihre Bestellung wurde entgegengenommen und wird nun von uns bearbeitet." \ No newline at end of file +acquisition_success = "Ihre Bestellung wurde entgegengenommen und wird nun von uns bearbeitet." + +number_of_pages = "Seiten" \ No newline at end of file diff --git a/themes/fid/languages/fid/en.ini b/themes/fid/languages/fid/en.ini index 3f1c0be6fefa26c25dd244ede967e21f24e84242..ecb16166624d90b50fbe217971a35b10f8fc16e1 100644 --- a/themes/fid/languages/fid/en.ini +++ b/themes/fid/languages/fid/en.ini @@ -142,11 +142,16 @@ acquisition_delivery_to = "Delivery to" acquisition_info_requested_item = "Order item" acquisition_label_pages = "Pages (from-to)" acquisition_label_submit = "Order" -acquisition_error_pages_too_short = "Too few characters" -acquisition_error_pages_too_long = "Too many characters" -acquisition_error_pages_pattern = "Inaccurate or wrong format" +acquisition_error_pages_too_short = "Your request has too few characters. Please enter at least 3 characters." +acquisition_error_pages_too_long = "Your request has too many characters. Please enter a maximum of 13 characters." +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_partial_copy_confirmation = "Do you like to order the partial copy?" 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_success = "Your order is received and will be processed now." + +number_of_pages = "Pages" \ No newline at end of file diff --git a/themes/fid/templates/fid/record/acquisition-subito-partial-copy.phtml b/themes/fid/templates/fid/record/acquisition-subito-partial-copy.phtml index d86c3dcc0503e4dd1362a6d5ff19950759f98a5b..5405b306203ebd3ff91628fdf5b1c939df11fe12 100644 --- a/themes/fid/templates/fid/record/acquisition-subito-partial-copy.phtml +++ b/themes/fid/templates/fid/record/acquisition-subito-partial-copy.phtml @@ -53,7 +53,7 @@ $form->setAttribute('class','fid-acquisition-form'); <div class="col col-md-6"> <?php $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'); ?> </div> @@ -69,9 +69,9 @@ $form->setAttribute('class','fid-acquisition-form'); $elemPages->setAttributes(['class' => 'form-control']); ?> <div class="form-group"> + <?= $this->formElementErrors($elemPages) ?> <?= $this->formLabel($elemPages) ?> <?= $this->formElement($elemPages) ?> - <?= $this->formElementErrors($elemPages) ?> </div> </div> </div>