You are here

function brightcove_media_list in Brightcove Video Connect 7.7

Same name and namespace in other branches
  1. 7.2 brightcove_media/brightcove_media.module \brightcove_media_list()
  2. 7.3 brightcove_media/brightcove_media.module \brightcove_media_list()
  3. 7.4 brightcove_media/brightcove_media.module \brightcove_media_list()
  4. 7.6 brightcove_media/brightcove_media.module \brightcove_media_list()

Prints the avaliable videos from brightcove.

1 string reference to 'brightcove_media_list'
brightcove_media_menu in brightcove_media/brightcove_media.module
Implements hook_menu().

File

brightcove_media/brightcove_media.module, line 565
This module provide the hook implementations for the integration with Media module.

Code

function brightcove_media_list() {
  module_load_include('browser.inc', 'media', 'includes/media');
  $default_items_per_page = 50;
  $params = drupal_get_query_parameters();
  $limit = isset($params['limit']) ? $params['limit'] : $default_items_per_page;
  $offset = isset($params['start']) ? $params['start'] : 0;
  $keywords = isset($params['filter']['keywords']) ? $params['filter']['keywords'] : '';

  /** @var \Brightcove\Object\Video\Video[] $videos */
  $videos = [];
  brightcove_try(function () use (&$videos, $keywords, $limit, $offset) {
    $client = brightcove_client_load_or_default();

    /** @var \Brightcove\API\CMS $cms */
    list($cms) = brightcove_create_classes($client);
    $videos = $cms
      ->listVideos($keywords, '-updated_at', $limit, $offset);
  });
  $media = [];
  $files = [];
  if (is_array($videos) && count($videos)) {
    foreach ($videos as $video) {
      $uri = file_stream_wrapper_uri_normalize("brightcove://v/{$video->getId()}/a/{$video->getAccountId()}");
      $file = file_uri_to_object($uri);
      $file->filename = $video
        ->getName();
      $file->type = 'video';
      if (!isset($file->fid)) {
        $file->fid = 0;
      }
      media_browser_build_media_item($file);
      $file->preview = l($file->preview, 'media/browser', [
        'html' => TRUE,
        'attributes' => [
          'data-uri' => $uri,
        ],
        'query' => [
          'render' => 'media-popup',
          'uri' => $uri,
        ],
      ]);
      $files[$uri] = $file;
      $media[] = $file;
    }
  }
  drupal_add_js([
    'brightcove' => [
      'files' => $files,
    ],
  ], 'setting');
  drupal_json_output($media);
}