You are here

function brightcove_cck_browse in Brightcove Video Connect 6

Same name and namespace in other branches
  1. 6.2 brightcove_cck/brightcove_cck.browse.inc \brightcove_cck_browse()

This function is a callback for modalframe window, providing an access to browse videos.

Parameters

none:

Return value

A list of available videos that can be attached to a field.

TODO: Allow limiting videos by user (own videos only). TODO: Interesting feature would be to detect multiple values allowed in the parent field and allow attaching all videos at once.

See also

brightcove_cck_menu()

1 string reference to 'brightcove_cck_browse'
brightcove_cck_menu in brightcove_cck/brightcove_cck.module
Implementation of hook_menu().

File

brightcove_cck/brightcove_cck.browse.inc, line 21
brightcove_cck.browse.inc Holds a method to list all BC videos that are attachable to a field.

Code

function brightcove_cck_browse() {
  global $pager_from_array, $pager_total, $pager_page_array;
  $items_per_page = 20;
  modalframe_child_js();

  //dialog internal area
  drupal_add_css(drupal_get_path('module', 'brightcove_cck') . '/styles/browse.css');
  drupal_add_js(drupal_get_path('module', 'brightcove_cck') . '/js/attach.js');

  // Issue a BC request to list videos
  // For all videos, get a thumbnail URL
  // Theme a table with videos and a button to attach.
  $bc = _brightcove_initialize();
  $matches = array();
  $page = isset($_GET['page']) ? intval($_GET['page']) : '0';
  $params = array();
  if (isset($_SESSION['brightcove_cck_filter'])) {
    switch ($_SESSION['brightcove_cck_filter']['search']) {
      case 'tags':
        $method = 'find_videos_by_tags';
        $params = array(
          'or_tags' => $_SESSION['brightcove_cck_filter']['keywords'],
        );
        break;
      case 'and_tags':
        $method = 'find_videos_by_tags';
        $params = array(
          'and_tags' => $_SESSION['brightcove_cck_filter']['keywords'],
        );
        break;
      case 'name':
      default:
        $method = 'find_videos_by_text';
        $params = array(
          'text' => join(' ', split(',', $_SESSION['brightcove_cck_filter']['keywords'])),
        );
        break;
    }
  }
  else {
    $method = 'find_all_videos';
  }
  try {
    $params['page_size'] = $items_per_page;
    $params['page_number'] = $page;
    $result = $bc
      ->find($method, $params);
  } catch (Exception $error) {
    watchdog('brightcove', 'Finding videos in autocomplete failed.', array(), WATCHDOG_ERROR);
  }
  $pager_page_array = explode(',', $page);
  $pager_total[0] = ceil($bc->total_count / $items_per_page);
  $pager_page_array[0] = max(0, min((int) $pager_page_array[0], (int) $pager_total[0] - 1));
  $items = array();
  if (count($result)) {
    foreach ($result as $video) {
      $item = array();
      $item['title'] = check_plain($video->name);
      $item['video_id'] = $video->id;
      if (!empty($video->thumbnailURL)) {
        if (module_exists('imagecache')) {
          $item['thumbnail'] = theme('imagecache', 'brightcove_browser', brightcove_remote_image($video->thumbnailURL));
        }
        else {
          $item['thumbnail'] = theme('image', $video->thumbnailURL, '', '', NULL, FALSE);
        }
      }
      else {
        $item['thumbnail'] = theme('image', brightcove_get_default_image(), '', '', array(
          'width' => 120,
          'height' => 120,
        ), FALSE);
      }
      $items[] = $item;
    }
  }
  $pager = theme('pager', NULL, $items_per_page, 0);
  $filter_form = drupal_get_form('brightcove_cck_filter_form');
  return '<div class="brightcove-browse-table">' . $filter_form . $pager . theme('brightcove_cck_browse_items', $items) . $pager . '</div>';
}