Skip to content
Snippets Groups Projects
Commit 53547bbd authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #14091 : added new view helper dedicated to audio album playing mode

parent 1d6e049e
Branches
Tags
5 merge requests!258Dev/13872 Orphee Allow Hold Available Items,!215Dev#12992 Custom Fields,!209Hotline#13914 Album Link Config Menu,!207Dev#14091 Audio Album Playing Mode,!192Dev#14091 Audio Album Playing Mode
<?php
/**
* Copyright (c) 2012-2014, 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_AlbumAudioJsPlayer extends Zend_View_Helper_HtmlElement {
use Trait_Translator;
public function albumAudioJsPlayer($album) {
$audiojs_path = URL_ADMIN_JS.'audiojs/audiojs/';
$options = ['swfLocation' => URL_ADMIN_JS.'audiojs/audiojs/audiojs.swf',
'imageLocation' => URL_ADMIN_JS.'audiojs/audiojs/player-graphics.gif'];
Class_ScriptLoader::getInstance()
->addStyleSheet(URL_ADMIN_JS.'audiojs/audiojs/style-light.css')
->addAdminScript('audiojs/audiojs/audio.min.js')
->addInlineScript('
$(function() {
var a = audiojs.createAll({
swfLocation: "' . $audiojs_path . 'audiojs.swf",
imageLocation: "' . $audiojs_path . 'player-graphics.gif",
trackEnded: function() {
var next = $("ol li.playing").next();
if (!next.length) next = $("ol li.audio_track").first();
next.click();
}
});
// Load in the first track
var audio = a[0];
first = $("ol li.audio_track a").attr("data-src");
$("ol li.audio_track").first().addClass("playing");
audio.load(first);
// Load in a track on click
$("ol li.audio_track").click(function(e) {
e.preventDefault();
$(this).addClass("playing").siblings().removeClass("playing");
audio.load($("a", this).attr("data-src"));
audio.play();
});
$(".audio_tracks_control .previous").click(function(e) {
e.preventDefault();
var prev = $("li.playing").prev();
if (!prev.length) prev = $("ol li.audio_track").last();
prev.click();
});
$(".audio_tracks_control .next").click(function(e) {
e.preventDefault();
var next = $("li.playing").next();
if (!next.length) next = $("ol li.audio_track").first();
next.click();
});
});');
return $this->renderAudioControl() . $this->renderTracksOf($album);
}
protected function renderAudioControl() {
return
'<audio preload></audio>'
. '<div class="audio_tracks_control">'
. '<a href="#" class="previous">&lt;&lt; '. $this->_('Piste précédente').'</a> '
. '<a href="#" class="next">' . $this->_('Piste suivante') . ' &gt;&gt;</a></div>';
}
protected function renderTracksOf($album) {
$html = '';
foreach($album->getAudioTracks() as $track)
$html .= $this->renderTrack($track);
return '<ol>' . $html . '</ol>';
}
protected function renderTrack($track) {
return
sprintf('<li class="audio_track"><a href="#" data-src="%s">%s</a></li>',
$this->view->album_PlayRessourceUrl($track),
$this->view->albumRessourceInfos($track));
}
}
?>
\ No newline at end of file
......@@ -27,19 +27,10 @@ class ZendAfi_View_Helper_TagAlbumTrackList extends Zend_View_Helper_HtmlElement
* Voir: http://kolber.github.com/audiojs/
*/
public function tagAlbumTrackList($album) {
$audio_tracks = $album->getAudioTracks();
$html = $this->view->album_Download($album);
$html .= '<ol>';
foreach($audio_tracks as $audio_track){
$html.=
'<li class="audio_track">'.
$this->view->albumRessourceInfos($audio_track).
$this->view->audioJsPlayer($this->view->album_PlayRessourceUrl($audio_track)).
'</li>';
}
return $html.='</ol>';
}
return
$this->view->album_Download($album) .
$this->view->albumAudioJsPlayer($album);
}
}
?>
\ No newline at end of file
......@@ -245,7 +245,7 @@ class RechercheControllerAlbumAudioRecordViewNoticeTest extends RechercheControl
class RechercheControllerAlbumAudioRecordViewMorceauxTest extends RechercheControllerAlbumAudioRecordTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/opac/noticeajax/morceaux/id_notice/'.$this->_notice->getId(), true);
$this->dispatch('/opac/noticeajax/morceaux/id_notice/' . $this->_notice->getId(), true);
}
......@@ -328,8 +328,26 @@ class RechercheControllerAlbumAudioRecordViewRessourcesNumeriquesTest extends Re
/** @test */
public function moonchildPlayerShouldBePresent() {
$this->assertXPath('//ol//li//audio/source[contains(@src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody());
public function albumPlayerShouldBePresent() {
$this->assertXPath('//audio[@preload]');
}
/** @test */
public function nextTrackLinkShouldBePresent() {
$this->assertXPath('//div[@class="audio_tracks_control"]/a[@class="next"]');
}
/** @test */
public function previousTrackLinkShouldBePresent() {
$this->assertXPath('//div[@class="audio_tracks_control"]/a[@class="previous"]');
}
/** @test */
public function moonchildTrackShouldBePresent() {
$this->assertXPath('//ol//li//a[contains(@data-src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody());
}
......@@ -357,11 +375,11 @@ class RechercheControllerAlbumAudioRecordViewRessourcesNumeriquesTest extends Re
$this->assertXPath('//a[contains(@href,"/bib-numerique/album-xspf-playlist/id/4.xspf")]');
}
/** @test */
public function pageShouldContainsLinkToRSSPodcast() {
$this->assertXPath('//a[contains(@href,"/bib-numerique/album-rss-feed/id/4.xml")]');
}
}
......@@ -391,7 +409,7 @@ class RechercheControllerAlbumAudioRecordAsTelephoneViewRessourcesNumeriquesTest
/** @test */
public function moonchildPlayerShouldBePresent() {
$this->assertXPath('//ol//li//audio/source[contains(@src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody());
$this->assertXPath('//ol//li//a[contains(@data-src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody());
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment