From 5e972fd66da479e6453b6078d3af1b9dda0c5915 Mon Sep 17 00:00:00 2001 From: llaffont <laurent.laffont@gmail.com> Date: Sat, 25 Jan 2014 12:24:12 +0100 Subject: [PATCH] Album de type enregistrement audio: le bloc morceaux dans la notice permet de lire les pistes --- .../opac/controllers/NoticeajaxController.php | 26 ++++---- library/Class/AlbumRessource.php | 8 ++- library/Class/CodifTypeDoc.php | 5 ++ .../PseudoNotice/UnimarcVisitor.php | 5 +- library/Class/Notice.php | 41 +++++++------ library/Class/TypeDoc.php | 3 + ...echercheControllerAlbumAudioRecordTest.php | 61 +++++++++++++++++++ 7 files changed, 116 insertions(+), 33 deletions(-) diff --git a/application/modules/opac/controllers/NoticeajaxController.php b/application/modules/opac/controllers/NoticeajaxController.php index 30f27bbd7e7..d6705797696 100644 --- a/application/modules/opac/controllers/NoticeajaxController.php +++ b/application/modules/opac/controllers/NoticeajaxController.php @@ -294,33 +294,33 @@ class NoticeAjaxController extends Zend_Controller_Action { public function morceauxAction() { - // lire notice et controle type de doc - $notice=$this->notice->getNotice($this->id_notice,"JA"); - if($notice['type_doc'] !=3) return false; - + $notice = Class_Notice::find($this->id_notice,"JA"); + + if (!$notice->isTypeDocSonore()) + return false; + // dans la notice $morceaux=$this->notice->getMorceaux(); $source=$morceaux['source']; - //tracedebug($morceaux,true); // Chez amazon - if (!$morceaux["nb_resultats"]) - { + if (!$morceaux["nb_resultats"]) { $source = "Amazon"; $amazon = new Class_WebService_AmazonSonores(); - $morceaux = $amazon->rend_notice_ean($notice["ean"]); + $morceaux = $amazon->rend_notice_ean($notice->getEan()); } // Chez LastFm - if (!$morceaux["nb_resultats"]) - { + if (!$morceaux["nb_resultats"]) { $source="Last.fm"; $last_fm=new Class_WebService_Lastfm(); - $morceaux=$last_fm->getMorceaux($notice["J"],$notice["A"]); + $morceaux=$last_fm->getMorceaux($notice->getTitrePrincipal(), + $notice->getAuteurPrincipal()); } - $morceaux["id_notice"]=$notice["id_notice"]; + + $morceaux["id_notice"] = $notice->getId(); if (!$morceaux["nb_resultats"]) $source=""; - $morceaux["auteur"]=$notice["A"]; + $morceaux["auteur"] = $notice->getAuteurPrincipal(); $html=$this->notice_html->getMorceaux($morceaux,$source); $this->_sendResponse(Class_ScriptLoader::getInstance()->html().$html); } diff --git a/library/Class/AlbumRessource.php b/library/Class/AlbumRessource.php index 003e3f77a3a..f59def683c2 100644 --- a/library/Class/AlbumRessource.php +++ b/library/Class/AlbumRessource.php @@ -937,7 +937,13 @@ class Class_AlbumRessource extends Storm_Model_Abstract { public function acceptVisitor($visitor) { - $visitor->visitRessourceDatas($this->getTitre(), $this->getDuration(), $this->getAuteur()); + if (!$titre = $this->getTitre()) + $titre = $this->getFolio(); + + $visitor->visitRessourceDatas($titre, + $this->getDuration(), + $this->getAuteur(), + $this->getOriginalUrl()); } } diff --git a/library/Class/CodifTypeDoc.php b/library/Class/CodifTypeDoc.php index 45ac1fc0696..fe692f8b713 100644 --- a/library/Class/CodifTypeDoc.php +++ b/library/Class/CodifTypeDoc.php @@ -64,6 +64,11 @@ class Class_CodifTypeDoc extends Storm_Model_Abstract { $this->setId($this->getTypeDocId()); } + + public function isSonore() { + return $this->getFamilleId() == static::SONORE; + } + } ?> \ No newline at end of file diff --git a/library/Class/Indexation/PseudoNotice/UnimarcVisitor.php b/library/Class/Indexation/PseudoNotice/UnimarcVisitor.php index 6f839530ada..130b03be885 100644 --- a/library/Class/Indexation/PseudoNotice/UnimarcVisitor.php +++ b/library/Class/Indexation/PseudoNotice/UnimarcVisitor.php @@ -159,11 +159,12 @@ class Class_Indexation_PseudoNotice_UnimarcVisitor extends Class_Indexation_Pseu } - public function visitRessourceDatas($title, $duration, $authors) { + public function visitRessourceDatas($title, $duration, $authors, $url) { $this->unimarc->add_field('464', ' ', [['t', $title], ['a', $duration], - ['f', $authors]]); + ['f', $authors], + ['3', $url]]); return $this; } diff --git a/library/Class/Notice.php b/library/Class/Notice.php index c95e62d4568..b1d9e5dc24b 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -865,13 +865,11 @@ class Class_Notice extends Storm_Model_Abstract { // ---------------------------------------------------------------- // Morceaux de docs sonores // ---------------------------------------------------------------- - public function getMorceaux() - { + public function getMorceaux() { // detecter url_ecoute en 464$3 $data=$this->get_subfield('464', '3'); - - if(count($data)>0) - { + + if(count($data)>0) { $this->root_url_ecoute=Class_AdminVar::get('ROOT_URL_ECOUTE'); } else @@ -899,30 +897,29 @@ class Class_Notice extends Storm_Model_Abstract { { if($champ['code']=='t') { - $ret=$this->getMorceaux464_t($data464); + $ret = $this->getMorceaux464_t($data464); return $ret; break; } } - $ret=$this->getMorceaux464_a($data464); + $ret = $this->getMorceaux464_a($data464); return $ret; } // ---------------------------------------------------------------- // Morceaux de docs sonores titres en 464$t // ---------------------------------------------------------------- - private function getMorceaux464_t($data) - { - $volume=0; - $piste=0; - foreach($data as $champs) - { + private function getMorceaux464_t($data) { + $volume = 0; + $piste = 0; + $ret = ['nb_resultats' => 0, + 'nombre_volumes' => 0, + 'source' => 'Bibliothèque']; + foreach($data as $champs) { $champ=$this->decoupe_bloc_champ($champs); $titre=$auteur_nom=$auteur_prenom=$duree=$volume=$url_ecoute=''; - foreach($champ as $sous_champ) - { - switch($sous_champ['code']) - { + foreach($champ as $sous_champ) { + switch($sous_champ['code']) { case 't' : $titre=$sous_champ['valeur']; break; case 'd' : $duree=$sous_champ['valeur']; break; case 'a' : $auteur_nom=$sous_champ['valeur']; break; @@ -932,8 +929,11 @@ class Class_Notice extends Storm_Model_Abstract { } } if(!$titre) continue; + if($auteur_prenom) $auteur_nom=$auteur_prenom.' '.$auteur_nom; + if($auteur_nom) $titre.=' / '.$auteur_nom; + if($duree) $titre.=' '.$duree; $piste++; if(!$volume) $volume=1; @@ -1803,6 +1803,13 @@ class Class_Notice extends Storm_Model_Abstract { if ($this->isNew() and !$this->getDateCreation()) $this->setDateCreation(date('Y-m-d', $this->getCurrentTime())); } + + + public function isTypeDocSonore() { + if (!$type_doc = Class_TypeDoc::find($this->getTypeDoc())) + return false; + return $type_doc->isSonore(); + } } ?> \ No newline at end of file diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php index 8073a1aa261..a3f4b4741f6 100644 --- a/library/Class/TypeDoc.php +++ b/library/Class/TypeDoc.php @@ -325,6 +325,9 @@ class Class_TypeDoc extends Storm_Model_Abstract { 'label' => $this->getLabel()]; } + public function isSonore() { + return $this->getCodifTypeDoc()->isSonore(); + } } ?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php b/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php index c8a084abbfb..8f54fd1e1a4 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php @@ -53,6 +53,9 @@ abstract class RechercheControllerAlbumAudioRecordTestCase extends AbstractContr ['id' => 2, 'titre' => 'Infinite Dreams', 'fichier' => 'infinite_dreams.mp3'])) + ->addRessource($this->fixture('Class_AlbumRessource', + ['id' => 3, + 'fichier' => 'unknown.mp3'])) ->assertSave(); $album->index(); @@ -95,6 +98,64 @@ class RechercheControllerAlbumAudioRecordViewNoticeTest extends RechercheControl 'Seventh Son of a Seventh Son', $this->_response->getBody()); } + + + /** @test */ + public function noticeFirstMorceauTitleShouldBeMoonchild() { + $this->assertEquals('Moonchild', + $this->_notice->getMorceaux()['morceaux'][1][1]['titre']); + } + + + /** @test */ + public function noticeFirstMorceauUrlEcouteShouldBeMoonchildDotMP3() { + $this->assertContains('moonchild.mp3', + $this->_notice->getMorceaux()['morceaux'][1][1]['url_ecoute']); + } + + + /** @test */ + public function noticeSecondMorceauTitleShouldBeInfiniteDreams() { + $this->assertEquals('Infinite Dreams', + $this->_notice->getMorceaux()['morceaux'][1][2]['titre']); + } + + + /** @test */ + public function noticeUnknownMorceauTitleShouldBeUnknown() { + $this->assertEquals('unknown', + $this->_notice->getMorceaux()['morceaux'][1][3]['titre']); + } +} + + + + +class RechercheControllerAlbumAudioRecordViewMorceauxTest extends RechercheControllerAlbumAudioRecordTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/noticeajax/morceaux/id_notice/'.$this->_notice->getId(), true); + } + + + /** @test */ + public function moonchildPlayerShouldBePresent() { + $this->assertXPath('//audio/source[contains(@src, "moonchild.mp3")]', $this->_response->getBody()); + } + + + /** @test */ + public function moonchildTitleShouldBePresent() { + $this->assertXPathContentContains('//div[@class="notice_info_ligne"]', + '1: Moonchild'); + } + + + /** @test */ + public function infiniteDreamsTitleShouldBePresent() { + $this->assertXPathContentContains('//div[@class="notice_info_ligne"]', + '2: Infinite Dreams'); + } } ?> \ No newline at end of file -- GitLab