From a698106415e38feac05c0533539c7bda4190afbe Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Tue, 20 Aug 2013 15:48:19 +0000 Subject: [PATCH] =?UTF-8?q?ArteVod=20+=20ressources=20num=C3=A9riques:=20i?= =?UTF-8?q?ndexation=20de=20l'auteur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../php/classes/classe_notice_integration.php | 48 ++++++++----- .../php/classes/NoticeIntegrationTest.php | 67 ++++++++++++------- library/Class/Album.php | 2 +- .../BibNumerique/ArteVOD/FilmReader.php | 28 +++++++- library/startup.php | 2 +- .../WebService/ArteVOD/FilmReaderTest.php | 2 +- 6 files changed, 102 insertions(+), 47 deletions(-) diff --git a/cosmogramme/php/classes/classe_notice_integration.php b/cosmogramme/php/classes/classe_notice_integration.php index cbc5e053e18..af81ba56f64 100644 --- a/cosmogramme/php/classes/classe_notice_integration.php +++ b/cosmogramme/php/classes/classe_notice_integration.php @@ -414,7 +414,14 @@ class notice_integration if ($enreg["sous_titre"]) $this->notice_sgbd->add_field("200","1 ","e".$enreg["sous_titre"]); - if($enreg["auteur"]) $this->notice_sgbd->add_field("700","1 ","a".$enreg["auteur"]); + if($auteur = $enreg["auteur"]) { + $this->notice_sgbd->add_field("700","1 ","a".$auteur); + $auteur = str_replace([','], [''], $auteur); + + if ($facette_auteur = $this->getFacetteAuteur($auteur)) + $facettes .= ' '.$facette_auteur; + } + if($enreg["editeur"]) $this->notice_sgbd->add_field("210","1 ","c".$enreg["editeur"]); if($enreg["annee"]) $this->notice_sgbd->add_field("210"," ","d".$enreg["annee"]); if($enreg["id_langue"]) $this->notice_sgbd->add_field("101","0 ","a".$enreg["id_langue"]); @@ -543,6 +550,7 @@ class notice_integration $ret["id_notice"]=$id_notice; $ret["unimarc"]=$data["unimarc"]; $ret["code_barres"]=$code_barres; + $ret["facettes"]=$facettes; return $ret; } @@ -979,20 +987,9 @@ class notice_integration // Auteurs if($this->notice["auteurs"]) { - foreach($this->notice["auteurs"] as $auteur) - { - $code_alpha=$this->indexation->alphaMaj($auteur); - $code_alpha=str_replace(" ","x",$code_alpha); - if(!$code_alpha) continue; - $enreg=$sql->fetchEnreg("Select * from codif_auteur where MATCH(formes) AGAINST('\"".$code_alpha."\"' IN BOOLEAN MODE) "); - if(!$enreg["id_auteur"]) - { - $pos=strscan($auteur,"|"); - $nom_prenom = trim(substr($auteur,($pos+1))." ".substr($auteur,0,$pos)); - $id_auteur=$sql->insert("codif_auteur",array("libelle" => $nom_prenom,"formes" => $code_alpha)); - } - else $id_auteur=$enreg["id_auteur"]; - $facettes[]="A".$id_auteur; + foreach($this->notice["auteurs"] as $auteur) { + if ($facette_auteur= $this->getFacetteAuteur($auteur)) + $facettes []= $facette_auteur; } } @@ -1050,6 +1047,27 @@ class notice_integration } } + + public function getFacetteAuteur($auteur) { + global $sql; + $code_alpha=$this->indexation->alphaMaj($auteur); + if (!$code_alpha=str_replace(" ","x",$code_alpha)) + return; + + $enreg=$sql->fetchEnreg("Select * from codif_auteur where MATCH(formes) AGAINST('\"".$code_alpha."\"' IN BOOLEAN MODE)"); + if(!$enreg["id_auteur"]) { + $nom_prenom = (-1 < $pos=strscan($auteur,"|")) + ? trim(substr($auteur,($pos+1))." ".substr($auteur,0,$pos)) + : $auteur; + + $id_auteur=$sql->insert("codif_auteur",array("libelle" => $nom_prenom,"formes" => $code_alpha)); + } + else + $id_auteur=$enreg["id_auteur"]; + + return "A".$id_auteur; + } + // -------------------------------------------------------------------------------- // Ecrit une notice : article de périodique // -------------------------------------------------------------------------------- diff --git a/cosmogramme/tests/php/classes/NoticeIntegrationTest.php b/cosmogramme/tests/php/classes/NoticeIntegrationTest.php index 88d6c1ba6db..2d2c81fd7c2 100644 --- a/cosmogramme/tests/php/classes/NoticeIntegrationTest.php +++ b/cosmogramme/tests/php/classes/NoticeIntegrationTest.php @@ -25,29 +25,27 @@ require_once 'ModelTestCase.php'; abstract class NoticeIntegrationAbstract extends ModelTestCase { - protected $notice_sgbd; - public function expectVariable($index, $name, $value) { - global $sql; - $sql->expects($this->at($index)) - ->method('fetchOne') - ->with("Select valeur from variables where clef='".$name."'") - ->will($this->returnValue($value)); - return $this; - } - + protected + $notice_sgbd, + $_mock_sql; + public function setUp() { parent::setUp(); + global $sql; - $sql=$this->getMock('NullSql',['fetchOne', - 'execute', - 'fetchAll', - 'insert', - 'update', - 'fetchEnreg']); + $sql = $this->_mock_sql = Storm_Test_ObjectWrapper::mock(); $this->getMock('NullSql',['fetchOne', + 'execute', + 'fetchAll', + 'insert', + 'update', + 'fetchEnreg']); - $sql->expects($this->any()) - ->method('execute') - ->will($this->returnValue(true)); + $this->_mock_sql + ->whenCalled('execute')->answers(true) + ->whenCalled('fetchAll')->answers(null) + ->whenCalled('insert')->answers(null) + ->whenCalled('update')->answers(null) + ->whenCalled('fetchEnreg')->answers(null); VariableCache::getInstance() @@ -94,14 +92,19 @@ class NoticeIntegrationLivreNumTest extends NoticeIntegrationAbstract { ->with(6) ->answers(Class_CodifThesaurus::newInstanceWithId(25, ['id_thesaurus' => 29])); + $this->_mock_sql + ->whenCalled('fetchEnreg') + ->with("Select * from codif_auteur where MATCH(formes) AGAINST('\"LABORITxHENRI\"' IN BOOLEAN MODE)") + ->answers(['id_auteur' => 234]); - $ret = $notice_integration->traitePseudoNotice(100, - ['titre'=>'Eloge de la fuite', - 'tags'=> 'domination,sociologie,biologie', - 'id_origine' => '666', - 'domaine_ids' => '5;6', - 'nature_doc' => '1;2']); - $this->notice_sgbd->ouvrirNotice($ret['unimarc'],0); + $this->ret = $notice_integration->traitePseudoNotice(100, + ['titre'=>'Eloge de la fuite', + 'tags'=> 'domination,sociologie,biologie', + 'auteur' => 'Laborit Henri', + 'id_origine' => '666', + 'domaine_ids' => '5;6', + 'nature_doc' => '1;2']); + $this->notice_sgbd->ouvrirNotice($this->ret['unimarc'],0); } @@ -112,6 +115,18 @@ class NoticeIntegrationLivreNumTest extends NoticeIntegrationAbstract { } + /** @test */ + public function auteurShouldBeHenriLaborit() { + $this->assertContains('A234', $this->ret['facettes']); + } + + + /** @test */ + public function facetteAuteurShouldBeA234() { + $this->assertEquals('Laborit Henri',$this->notice_sgbd->get_subfield("700","a")[0]); + } + + /** @test */ public function subfield200_b_ShouldContainsCollectionAndDataset() { $this->assertEquals(['Collection', 'Dataset'], $this->notice_sgbd->get_subfield('200', 'b')); diff --git a/library/Class/Album.php b/library/Class/Album.php index 76097119ce5..46cff20534c 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -57,7 +57,7 @@ class AlbumLoader extends Storm_Model_Loader { public function getItemsOf($categoryId) { - return $this->findAll('select id, titre, type_doc_id from album where cat_id=' . $categoryId); + return $this->findAll('select id, titre, type_doc_id from album where cat_id=' . $categoryId .' order by titre'); } } diff --git a/library/Class/WebService/BibNumerique/ArteVOD/FilmReader.php b/library/Class/WebService/BibNumerique/ArteVOD/FilmReader.php index 5a1e4951cff..45c33f43ae9 100644 --- a/library/Class/WebService/BibNumerique/ArteVOD/FilmReader.php +++ b/library/Class/WebService/BibNumerique/ArteVOD/FilmReader.php @@ -22,6 +22,7 @@ class Class_WebService_Bibnumerique_ArteVOD_FilmReader { protected $_xml_parser; protected $_film; + protected $_current_author; public function parseContentOn($xml, $film) { $this->_film = $film; @@ -54,9 +55,30 @@ class Class_WebService_Bibnumerique_ArteVOD_FilmReader { } - public function endFull_Name($data) { - if ($this->_xml_parser->inParents('authors')) - $this->_film->addAuthor($data); + public function startPerson($data) { + if ($this->_xml_parser->inParents('authors')) { + $this->_current_author = new StdClass(); + } + } + + + public function endFirst_Name($data) { + if ($this->_xml_parser->inParents('authors')) { + $this->_current_author->first_name = $data; + } + } + + + public function endLast_Name($data) { + if ($this->_xml_parser->inParents('authors')) { + $this->_current_author->last_name = $data; + } + } + + public function endPerson($data) { + if ($this->_xml_parser->inParents('authors')) { + $this->_film->addAuthor($this->_current_author->last_name.' '.$this->_current_author->first_name); + } } diff --git a/library/startup.php b/library/startup.php index dfef7b5984f..68c31c6f38c 100644 --- a/library/startup.php +++ b/library/startup.php @@ -135,7 +135,7 @@ function setupCache($cfg) { $frontendOptions = [ 'lifetime' => 3600, // durée du cache: 1h 'automatic_serialization' => false, - 'caching' => true]; + 'caching' => false]; $use_memcached = (MEMCACHED_ENABLE === true); $backendOptions = $use_memcached diff --git a/tests/library/Class/WebService/ArteVOD/FilmReaderTest.php b/tests/library/Class/WebService/ArteVOD/FilmReaderTest.php index 54193591fe4..4b610f4f2e5 100644 --- a/tests/library/Class/WebService/ArteVOD/FilmReaderTest.php +++ b/tests/library/Class/WebService/ArteVOD/FilmReaderTest.php @@ -65,7 +65,7 @@ class ArteVOD_FilmReaderTest extends PHPUnit_Framework_TestCase { /** @test */ public function authorShouldBeFlorentTrochel() { $authors = $this->_film->getAuthors(); - $this->assertEquals('Florent Trochel', current($authors)); + $this->assertEquals('Trochel Florent', current($authors)); } -- GitLab