From ea556cd5c7f689a66d1bad024e57a3085e08b92a Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-loas.afi-sa.net> Date: Fri, 7 Feb 2014 10:09:11 +0100 Subject: [PATCH] rel #11216 add audio player to album type doc audio record --- library/Class/Album.php | 14 ++++++ library/Class/AlbumRessource.php | 11 +++++ library/ZendAfi/View/Helper/RenderAlbum.php | 3 ++ .../ZendAfi/View/Helper/TagAlbumTrackList.php | 44 +++++++++++++++++++ ...echercheControllerAlbumAudioRecordTest.php | 24 ++++++++++ 5 files changed, 96 insertions(+) create mode 100644 library/ZendAfi/View/Helper/TagAlbumTrackList.php diff --git a/library/Class/Album.php b/library/Class/Album.php index ddbf7beb5e1..788fdb938dc 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -423,6 +423,11 @@ class Class_Album extends Storm_Model_Abstract { return $this->getTypeDocId() == Class_TypeDoc::EPUB; } + + public function isAudioRecord() { + return $this->getTypeDocId() == Class_TypeDoc::AUDIO_RECORD; + } + public function beCoursToutApprendre() { return $this->setTypeDocId(Class_TypeDoc::TOUTAPPRENDRE); @@ -1246,6 +1251,15 @@ class Class_Album extends Storm_Model_Abstract { } + public function getAudioTracks() { + return array_filter(array_map( + function($item){ + return $item->isAudio() ? $item : null; + }, + $this->getRessources())); + } + + /** * Return arteVOD poster url * @return string diff --git a/library/Class/AlbumRessource.php b/library/Class/AlbumRessource.php index d9a15168f59..2c5d51a00d4 100644 --- a/library/Class/AlbumRessource.php +++ b/library/Class/AlbumRessource.php @@ -48,6 +48,7 @@ class Class_AlbumRessource extends Storm_Model_Abstract { const DURATION_TRACK_FIELD = '464$a'; protected static $_image_extensions = ['png', 'jpg', 'jpeg', 'gif']; + protected static $_audio_extensions = ['mp3', 'ogg', 'wav']; protected static $THUMBNAILS_BY_EXT = ['swf' => 'flash-logo.jpg', 'mov' => 'quicktime-logo.png', @@ -105,6 +106,11 @@ class Class_AlbumRessource extends Storm_Model_Abstract { return self::$_image_extensions; } + + public static function getAudioExtensions() { + return self::$_audio_extensions; + } + /** * Les fichiers sont formattés ID_NOM_DU_FICHIER.EXT @@ -784,6 +790,11 @@ class Class_AlbumRessource extends Storm_Model_Abstract { } + public function isAudio() { + return $this->isFileExtensionIn($this->getAudioExtensions()); + } + + /** * @return string */ diff --git a/library/ZendAfi/View/Helper/RenderAlbum.php b/library/ZendAfi/View/Helper/RenderAlbum.php index 14753e469a4..e2da3bcc4c3 100644 --- a/library/ZendAfi/View/Helper/RenderAlbum.php +++ b/library/ZendAfi/View/Helper/RenderAlbum.php @@ -57,6 +57,9 @@ class ZendAfi_View_Helper_RenderAlbum extends Zend_View_Helper_HtmlElement { if ($album->isEPUB()) return $this->view->monocleReaderServerSide($album); + if ($album->isAudioRecord()) + return $this->view->tagAlbumTrackList($album); + return $this->view->tagAlbumMediaList($album); } } diff --git a/library/ZendAfi/View/Helper/TagAlbumTrackList.php b/library/ZendAfi/View/Helper/TagAlbumTrackList.php new file mode 100644 index 00000000000..5a9bb56014f --- /dev/null +++ b/library/ZendAfi/View/Helper/TagAlbumTrackList.php @@ -0,0 +1,44 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_View_Helper_TagAlbumTrackList extends Zend_View_Helper_HtmlElement { + /** + * Exemple: + * $this->audioJsPlayer(); + * Voir: http://kolber.github.com/audiojs/ + */ + public function tagAlbumTrackList($album) { + $audio_tracks = $album->getAudioTracks(); + $html = '<ol>'; + foreach($audio_tracks as $audio_track){ + $html.= + '<li class="audio_track">'. + $this->view->albumRessourceInfos($audio_track). + $this->view->audioJsPlayer($audio_track->getOriginalUrl()). + '</li>'; + } + return $html.='</ol>'; + } + +} + +?> \ 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 ec21f215004..44ce3b8b1fd 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php @@ -199,4 +199,28 @@ class RechercheControllerAlbumAudioRecordViewDetailsTest extends RechercheContro } } + + +class RechercheControllerAlbumAudioRecordViewRessourcesNumeriquesTest extends RechercheControllerAlbumAudioRecordTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/noticeajax/resnumeriques/id_notice/'.$this->_notice->getId(), true); + } + + /** @test */ + public function moonchildPlayerShouldBePresent() { + $this->assertXPath('//ol//li//audio/source[contains(@src, "moonchild.mp3")]', $this->_response->getBody()); + } + + + /** @test */ + public function titreShouldContainsMoonchild() { + $this->assertXPathContentContains('//ol//li', 'Moonchild'); + } + + /** @test **/ + public function liShouldBeFileNameunknown() { + $this->assertXPathContentContains('//ol//li', 'unknown.mp3'); + } +} ?> \ No newline at end of file -- GitLab