You are here

function _video_field_get_all_thumbnails in Video 7.2

4 calls to _video_field_get_all_thumbnails()
video_field_delete in ./video.field.inc
Implements hook_field_delete().
video_field_delete_revision in ./video.field.inc
Implements hook_field_delete_revision().
video_field_insert in ./video.field.inc
Implements hook_field_insert().
video_field_update in ./video.field.inc
Implements hook_field_update().

File

./video.field.inc, line 1398
Implement a video field, based on the file module's file field.

Code

function _video_field_get_all_thumbnails(array $field, array $items, $usage_entity_type = NULL, $usage_entity_id = NULL) {
  if (empty($items)) {
    return array();
  }
  $defaultthumbnailfid = !empty($field['settings']['default_video_thumbnail']) ? $field['settings']['default_video_thumbnail']['fid'] : 0;
  $videofids = array();
  $thumbnailfids = array();
  foreach ($items as $item) {
    if (!empty($item['fid'])) {
      $videofids[] = intval($item['fid']);

      // Add the selected thumbnail if it is not the default thumbnail for the field
      if (!empty($item['thumbnail']) && $item['thumbnail'] != $defaultthumbnailfid) {
        $thumbnailfids[] = intval($item['thumbnail']);
      }
    }
  }
  if (empty($videofids)) {
    return array();
  }

  // Add the automatically extracted thumbnails
  $query = db_select('video_thumbnails', 't')
    ->fields('t', array(
    'thumbnailfid',
  ))
    ->condition('videofid', $videofids, 'IN');

  // Only return files with usage when requested
  if ($usage_entity_type != NULL && $usage_entity_id != NULL) {
    $query
      ->innerJoin('file_usage', 'u', 'u.fid = t.thumbnailfid AND u.type = :type AND u.id = :id', array(
      ':type' => $usage_entity_type,
      ':id' => $usage_entity_id,
    ));
  }
  $thumbnailfids = array_merge($thumbnailfids, $query
    ->execute()
    ->fetchCol(0));
  return video_utility::objectToArray(file_load_multiple($thumbnailfids));
}