diff --git a/VERSIONS_WIP/73870 b/VERSIONS_WIP/73870 new file mode 100644 index 0000000000000000000000000000000000000000..f801a8f9c8325dd46ffc96046b7656be4bd9d8d7 --- /dev/null +++ b/VERSIONS_WIP/73870 @@ -0,0 +1,3 @@ + - ticket #73870 : Inspector Gadget : Après activation de la variable INSPECTOR_GADGET_MARC_XML, + l'Inspector Gadget d'une notice est capable d'afficher l'unimarc interne de Bokeh en marc-xml + \ No newline at end of file diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index 0a564dd66a9aa7b4c95b9f39ca0946c0a1f3ad19..9d0334e251500924b2c4889140f576f8761e7b77 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -363,7 +363,8 @@ class Class_AdminVarLoader extends Storm_Model_Loader { 'BUID' => Class_AdminVar_Meta::newRawText($this->_('Identifiant unique (attention: la modification de cette variable impactera les outils de suivi de cette installation)'))->bePrivate(), 'STATUS_REPORT_PUSH_URL' => Class_AdminVar_Meta::newRawText($this->_('URL destinataire du rapport d\'état du système (0 pour désactiver)'), ['value' => 'http://pola.afi-sa.net/smile.php'])->bePrivate(), 'STATUS_REPORT_TAGS' => Class_AdminVar_Meta::newMultiInput($this->_('Liste des tags à ajouter au rapport d\'état du système'))->bePrivate(), - 'FEATURES_TRACKING_ENABLE' => Class_AdminVar_Meta::newOnOff('Affiche les dernières modifications apportés au logiciel Bokeh', ['value' => 1])->bePrivate() + 'FEATURES_TRACKING_ENABLE' => Class_AdminVar_Meta::newOnOff('Affiche les dernières modifications apportés au logiciel Bokeh', ['value' => 1])->bePrivate(), + 'INSPECTOR_GADGET_MARC_XML' => Class_AdminVar_Meta::newOnOff('Affiche le MARC XML de la notice dans Inspector Gadget')->bePrivate() ]; } @@ -904,6 +905,11 @@ class Class_AdminVarLoader extends Storm_Model_Loader { } + public static function isInspectorGadgetMarcXmlEnabled() { + return Class_AdminVar::isModuleEnabled('INSPECTOR_GADGET_MARC_XML'); + } + + public function getBabelthequeId() { $mathes = []; if (preg_match('/bw_([^\.]+)\.js/', (string)Class_AdminVar::get('BABELTHEQUE_JS'), $matches)) diff --git a/library/Class/Testing/Yaz.php b/library/Class/Testing/Yaz.php new file mode 100644 index 0000000000000000000000000000000000000000..ab103b5f0786536383ac5161d281215160785267 --- /dev/null +++ b/library/Class/Testing/Yaz.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright (c) 2012-2017, 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_Testing_Yaz { + use Trait_StaticCommand, Trait_StaticFileSystem; + + + public function marcToMarcXml($unimarc) { + if(!$unimarc) + return []; + + $filename = $this->_writeUnimarcInFile($unimarc); + + $cmd = static::getCommand(); + $cmd->exec(sprintf('yaz-marcdump -i marc -o marcxml %s', $filename)); + + static::getFileSystem()->unlink($filename); + + return $cmd->getOutput(); + } + + + protected function _writeUnimarcInFile($unimarc) { + $filename = PATH_TEMP . md5($unimarc) . '.marc'; + static::getFileSystem()->unlink($filename); + static::getFileSystem()->file_put_contents($filename, $unimarc); + return $filename; + } +} \ No newline at end of file diff --git a/library/Trait/Yaz.php b/library/Trait/Yaz.php new file mode 100644 index 0000000000000000000000000000000000000000..d429a544e82b9725ad02ab1d230ebbcd0ffdbc11 --- /dev/null +++ b/library/Trait/Yaz.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright (c) 2012-2017, 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 + */ + + +trait Trait_Yaz { + protected static $_yaz; + + + public static function setYaz($yaz) { + static::$_yaz = $yaz; + } + + + public static function getYaz() { + if (null !== self::$_yaz) + return self::$_yaz; + return new Class_Testing_Yaz(); + } +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Notice/Unimarc.php b/library/ZendAfi/View/Helper/Notice/Unimarc.php index d0fc9699269513a95ca5c09096219b45a7c93e96..59eb531add46466bb57d9e0d7a776011e114da6d 100644 --- a/library/ZendAfi/View/Helper/Notice/Unimarc.php +++ b/library/ZendAfi/View/Helper/Notice/Unimarc.php @@ -21,7 +21,7 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement { - use Trait_Translator; + use Trait_Translator, Trait_Yaz; protected $_headers; protected $_zones; @@ -39,7 +39,8 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement { . $this->_tag('div', $this->renderTabs() . $this->renderZones($notice) - . $this->renderItems($notice), + . $this->renderItems($notice) + . $this->renderMarcXml($notice), ['class' => 'ig-tabs']); } @@ -67,11 +68,16 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement { protected function renderTabs() { - return $this->_tag('ul', - $this->_tag('li', $this->_tag('a', $this->_('Zones'), - ['href' => '#ig-tab-zones'])) - . $this->_tag('li', $this->_tag('a', $this->_('Exemplaires'), - ['href' => '#ig-tab-items']))); + $lis = [$this->_tag('li', $this->_tag('a', $this->_('Zones'), + ['href' => '#ig-tab-zones'])), + $this->_tag('li', $this->_tag('a', $this->_('Exemplaires'), + ['href' => '#ig-tab-items']))]; + + if(Class_AdminVar::isInspectorGadgetMarcXmlEnabled()) + $lis [] = $this->_tag('li', $this->_tag('a', $this->_('MARC-XML'), + ['href' => '#ig-tab-marc-xml'])); + + return $this->_tag('ul', implode($lis)); } @@ -141,6 +147,33 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement { } + protected function renderMarcXml($notice) { + if(!Class_AdminVar::isInspectorGadgetMarcXmlEnabled()) + return ''; + + $content = ($marc_xml = $this->_prettyPrint(static::getYaz()->marcToMarcXml($notice->getUnimarc()))) + ? $marc_xml + : $this->_tag('p', $this->_('Impossible d\'afficher le MARC-XML de cette notice.'), ['class' => 'error']); + + return $this->_tag('div', $content, ['id' => 'ig-tab-marc-xml']); + } + + + protected function _prettyPrint($marc_xml_array) { + if(!$marc_xml_array) + return ''; + + if(empty($marc_xml_array)) + return ''; + + $output = array_map(function($row) + { + return htmlspecialchars($row); + }, $marc_xml_array); + return implode(BR, $output); + } + + protected function renderItemDownload($item) { if (!Class_Cosmogramme_Integration_RawRecord::hasVersionFor($item)) return ''; diff --git a/public/opac/css/inspector-gadget/style.css b/public/opac/css/inspector-gadget/style.css index 288dae3b5a3667cfdc1e963833a0583b6db0def1..f7bf54c0a190dca1780f09175278872c044686d8 100644 --- a/public/opac/css/inspector-gadget/style.css +++ b/public/opac/css/inspector-gadget/style.css @@ -45,4 +45,8 @@ .inspector-gadget .ig-accordion { height: 100%; +} + +.inspector-gadget #ig-tab-marc-xml { + text-align: left; } \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/RechercheControllerViewnoticeTest.php b/tests/application/modules/opac/controllers/RechercheControllerViewnoticeTest.php index a382cf40781ebb1e466ae95ae18f56c2e224afe7..3b7dc0d0991196ae39534794bc0fc569fb8d265a 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerViewnoticeTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerViewnoticeTest.php @@ -91,4 +91,59 @@ class RechercheControllerSearchResultWithInspectorGadgetTest extends AbstractCon public function buttonConfigurationOfSearchShouldBePresent() { $this->assertXPathContentContains('//button', 'Configuration de la recherche'); } +} + + + + +class RechercheControllerViewnoticeWithInspectorGadgetAndMarcXMLEnabledTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + Class_AdminVar::set('INSPECTOR_GADGET_MARC_XML', 1); + + $cmd = $this->mock() + ->whenCalled('exec') + ->answers(true) + + ->whenCalled('getOutput') + ->answers(['<collection xmlns="http://www.loc.gov/MARC21/slim">', + '<record>', + '<leader>01185nam0a2200217 450 </leader>', + '<controlfield tag="001">2774</controlfield>', + '<datafield tag="010" ind1=" " ind2=" ">', + '<subfield code="a">2-84563-280-0</subfield>']); + + $filesystem = $this->mock() + ->whenCalled('unlink') + ->answers(true) + + ->whenCalled('file_put_contents') + ->answers(true); + + Class_Testing_Yaz::setCommand($cmd); + Class_Testing_Yaz::setFileSystem($filesystem); + + $this->fixture('Class_Notice', + ['id' => 2, + 'type_doc' => Class_TypeDoc::DILICOM, + 'unimarc' => "01185nam0 2200217 450 0010005000000100031000050350016000360900009000520990038000611000041000991010008001402000036001482100013001842150011001973300660002083330010008686760006008787000028008848010026009129020029009382774 a2-84563-280-0d19,90 Euros aALOES355754 a2774 c2017-12-11d2018-03-16tLIVREx12 a20171211 frey50 afre aSeras-tu là ?fGuillaume Musso cXOd2012 a301 p. aUn seul geste aurait suffi pour tout changer. Qui n'a jamais rêvé de revenir à cet instant décisif où le bonheur était possible ? San Francisco. Elliott, médecin passionné, ne s'est jamais consolé de la disparition d'Ilena, la femme qu'il aimait, morte il y a trente ans. Un jour, par une circonstance extraordinaire, il est ramené en arrière et rencontre le jeune homme qu'il était, trente ans plus tôt. Il est revenu à l'instant décisif où un geste de lui peut sauver Ilena. Et modifier l'implacable destin qui a figé son sort à jamais. Un stupéfiant face-à -face, Une histoire d'amour bouleversante, Un suspense à couper le souffle. aAG 14 aR aMussobGuillaume960415 aFRbCALUIREc20060516 981440aroman francophone", + 'alpha_titre' => '', + 'alpha_auteur' => '']); + + $this->dispatch('/opac/recherche/viewnotice/id/2/inspector_gadget/1', true); + } + + + /** @test */ + public function tabMarcXMLShouldBePresent() { + $this->assertXPathContentContains('//button[contains(@onclick, "#ig-tab-marc-xml")]', 'Notice Bokeh'); + } + + + /** @test */ + public function marcXMLShouldBePresent() { + $this->assertXPathContentContains('//button[contains(@onclick, "controlfield")]', 'Notice Bokeh'); + } } \ No newline at end of file