From 9b19c45137a5a10d748ad0e47500e94b1f7abb25 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@afi-sa.fr> Date: Tue, 24 Feb 2015 12:05:03 +0100 Subject: [PATCH] rd #14085 pnb extract loan duration --- library/Class/Album.php | 7 +++- library/Class/Album/Marc.php | 3 +- library/Class/Album/UsageConstraint.php | 33 ++++++++++++++++ library/Class/Album/UsageConstraints.php | 29 ++++++++++++++ .../WebService/BibNumerique/Dilicom/Book.php | 12 +++++- .../BibNumerique/Dilicom/ONIXFile.php | 38 ++++++++++++++++++- library/storm | 2 +- .../Dilicom/PNBOffersParserTest.php | 17 +++++++++ 8 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 library/Class/Album/UsageConstraint.php create mode 100644 library/Class/Album/UsageConstraints.php diff --git a/library/Class/Album.php b/library/Class/Album.php index ff692082ff7..894af3273e6 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -103,7 +103,12 @@ class Class_Album extends Storm_Model_Abstract { protected $_has_many = ['ressources' => ['model' => 'Class_AlbumRessource', 'role' => 'album', 'dependents' => 'delete', - 'order' => 'ordre']]; + 'order' => 'ordre'], + + 'usage_constraints' => ['model' => 'Class_Album_UsageConstraint', + 'role' => 'album', + 'instance_of' => 'Class_Album_UsageConstraints', + 'dependents' => 'delete']]; protected $_default_attribute_values = ['titre' => '', 'sous_titre' => '', diff --git a/library/Class/Album/Marc.php b/library/Class/Album/Marc.php index a4e139d91fe..a0034a8abae 100644 --- a/library/Class/Album/Marc.php +++ b/library/Class/Album/Marc.php @@ -100,7 +100,8 @@ class Class_Album_Marc { } } - return $this->addZone($field, [[ $subfield, $value ]]); + return $this->addZone($field, + [ [ $subfield, $value ] ] ); } diff --git a/library/Class/Album/UsageConstraint.php b/library/Class/Album/UsageConstraint.php new file mode 100644 index 00000000000..707c416f3be --- /dev/null +++ b/library/Class/Album/UsageConstraint.php @@ -0,0 +1,33 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Album_UsageConstraint extends Storm_Model_Abstract { + const LOAN_CONSTRAINT = '06'; + + protected $_belongs_to = ['album' => ['model' => 'Class_Album']]; + + public function isLoanConstraint() { + return $this->getUsageType() == self::LOAN_CONSTRAINT; + } +} + +?> \ No newline at end of file diff --git a/library/Class/Album/UsageConstraints.php b/library/Class/Album/UsageConstraints.php new file mode 100644 index 00000000000..3126f5f11a1 --- /dev/null +++ b/library/Class/Album/UsageConstraints.php @@ -0,0 +1,29 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Album_UsageConstraints extends Storm_Model_Collection_Abstract { + public function getLoanDuration() { + return $this->detect(function($c) {return $c->isLoanConstraint();})->getLoanDuration(); + } +} + +?> \ No newline at end of file diff --git a/library/Class/WebService/BibNumerique/Dilicom/Book.php b/library/Class/WebService/BibNumerique/Dilicom/Book.php index 193f24f4611..e0191cfa81a 100644 --- a/library/Class/WebService/BibNumerique/Dilicom/Book.php +++ b/library/Class/WebService/BibNumerique/Dilicom/Book.php @@ -24,7 +24,8 @@ class Class_WebService_BibNumerique_Dilicom_Book extends Class_WebService_BibNum protected $_isbn, $_subtitle, - $_collections = []; + $_collections = [], + $_usage_constraints = []; public function fillAlbum($album) { @@ -32,7 +33,8 @@ class Class_WebService_BibNumerique_Dilicom_Book extends Class_WebService_BibNum ->setTypeDoc(Class_TypeDoc::find(Class_TypeDoc::DILICOM)) ->setISBN($this->_isbn) ->setSousTitre($this->_subtitle) - ->addEditor($this->getEditeur()); + ->addEditor($this->getEditeur()) + ->setUsageConstraints($this->_usage_constraints); array_map([$album, 'addAuthor'], $this->getAuthors()); array_map([$album, 'addCollection'], $this->_collections); @@ -48,6 +50,12 @@ class Class_WebService_BibNumerique_Dilicom_Book extends Class_WebService_BibNum $this->_collections []= $collection; } + + public function addUsageConstraint($constraint) { + $this->_usage_constraints []= $constraint; + } + + public function setIsbn($isbn) { $this->_isbn = $isbn; return $this; diff --git a/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php b/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php index 8539597c100..24008d3fb44 100644 --- a/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php +++ b/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php @@ -29,7 +29,8 @@ class Class_WebService_BibNumerique_Dilicom_ONIXFile { TEXT_TYPE_DESCRIPTION = '03', LANG_ROLE_TEXT_LANG = '01', RESOURCE_CONTENT_TYPE_FRONT_COVER = '01', - RESOURCE_CONTENT_TYPE_WIDGET = '16'; + RESOURCE_CONTENT_TYPE_WIDGET = '16', + USAGE_UNIT_DAYS = '09'; protected $_parser, @@ -40,6 +41,9 @@ class Class_WebService_BibNumerique_Dilicom_ONIXFile { $_current_product_id_value, $_current_resource_content_type, $_current_language_role, + $_current_usage_constraint, + $_current_quantity, + $_current_usage_unit, $_tag_mapping = ['B203' => 'TitleText', 'B221' => 'ProductIDType', 'B244' => 'IDValue', @@ -53,7 +57,10 @@ class Class_WebService_BibNumerique_Dilicom_ONIXFile { 'B253' => 'LanguageRole', 'B252' => 'LanguageCode', 'X435' => 'ResourceLink', - 'X436' => 'ResourceContentType']; + 'X436' => 'ResourceContentType', + 'X318' => 'EPubUsageType', + 'X320' => 'Quantity', + 'X321' => 'EPubUsageUnit']; public function __construct() { @@ -77,6 +84,7 @@ class Class_WebService_BibNumerique_Dilicom_ONIXFile { public function parseXML($xml) { $this->_book = new Class_WebService_BibNumerique_Dilicom_Book(); + $this->_resources = []; $this->_parser = (new Class_WebService_FasterXMLParser()); $this->_parser @@ -188,5 +196,31 @@ class Class_WebService_BibNumerique_Dilicom_ONIXFile { $this->_book->setExternalURI($content); } } + + + public function startEPubUsageConstraint() { + $this->_book->addUsageConstraint($this->_current_usage_constraint = new Class_Album_UsageConstraint()); + } + + + public function endEPubUsageType($content) { + $this->_current_usage_constraint->setUsageType($content); + } + + + public function endEPubUsageLimit() { + if ($this->_current_usage_unit == self::USAGE_UNIT_DAYS) + $this->_current_usage_constraint->setLoanDuration($this->_current_quantity); + } + + + public function endQuantity($content) { + $this->_current_quantity = $content; + } + + + public function endEPubUsageUnit($content) { + $this->_current_usage_unit = $content; + } } ?> \ No newline at end of file diff --git a/library/storm b/library/storm index aa890c69508..0d3f5dd76ba 160000 --- a/library/storm +++ b/library/storm @@ -1 +1 @@ -Subproject commit aa890c69508b0c9f62cb2313f9ae8269890d9ce1 +Subproject commit 0d3f5dd76ba2030bc022f4513a43240d52b6bfe2 diff --git a/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php b/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php index 78325df0030..27d99caf8b5 100644 --- a/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php +++ b/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php @@ -86,6 +86,23 @@ class DilicomPNBOfferParserTest extends Storm_Test_ModelTestCase { } + /** + * @depends firstAlbumShouldBePlusJamaisSansElle + * @test + */ + public function firstAlbumShouldHaveSixUsageConstraints($album) { + $this->assertCount(6, $album->getUsageConstraints()); + } + + + /** + * @depends firstAlbumShouldBePlusJamaisSansElle + * @test + */ + public function firstAlbumLoanDurationShouldBe59($album) { + $this->assertEquals(59, $album->getUsageConstraints()->getLoanDuration()); + } + /** @test */ public function secondAlbumShouldBeJournalDunDegonfle() { -- GitLab