function mediafront_get_playlist_from_view in MediaFront 7.2
Same name and namespace in other branches
- 6.2 mediafront.module \mediafront_get_playlist_from_view()
- 6 mediafront.module \mediafront_get_playlist_from_view()
- 7 mediafront.module \mediafront_get_playlist_from_view()
Returns a playlist provided a view.
3 calls to mediafront_get_playlist_from_view()
- mediafront_get_playlist in ./
mediafront.module - Gets a playlist
- mediafront_handler_area_player::render in views/
mediafront_handler_area_player.inc - Render the area.
- mediafront_plugin_style_player::render in views/
mediafront_plugin_style_player.inc - Renders the media player.
File
- ./
mediafront.module, line 315
Code
function mediafront_get_playlist_from_view($view, $limit = 10, $start = 0) {
// Create our playlist array.
$playlist = array();
$playlist['nodes'] = array();
$playlist['name'] = $view->name;
// Get the endpoint for this view.
$endpoint = 'mediafront_getplaylist/' . $view->name;
$playlist['endpoint'] = url($endpoint, array(
'absolute' => TRUE,
));
// Get the total items.
$total = !empty($view->total_rows) ? $view->total_rows : (isset($view->query->pager) ? $view->query->pager
->get_total_items() : 0);
$total = empty($total) ? count($view->result) : $total;
$total += $start;
$playlist['total_rows'] = $total;
// Iterate through each field and add the configuration.
$fields = array();
foreach ($view->field as $name => $field) {
$options = mediafront_views_get_options($field);
if (!empty($options['field_type'])) {
$fields[$field->field] = array(
'type' => $options['field_type'],
'field' => $field,
'options' => $options,
);
}
}
// Only continue if there are fields.
if ($fields) {
// Iterate through all the results.
foreach ($view->result as $row) {
// Add this as a playlist node.
if ($node = mediafront_get_node('view', $row, $fields)) {
// Add the node ID.
if (!empty($row->nid)) {
$node['nid'] = $row->nid;
}
// Add this node.
$playlist['nodes'][] = $node;
}
}
}
// Return the playlist.
return $playlist;
}