You are here

function _auditfiles_used_not_referenced_get_file_data in Audit Files 7.3

Same name and namespace in other branches
  1. 7.4 auditfiles.usednotreferenced.inc \_auditfiles_used_not_referenced_get_file_data()

Retrieves information about an individual file from the database.

Parameters

int $file_id: The ID of the file to prepare for display.

Return value

array The row for the table on the report, with the file's information formatted for display.

2 calls to _auditfiles_used_not_referenced_get_file_data()
auditfiles_used_not_referenced_form in ./auditfiles.usednotreferenced.inc
Generates the report.
_auditfiles_used_not_referenced_batch_display_process_files in ./auditfiles.usednotreferenced.inc
The batch process operation for formatting the files for display on the page.

File

./auditfiles.usednotreferenced.inc, line 611
Generates report showing files in file_usage, but not referenced by content.

Code

function _auditfiles_used_not_referenced_get_file_data($file_id) {

  // Get the file's information from the file_managed table.
  $file_managed = db_query("SELECT * FROM {file_managed} fm WHERE fid = {$file_id}")
    ->fetchObject();
  if (empty($file_managed)) {

    // The file is not listed in the file_managed table. Display an error
    // message, instead of the file information.
    $row = array(
      'fid' => t('This file is not listed in the file_managed table. See the "!usednotmanaged" report.', array(
        '!usednotmanaged' => l(t('Used not managed'), 'admin/reports/auditfiles/usednotmanaged'),
      )),
      'uri' => '',
      'usage' => '',
    );
  }
  else {
    $usage = '<ul>';
    $results = db_query("SELECT * FROM {file_usage} WHERE fid = {$file_id}");
    foreach ($results as $file_usage) {

      // Create the usages list.
      $used_by = $file_usage->module;
      $type = $file_usage->type;
      $used_in = $file_usage->type == 'node' ? l($file_usage->id, 'node/' . $file_usage->id) : $file_usage->id;
      $times_used = $file_usage->count;
      $usage .= '<li>' . t('Used by module: %used_by, as object type: %type, in content ID: !used_in; Times used: %times_used', array(
        '%used_by' => $used_by,
        '%type' => $type,
        '!used_in' => $used_in,
        '%times_used' => $times_used,
      )) . '</li>';
    }
    $usage .= '</ul>';

    // Create the data for displaying in the table.
    $row = array(
      'fid' => $file_id,
      'uri' => $file_managed->uri,
      'usage' => $usage,
    );
  }
  return $row;
}