You are here

function filefield_source_reference_get_files in FileField Sources 6

Same name and namespace in other branches
  1. 7 sources/reference.inc \filefield_source_reference_get_files()

Get all the files used within a particular field (or all fields).

Parameters

$file_name: The partial name of the file to retrieve.

$field: Optional. A CCK field array for which to filter returned files.

1 call to filefield_source_reference_get_files()
filefield_source_reference_autocomplete in sources/reference.inc
Menu callback; autocomplete.js callback to return a list of files.

File

sources/reference.inc, line 206
A FileField extension to allow referencing of existing files.

Code

function filefield_source_reference_get_files($filename, $field = NULL) {
  if (!isset($field)) {
    foreach (content_fields() as $field) {
      if ($field['type'] == 'filefield') {
        $fields[] = $field;
      }
    }
  }
  else {
    $fields = array(
      $field,
    );
  }
  $files = array();
  foreach ($fields as $field) {
    $db_info = content_database_info($field);

    // 1 == contains, 0 == starts with.
    $like = empty($field['widget']['filefield_source_autocomplete']) ? '%s%%' : '%%%s%%';
    $result = db_query_range("SELECT f.* FROM {" . $db_info['table'] . "} c INNER JOIN {files} f ON c." . $db_info['columns']['fid']['column'] . " = f.fid WHERE f.filename LIKE '" . $like . "' AND f.status = 1 GROUP BY f.fid ORDER BY f.timestamp DESC", $filename, 0, 30);
    while ($file = db_fetch_object($result)) {
      $files[$file->fid] = $file;
    }
  }
  return $files;
}