asset_view

Versions
mediamosa-174
asset_view($asset_id)

This function displays information and all assets of a single asset

Code

vpx_beheer_mm/asset/asset.module, line 828

<?php
function asset_view($asset_id) {
  global $user;
  $item_limit = variable_get('vpx_connector_item_limit', NULL);
  $page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
  $vpx = new vpx_connector();
  $output = '';

// get asset information
  $result = $vpx->request('GET', sprintf('/asset/%s', $asset_id));
  $item = $result->items->item;
  $app_id = $item->app_id;
  drupal_set_title(pa_trim_string($item->dublin_core->title));

  // fill the asset property table

  // asset information
  $rows = array();
  foreach (array('owner_id', 'app_id', 'group_id', 'reference_id', 'videotimestamp', 'videotimestampmodified', 'play_restriction_start', 'play_restriction_end') as $subject) {
    pa_table_add_row($subject, $item->$subject, $rows);
  }

  // metadata
  $temp = $item->dublin_core[0]; // workaround for a bug in php
  if ($temp) {
    foreach ($temp as $key => $value) {
      pa_table_add_row($key, $value, $rows);
    }
  }
  $temp = $item->qualified_dublin_core[0]; // workaround for a bug in php
  if ($temp) {
    foreach ($temp as $key => $value) {
      pa_table_add_row($key, $value, $rows);
    }
  }
  $app_metadata = 'app_'. $app_id;
  $temp = $item->$app_metadata[0]; // workaround for a bug in php
  if ($temp) {
    foreach ($temp as $key => $value) {
      pa_table_add_row($key, $value, $rows);
    }
  }
  $header = array(t('Property'), t('Value'));
  $output .= '<p>'. t('Metadata properties for the asset are shown below.');
  $output .= theme('table', $header, $rows);

// find all jobs for this asset
  $url = sprintf('/asset/%s/joblist', $asset_id);
  $result = $vpx->request('GET', $url, NULL, TRUE, $app_id);
  $delete_states = array('WAITING', 'FINISHED', 'FAILED');
  $item_count = (int)$result->header->item_count;

  if ($item_count) {
    $rows = array();
    foreach ($result->items->item as $item) {
      $delete = (in_array((string)$item->status, $delete_states)) ? l(t('Delete'), variable_get('vpx_connector_menu_prefix', '') .'asset/'. $asset_id .'/job/'. (string)$item->id .'/delete') : '';
      $rows[] = array(
        (string)$item->id,
        (string)$item->job_type,
        (string)$item->status,
        ((string)$item->started_unix) ? format_date((string)$item->started_unix, 'small') : '',
        (string)$item->progress * 100 .'%',
        (string)$item->owner,
        (string)$item->error_description,
        $delete,
      );
    }
    $header = array(
      t('ID'),
      t('Type'),
      t('Status'),
      t('Started'),
      t('Progress'),
      t('Owner'),
      t('Description'),
      t('Action'),
    );
    $content = theme('table', $header, $rows);
    $output .= '<p><h2>'. t('Jobs (@count)', array('@count' => $item_count)) .'</h2>';
    $output .= '<div>'. t('Jobs started for this asset.') .'</div>';
    $output .= $content .'</p>';
  }

// find all mediafiles of this asset
  $url = sprintf('/asset/%s/mediafile', $asset_id);
  $result = $vpx->request('GET', $url);
  $item_count = (int)$result->header->item_count;
  $play_uris = variable_get('pa_play_uris', array());

  if ($item_count === 0) {
    $content = t('This asset does not contain mediafiles.');
  }
  else {
    $content = t('Mediafiles for this asset are shown below.');
    foreach ($result->items->item as $item) {
      $delete = (user_access('delete mediafiles')) ? ' - '. l('Delete', variable_get('vpx_connector_menu_prefix', '') . sprintf('mediafile/%s/%s/delete', $item->asset_id, $item->mediafile_id)) : '';
      $analyse = (user_access('edit mediafiles')) ? ' - '. l('Analyse', variable_get('vpx_connector_menu_prefix', '') . sprintf('mediafile/%s/%s/analyse', $item->asset_id, $item->mediafile_id)) : '';
      $download = (user_access('edit mediafiles')) ? ' - '. l('Download', variable_get('vpx_connector_menu_prefix', '') . sprintf('mediafile/%s/%s/download', $item->asset_id, $item->mediafile_id)) : '';
      $header = array(array(
        'data' => pa_trim_string($item->filename) . $delete . $analyse . $download,
        'colspan' => 2
      ));
      $rows = array();
      foreach ($play_uris as $play_uri) {
        $patterns = array(
          '/{mediafile_id}/i',
          '/{asset_id}/i',
          '/{mediafile_filename}/i',
        );
        $replace = array(
          $item->mediafile_id,
          $item->asset_id,
          rawurlencode($item->filename),
        );
        $play_uri['uri'] = preg_replace($patterns, $replace, $play_uri['uri']);
        $rows[] = array(
          t('Play URI for %description', array('%description' => $play_uri['description'])),
          sprintf('<a href="%s">%s</a>', $play_uri['uri'], pa_trim_string($play_uri['uri'], 90)),
        );
      }
      pa_table_add_row(t('Mediafile id'), (string)$item->mediafile_id, $rows);
      pa_table_add_row(t('Owner id'), (string)$item->owner_id, $rows);
      pa_table_add_row(t('Group id'), (string)$item->group_id, $rows);
      pa_table_add_row(t('Mime Type'), (string)$item->metadata->mime_type, $rows);
      pa_table_add_row(t('Container'), ((string)$item->metadata->container_type) ? (string)$item->metadata->container_type .' @ '. (string)$item->metadata->bitrate .'kbps' : NULL, $rows, TRUE);
      pa_table_add_row(t('Width * Height @ fps'), ((string)$item->metadata->width) ? (string)$item->metadata->width .'px * '. (string)$item->metadata->height .'px @ '. (string)$item->metadata->fps .'fps' : NULL, $rows, TRUE);
      pa_table_add_row(t('Duration'), (string)$item->metadata->file_duration, $rows, TRUE);
      pa_table_add_row(t('Filesize'), ((string)$item->metadata->filesize) ? format_size((string)$item->metadata->filesize) : NULL, $rows, TRUE);
      pa_table_add_row(t('Video information'), ((string)$item->metadata->video_codec) ? (string)$item->metadata->video_codec .' @ '. (string)$item->metadata->video_bitrate .'kbps ('. (string)$item->metadata->colorspace .')' : NULL, $rows, TRUE);
      pa_table_add_row(t('MP4 hinted'), (string)$item->metadata->is_hinted, $rows);
      pa_table_add_row(t('FLV metadated'), (string)$item->metadata->is_inserted_md, $rows);
      pa_table_add_row(t('Original'), (string)$item->is_original_file, $rows);
      pa_table_add_row(t('Downloadable'), (string)$item->is_downloadable, $rows);
      pa_table_add_row(t('Audio information'), ((string)$item->metadata->audio_codec) ? (string)$item->metadata->audio_codec .' @ '. (string)$item->metadata->sample_rate .'Hz/'. (string)$item->metadata->audio_bitrate .'kbps ('. (string)$item->metadata->channels .')': NULL, $rows, TRUE);

      pa_table_add_row(t('Protected'), (string)$item->is_protected, $rows);
      // ACL rules
      $acl_result = $vpx->request('GET', sprintf('/mediafile/%s/acl?user_id=%s', $item->mediafile_id, $user->name));
      $is_aut = FALSE;
      foreach ($acl_result->items->item as $acl_item) {
        $acl_item = (array)$acl_item; // cast the object into an array
        $keys = array_keys($acl_item);
        foreach ($keys as $key) {
          if (strpos($key, '@') !== 0) {
            pa_table_add_row($key, $acl_item[$key], $rows);
            $is_aut = TRUE;
          }
        }
      }
      if (!$is_aut) {
        pa_table_add_row(t('Autorisarion rules'), '-', $rows);
      }

      // Stills
      $still_result = $vpx->request('GET', sprintf('/mediafile/%s', $item->mediafile_id));
      $is_still = FALSE;
      $allowed_still_fields = array(
        'mediafile_id',
        'file_extension',
        'created',
        'width',
        'height',
        'filesize',
        'mime_type',
        'still_time_code',
        'still_order',
        'still_format',
        'still_type',
        'still_default',
        'still_ticket',
      );
      foreach ($still_result->items->item->still as $still_item) {
        $still_header = array();
        $still_rows = array();
        $still_ticket = NULL;
        foreach ($still_item as $still_key => $still_det) {
          if (in_array((string)$still_key, $allowed_still_fields)) {
            $still_rows[] = array(
              (string)$still_key == 'mediafile_id' ? 'still_id' : (string)$still_key,
              (string)$still_det,
            );
            if ($still_key == 'still_ticket') {
              $still_ticket = $still_det;
            }
          }
        }
        $rows[] = array(
          t('Still') .'<br />'. ($still_ticket ? theme('image', $still_ticket, '', '', array('width' => 200, 'height' => NULL,), FALSE) : ''),
          theme('table', $still_header, $still_rows),
        );
        $is_still = TRUE;
      }
      if (!$is_still) {
        pa_table_add_row(t('Still'), '-', $rows);
      }

      $content .= theme('table', $header, $rows);
    }
  }
  $output .= '<p><h2>'. t('Mediafiles (@count)', array('@count' => $item_count)) .'</h2>'. $content .'</p>';


  // find all collections this asset is a member of
  //#TODO: find more than 200 (if needed)
  $url = sprintf('/asset/%s/collection?limit=%d&offset=%d', $asset_id, $item_limit, $page * $item_limit);
  $result = $vpx->request('GET', $url);
  $item_count = (int)$result->header->item_count_total;

  if ($item_count === 0) {
    $content = t('This asset was not found in any collection.');
  }
  else {
    $rows = array();
    foreach ($result->items->item as $item) {
      $rows[] = array(
        l(pa_trim_string($item->title), sprintf(variable_get('vpx_connector_menu_prefix', '') .'collection/%s', $item->coll_id)),
        l(t('Remove'), sprintf(variable_get('vpx_connector_menu_prefix', '') .'collection/%s/remove_asset/%s', $item->coll_id, $asset_id), array('query' => 'return=asset')),
      );
    }

    $content = t('This asset was found in the following collections:');
    $header = $header = array(array(
        'data' => t('Title'),
        'colspan' => 2
      ));;
    $content .= theme('table', $header, $rows);
  }
  $output .= '<p><h2>'. t('Collections (@count)', array('@count' => $item_count)) .'</h2>'. $content .'</p>';

  return $output;
}
?>