You are here

function commerce_file_handler_field_download_limit::pre_render in Commerce File 7.2

Run before any fields are rendered.

This gives the handlers some time to set up before any handler has been rendered.

Parameters

array $values: An array of all objects returned from the query.

Overrides views_handler_field::pre_render

File

includes/views/handlers/commerce_file_handler_field_download_limit.inc, line 22
Contains commerce_file_handler_field_download_limit.

Class

commerce_file_handler_field_download_limit
Displays the download limit for a file

Code

function pre_render(&$values) {
  $data = array();

  // Note: this assumes the view has license_id and commerce_file fields.
  foreach ($values as $index => $value) {
    if (isset($value->license_id) && isset($value->field_commerce_file)) {
      $data[$value->license_id][$index] = $value->field_commerce_file[0]['raw']['fid'];
    }
  }

  // No data found, stop here.
  if (empty($data)) {
    return;
  }
  $license_ids = array_keys($data);
  $licenses = entity_load('commerce_license', $license_ids);

  // Get the counts and add them to $values for render() to use.
  foreach ($data as $license_id => $fids) {
    $license = $licenses[$license_id];
    $counts = commerce_file_download_log_get_counts($license, $fids);
    foreach ($fids as $index => $fid) {
      $values[$index]->commerce_file_download_count = $counts[$fid];
    }
  }
}