Skip to content
Snippets Groups Projects
RenderTracks.php 3.99 KiB
Newer Older
<?php
/**
 * Copyright (c) 2012-2019, Agence Française Informatique (AFI). All rights reserved.
 *
 * BOKEH 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).
 *
 * BOKEH 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 BOKEH; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 */


class Intonation_View_RenderTracks extends ZendAfi_View_Helper_BaseHelper {
  public function renderTracks($tracks) {
    if ($tracks->isEmpty())
      return '';

    $html = [$this->_renderAudioTracks($tracks->select('isAudio')),
             $this->_renderYoutubeTracks($tracks->select('isYoutube'))];

    $html = array_filter($html);
    $html = array_map(function($content)
                      {
                        return $this->_div(['class' => 'col-12'],
                                           $content);
                      },
                      $html);
    return $this->view->grid($html);
  protected function _renderAudioTracks($tracks) {
    if ($tracks->isEmpty())
      return '';
    $html = [$this->_div(['class' => 'col-12'],
                         $this->view->renderList($tracks, function($track)
                                                 {return $this->_audioTrack($track);})),
             $this->_div(['class' => 'col-12'],
                         $this->_renderPlayer())];
    return $this->view->grid($html, ['class' => 'audio_tracks']);
  protected function _renderYoutubeTracks($tracks) {
    if ($tracks->isEmpty())
      return '';

    $html = $this->_div(['class' => 'col-12'],
                        $this->view->renderList($tracks, function($track)
                                                {return $this->_youtubeTrack($track);}));

    return $this->view->grid($html, ['class' => 'youtube_tracks']);
  }


  protected function _audioTrack($track) {
    $html = [$this->view->templateIco('track', 'utils'),

             $this->_tag('span', $track->getTitle(),['class' => 'track_title']),

             $this->_tag('span', $track->getSource(),['class' => 'track_source'])];

    return $this->_tag('a',
                       implode($html),
                       ['class' => 'audio_track card-title',
                        'data-track-url' => $track->getUrl(),
                        'onclick' => ' $(\'.audio_player\').attr(\'src\',$(this).attr(\'data-track-url\')); $(\'.audio_player\').trigger(\'play\');$(this).closest(\'.list-group\').find(\'.playing\').removeClass(\'playing\');$(this).addClass(\'playing\');'
                       ]);
  }


  protected function _renderPlayer() {
                       ['class' => 'audio_player',
                        'src' => '',
                        'onplaying' => "$('audio, video').not($(this)).trigger('pause');",
  protected function _youtubeTrack($track) {
    $html = [$this->view->templateIco('youtube', 'utils'),

             $this->_tag('span',
                         $track->getTitle(),
                         ['class' => 'track_title']),

             $this->_tag('span',
                         $track->getSource(),
                         ['class' => 'track_source'])];

    $html = [$this->_div(['class' => 'col-12'],
                         implode($html)),
             $this->_div(['class' => 'col-12'],
                         $this->view->embed($track->getSource(), $track->getUrl()))];