From 19b185089328159181c98691666c16ade29fa3c8 Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@afi-sa.fr> Date: Wed, 18 Apr 2018 11:32:33 +0200 Subject: [PATCH] dev #73934 : explo bibliondemand , cosmogrammme can handle bibliondemand xml file --- library/Class/Cosmogramme/FileParser.php | 26 +++++++++++++++++-- .../Integration/Record/Bibliondemand.php | 8 ++++++ .../Integration/Record/DublinCore.php | 10 ++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/library/Class/Cosmogramme/FileParser.php b/library/Class/Cosmogramme/FileParser.php index c7c74cd5079..e9eb33259b3 100644 --- a/library/Class/Cosmogramme/FileParser.php +++ b/library/Class/Cosmogramme/FileParser.php @@ -33,6 +33,8 @@ abstract class Class_Cosmogramme_FileParser { const FORMAT_CSV = 5; const FORMAT_MARC21 = 6; const FORMAT_AVENIO = 8; + const FORMAT_DUBLIN_CORE =11; + protected static $_format_parsers = [self::FORMAT_UNIMARC => 'Marc', @@ -42,7 +44,8 @@ abstract class Class_Cosmogramme_FileParser { self::FORMAT_XML => 'Xml', self::FORMAT_CSV => 'Csv', self::FORMAT_MARC21 => 'Marc', - self::FORMAT_AVENIO => 'Ascii_Tab']; + self::FORMAT_AVENIO => 'Ascii_Tab', + self::FORMAT_DUBLIN_CORE => 'OaiDC']; protected $_file_handle, $_position, $_file_size, $_profil; protected $_errors = []; @@ -203,6 +206,7 @@ class Class_Cosmogramme_FileParser_Ascii_Pipe extends Class_Cosmogramme_FilePars + class Class_Cosmogramme_FileParser_Xml extends Class_Cosmogramme_FileParser { const READ_SIZE = 1024; @@ -215,13 +219,16 @@ class Class_Cosmogramme_FileParser_Xml extends Class_Cosmogramme_FileParser { $data = $profil->getAttributs(); $attributs = unserialize($data); + $this->_checkErrors(); + } + + protected function _checkErrors() { $this->_xml_separator = $attributs[5]['xml_balise_abonne']; if (!$this->_xml_separator) { $this->_errors[] = 'La balise Xml qui sépare les enregistrements n\'est pas définie.'; } } - protected function _next() { $start_record = '<' . $this->_xml_separator . '>'; $end_record = '</' . $this->_xml_separator . '>'; @@ -261,6 +268,21 @@ class Class_Cosmogramme_FileParser_Xml extends Class_Cosmogramme_FileParser { } +class Class_Cosmogramme_FileParser_OaiDC extends Class_Cosmogramme_FileParser_Xml { + public function __construct($file, $position, $profil) { + $this->_xml_separator = 'record'; + parent::__construct($file, $position, $profil); + $data = $profil->getAttributs(); + $attributs = unserialize($data); + return new Class_Cosmogramme_FileParser_Record($data); + } + + + protected function _checkErrors() { + } + + +} class Class_Cosmogramme_FileParser_Csv extends Class_Cosmogramme_FileParser_Ascii { protected $_separator = ','; diff --git a/library/Class/Cosmogramme/Integration/Record/Bibliondemand.php b/library/Class/Cosmogramme/Integration/Record/Bibliondemand.php index 4cd5ae5d08f..61d549e181d 100644 --- a/library/Class/Cosmogramme/Integration/Record/Bibliondemand.php +++ b/library/Class/Cosmogramme/Integration/Record/Bibliondemand.php @@ -21,6 +21,14 @@ class Class_Cosmogramme_Integration_Record_Bibliondemand extends Class_Cosmogramme_Integration_Record_DublinCore { + + + protected function _parseDatas($data) { + $parser = new Class_WebService_OAI_DublinCoreParser_Bibliondemand(); + return $parser->parse($data)[0]; + } + + protected function _dublinCoreToUnimarc() { $visitor = parent::_dublinCoreToUnimarc(); $visitor diff --git a/library/Class/Cosmogramme/Integration/Record/DublinCore.php b/library/Class/Cosmogramme/Integration/Record/DublinCore.php index d79e9d5efe5..f08e60b4ecf 100644 --- a/library/Class/Cosmogramme/Integration/Record/DublinCore.php +++ b/library/Class/Cosmogramme/Integration/Record/DublinCore.php @@ -32,6 +32,7 @@ class Class_Cosmogramme_Integration_Record_DublinCore extends notice_unimarc { public function ouvrirNotice($data, $id_data_profile, $sigb, $type_doc_force) { $this->_profil = Class_IntProfilDonnees::find($id_data_profile); + $data = $this->_parseDatas($data); $this->_types = $data['type']; $this->_formats = $data['format']; $this->_datas = $data; @@ -40,10 +41,17 @@ class Class_Cosmogramme_Integration_Record_DublinCore extends notice_unimarc { return parent::ouvrirNotice($unimarc, $id_data_profile, $sigb, $type_doc_force); } + protected function _parseDatas($data) { + return $data; + } protected function _dublinCoreToUnimarc() { $authors = $this->_authorsFrom($this->_datas['auteur']); + $first_language=is_array($this->_datas['language']) + ? reset($this->_datas['language']) + : $this->_datas['language']; + $unimarc_visitor = new Class_Indexation_PseudoNotice_UnimarcVisitor(); $unimarc_visitor ->visitIdNotice($this->_datas['id_oai']) @@ -53,7 +61,7 @@ class Class_Cosmogramme_Integration_Record_DublinCore extends notice_unimarc { ->visitDescriptions($this->_datas['rights']) ->visitDescriptions($this->_datas['relation']) ->visitYear($this->_datas['date']) - ->visitLanguageId(reset($this->_datas['language'])) + ->visitLanguageId($first_language) ->visitMatiere(implode(';', $this->_datas['matiere'])) ->visitEditors($this->_datas['editeur']) ->visitItems($this->_getItem()) -- GitLab