You are here

public function ServiceAuditFilesManagedNotUsed::auditfilesManagedNotUsedGetFileData in Audit Files 8.3

Same name and namespace in other branches
  1. 8.2 src/ServiceAuditFilesManagedNotUsed.php \Drupal\auditfiles\ServiceAuditFilesManagedNotUsed::auditfilesManagedNotUsedGetFileData()
  2. 4.x src/ServiceAuditFilesManagedNotUsed.php \Drupal\auditfiles\ServiceAuditFilesManagedNotUsed::auditfilesManagedNotUsedGetFileData()

Retrieves information about an individual file from the database.

Parameters

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

int $date_format: The Format of the date to prepare for display.

Return value

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

File

src/ServiceAuditFilesManagedNotUsed.php, line 103

Class

ServiceAuditFilesManagedNotUsed
Service managed not used functions.

Namespace

Drupal\auditfiles

Code

public function auditfilesManagedNotUsedGetFileData($file_id, $date_format) {
  $connection = $this->connection;
  $query = $connection
    ->select('file_managed', 'fm');
  $query
    ->condition('fm.fid', $file_id);
  $query
    ->fields('fm', [
    'fid',
    'uid',
    'filename',
    'uri',
    'filemime',
    'filesize',
    'created',
    'status',
  ]);
  $results = $query
    ->execute()
    ->fetchAll();
  $file = $results[0];
  return [
    'fid' => $file->fid,
    'uid' => $file->uid,
    'filename' => $file->filename,
    'uri' => $file->uri,
    'path' => $this->fileSystem
      ->realpath($file->uri),
    'filemime' => $file->filemime,
    'filesize' => number_format($file->filesize),
    'datetime' => $this->dateFormatter
      ->format($file->created, $date_format),
    'status' => $file->status == 1 ? 'Permanent' : 'Temporary',
  ];
}