function _brightcove_field_playlist_browse in Brightcove Video Connect 7.4
Same name and namespace in other branches
- 7.3 brightcove_field/brightcove_field.playlist.inc \_brightcove_field_playlist_browse()
- 7.5 brightcove_field/brightcove_field.playlist.inc \_brightcove_field_playlist_browse()
1 call to _brightcove_field_playlist_browse()
- brightcove_field_browse in brightcove_field/
brightcove_field.browse.inc - This function is a callback for modalframe window, providing an access to browse videos.
File
- brightcove_field/
brightcove_field.playlist.inc, line 180 - Holds all of the playlist field related methods.
Code
function _brightcove_field_playlist_browse() {
global $pager_from_array, $pager_total, $pager_page_array;
$items_per_page = 20;
$page = isset($_GET['page']) ? intval($_GET['page']) : '0';
$params = array();
$method = 'find_all_playlists';
$result = NULL;
// Add parameters.
$params['page_size'] = $items_per_page;
$params['page_number'] = $page;
// Try to load the data from cache.
$cid = 'brightcove:playlist:list';
foreach ($params as $key => $param) {
$cid .= ":{$key}:{$param}";
}
$content = brightcove_cache_get($cid);
if (!$content) {
try {
$bc = brightcove_initialize();
$result = $bc
->find($method, $params);
} catch (Exception $error) {
watchdog('brightcove', 'Finding playlists in browse 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 $playlist) {
$item = array();
$item['title'] = check_plain($playlist->name);
$item['brightcove_id'] = $playlist->id;
if (!empty($playlist->thumbnailURL)) {
$image_vars = array(
'path' => $playlist->thumbnailURL,
'alt' => '',
'title' => '',
'attributes' => '',
);
$item['thumbnail'] = theme('image', $image_vars);
}
else {
$image_vars = array(
'path' => brightcove_get_default_image(),
'alt' => '',
'title' => '',
'attributes' => '',
'width' => '120',
'height' => '',
);
$item['thumbnail'] = theme('image', $image_vars);
}
$items[] = $item;
}
}
$pager_vars = array(
'tags' => NULL,
'element' => 0,
'parameters' => array(),
'quantity' => $items_per_page,
);
// No possibility to search any parameter of the playlist.(Only ID).
$content['filter_form'] = array();
$content['items'] = $items;
$content['pager'] = theme('pager', $pager_vars);
// Save the output to the cache record(not only the video objects),
// because we also need data for pagination.
brightcove_cache_set($cid, $content);
}
return $content;
}