You are here

function uc_file_get_by_uid in Ubercart 8.4

Same name and namespace in other branches
  1. 7.3 uc_file/uc_file.module \uc_file_get_by_uid()

Retrieves a file by user ID.

Parameters

int $uid: A user ID.

int $fid: A file ID.

Return value

A uc_file object.

1 call to uc_file_get_by_uid()
DownloadController::download in uc_file/src/Controller/DownloadController.php
Handles file downloading and error states.

File

uc_file/uc_file.module, line 841
Allows products to be associated with downloadable files.

Code

function &uc_file_get_by_uid($uid, $fid) {
  $cache = _uc_file_get_cache();
  $connection = \Drupal::database();
  if (!isset($cache[$uid][$fid])) {
    $cache[$uid][$fid] = $connection
      ->query("SELECT * FROM {uc_file_users} ufu " . "LEFT JOIN {uc_files} uf ON uf.fid = ufu.fid " . "WHERE ufu.fid = :fid AND ufu.uid = :uid", [
      ':uid' => $uid,
      ':fid' => $fid,
    ])
      ->fetchObject();
    if ($cache[$uid][$fid]) {
      $cache[$uid][$fid]->addresses = unserialize($cache[$uid][$fid]->addresses);
    }
  }
  return $cache[$uid][$fid];
}