function brightcove_media_playlist_list in Brightcove Video Connect 7.4
Same name and namespace in other branches
- 7.7 brightcove_media/brightcove_media.module \brightcove_media_playlist_list()
- 7.6 brightcove_media/brightcove_media.module \brightcove_media_playlist_list()
brightcove/media/playlist/list menu callback function.
Return value
JSON available playlists.
1 string reference to 'brightcove_media_playlist_list'
- brightcove_media_menu in brightcove_media/
brightcove_media.module - Implements hook_menu().
File
- brightcove_media/
brightcove_media.module, line 896 - This module provide the hook implementations for the integration with Media module.
Code
function brightcove_media_playlist_list() {
module_load_include('browser.inc', 'media', 'includes/media');
$media = array();
$files = array();
$default_items_per_page = 20;
$params = drupal_get_query_parameters();
$limit = isset($params['limit']) ? $params['limit'] : $default_items_per_page;
$start = isset($params['start']) ? ceil($params['start'] / $limit) : 0;
$method = 'find_all_playlists';
$bc_find_params = array();
$bc_find_params['page_size'] = $limit;
$bc_find_params['page_number'] = $start;
// Try to load the data from cache. It uses different key than the cache of field browse results,
// because it has a different output.
$cid = 'brightcove:playlist:list:media';
foreach ($bc_find_params as $key => $param) {
$cid .= ":{$key}:{$param}";
}
$result = brightcove_cache_get($cid);
if (!$result) {
try {
$bc = brightcove_initialize();
$result = $bc
->find($method, $bc_find_params);
brightcove_cache_set($cid, $result);
} catch (Exception $e) {
watchdog('brightcove', 'Retrieving media list failed.', array(), WATCHDOG_ERROR);
}
}
if (count($result)) {
foreach ($result as $playlist) {
$uri = file_stream_wrapper_uri_normalize("brightcove-playlist://{$playlist->id}");
$file = file_uri_to_object($uri);
$file->filename = $playlist->name;
$file->type = 'video';
if (!isset($file->fid)) {
$file->fid = 0;
}
media_browser_build_media_item($file);
$file->preview = l($file->preview, 'media/browser', array(
'html' => TRUE,
'attributes' => array(
'data-uri' => $uri,
),
'query' => array(
'render' => 'media-popup',
'uri' => $uri,
),
));
$files[$uri] = $file;
$media[] = $file;
}
}
drupal_add_js(array(
'brightcove_playlist' => array(
'files' => $files,
),
), 'setting');
drupal_json_output($media);
exit;
}