function tripal_user_files_page

3.x tripal.user.inc tripal_user_files_page($uid)

Provides the page with a list of files uploaded by the user.

Parameters

$uid: The user ID.

Return value

A Drupal render array.

1 string reference to 'tripal_user_files_page'
tripal_menu in tripal/tripal.module
Implements hook_menu(). Defines all menu items needed by Tripal Core

File

tripal/includes/tripal.user.inc, line 13

Code

function tripal_user_files_page($uid) {

  // Get all of the files that have been uploaded by the user.
  // TODO: we should make this a paged query in case a user has a huge
  // numbef of uploaded files.
  $sql = "
     SELECT FM.fid, FM.filename, TGEF.expiration_date
     FROM {file_managed} FM
       INNER JOIN {file_usage} FU on FM.fid = FU.fid and FM.uid = :user_id
       LEFT JOIN {tripal_expiration_files} TGEF on TGEF.fid = FU.fid
     WHERE FU.module = 'tripal'
     GROUP BY FM.fid, TGEF.expiration_date
     ORDER BY FM.filename
   ";
  $files = db_query($sql, array(':user_id' => $uid));
  $rows = array();
  while ($entry = $files->fetchObject()) {
    $file = file_load($entry->fid);

    // Don't list files that don't exist on the file system.
    if (!file_exists($file->uri)) {
      continue;
    }

    $date_uploaded = date('Y-m-d H:i:s', $file->timestamp);
    $expiration = $entry->expiration_date ? date('Y-m-d H:i:s', $entry->expiration_date) : '';
    $actions = l('Delete', "user/$uid/files/$file->fid/delete") . ' | ' .
      l('Renew', "user/$uid/files/$file->fid/renew");

    $rows[] = array(
      $entry->fid,
      l($file->filename, "/user/$uid/files/$file->fid"),
      $date_uploaded,
      $expiration,
      tripal_format_bytes($file->filesize),
      $actions,
    );
  }
  $header = array('ID', 'File Name', 'Upload Date', 'Expiration', 'Size', 'Actions');

  // Get the user quota settings.
  $quota = tripal_get_user_quota($uid);
  $usage = tripal_get_user_usage($uid);

  $content = array(
    'page_title' => array(
      '#type' => 'markup',
      '#markup' => '<h2>Your Uploaded Files</h2>',
    ),
    'page_description' => array(
      '#type' => 'markup',
      '#markup' => '<p>' . t('Each user is allowed to consume a limited amount of space with uploaded files. This page provides details about your current usage, your limits and files you\'ve uploaded.') . '</p>',
    ),
    'usage' => array(
      '#type' => 'item',
      '#title' => 'Current Usage',
      '#markup' => tripal_format_bytes($usage),
      '#description' => t('The total number of bytes you currently consume.'),
    ),
    'quota' => array(
      '#type' => 'item',
      '#title' => 'Current Quota',
      '#markup' => tripal_format_bytes($quota->custom_quota),
      '#description' => t('The maximum number of bytes of files you can upload.')
    ),
    'expiration' => array(
      '#type' => 'item',
      '#title' => 'Current Days to Expire',
      '#markup' => $quota->custom_expiration,
      '#description' => t('The number of days a file will remain on the server before deletion. The expiration of date of a file can be renewed using the "Renew" link in the table below.')
    ),
    'file_list' => array(
      '#type' => 'item',
      '#title' => 'Uploaded Files',
      '#markup' => theme_table(array(
        'header' => $header,
        'rows' => $rows,
        'attributes' => array(),
        'caption' => t('Click a file name for more details.'),
        'colgroups' => array(),
        'sticky' => TRUE,
        'empty' => 'You currently have no uploaded files.',
      )),
    )
  );


  if ($usage < $quota->custom_quota) {
    drupal_set_message('Your file usage is currently below the file quota limit.');
  }
  else {
    drupal_set_message('Your file usage is currently over your file quota limit. Please remove some files before uploading more', 'warning');
  }

  return $content;
}