You are here

function mediafront_plugin_style_player_advanced::render in MediaFront 7

Renders the media player.

Overrides views_plugin_style::render

File

views/mediafront_plugin_style_player_advanced.inc, line 66
This file holds style plugin for MediaFront Views

Class

mediafront_plugin_style_player_advanced
@class Extension of the Views Plugin Syle for the Media Player from MediaFront

Code

function render() {
  $output = '';

  // Check for live preview.
  if (!empty($this->view->live_preview)) {
    return t('MediaFront views are not compatible with live preview.');
  }
  $i = 0;
  $params = array();
  $params['playlistObj']['nodes'] = array();
  foreach ($this->view->result as $index => $row) {
    $media_url = $this
      ->getFieldRawUrl($index, $this->options['mediafront_media_field']);
    $this->view->row_index = $index;
    if ($media_url) {
      $playlist_node = array(
        'mediafiles' => array(
          'media' => array(
            'media' => (object) array(
              'path' => $media_url,
            ),
          ),
        ),
      );
      if ($this->options['mediafront_title_field']) {
        $title = $this->view
          ->render_field($this->options['mediafront_title_field'], $index);
        if ($title) {
          $playlist_node['title'] = $title;
        }
      }
      if ($this->options['mediafront_image_field']) {
        $image_url = $this
          ->getFieldRawUrl($index, $this->options['mediafront_image_field']);
        if ($image_url) {
          $playlist_node['mediafiles']['images'] = array(
            'image' => (object) array(
              'path' => $image_url,
            ),
          );
        }
      }
      $params['playlistObj']['nodes'][] = $playlist_node;
    }
  }
  $params['playlistObj']['total_rows'] = count($params['playlistObj']['nodes']);

  // Now render the media player for this view.
  return mediafront_get_player($this->options['mediafront_preset'], $params);
}