You are here

function theme_uc_file_user_downloads in Ubercart 8.4

Same name and namespace in other branches
  1. 6.2 uc_file/uc_file.pages.inc \theme_uc_file_user_downloads()
  2. 7.3 uc_file/uc_file.pages.inc \theme_uc_file_user_downloads()

Themes user file downloads page.

Parameters

array $variables: An associative array containing:

  • header: Table header array, in format required by theme_table().
  • files: Associative array of downloadable files, containing:
    • granted: Timestamp of file grant.
    • link: URL of file.
    • description: File name, as it should appear to user after downloading.
    • accessed: Integer number of times file has been downloaded.
    • download_limit: Integer limit on downloads.
    • addresses: Integer number of IP addresses used.
    • address_limit: Integer limit on IP addresses.

Return value

string Formatted HTML.

See also

theme_table()

1 string reference to 'theme_uc_file_user_downloads'
uc_file_theme in uc_file/uc_file.module
Implements hook_theme().
1 theme call to theme_uc_file_user_downloads()
DownloadController::userDownloads in uc_file/src/Controller/DownloadController.php
Table builder for user downloads.

File

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

Code

function theme_uc_file_user_downloads(array $variables) {
  $header = $variables['header'];
  $files = $variables['files'];
  $rows = [];
  $row = 0;
  foreach ($files as $file) {
    $rows[] = [
      [
        'data' => \Drupal::service('date.formatter')
          ->format($file['granted'], 'uc_store'),
        'class' => [
          'date-row',
        ],
        'id' => 'date-' . $row,
      ],
      [
        'data' => $file['link'],
        'class' => [
          'filename-row',
        ],
        'id' => 'filename-' . $row,
      ],
      [
        'data' => $file['description'],
        'class' => [
          'description-row',
        ],
        'id' => 'description-' . $row,
      ],
      [
        'data' => $file['accessed'] . '/' . ($file['download_limit'] ? $file['download_limit'] : t('Unlimited')),
        'class' => [
          'download-row',
        ],
        'id' => 'download-' . $row,
      ],
      [
        'data' => count(unserialize($file['addresses'])) . '/' . ($file['address_limit'] ? $file['address_limit'] : t('Unlimited')),
        'class' => [
          'addresses-row',
        ],
        'id' => 'addresses-' . $row,
      ],
    ];
    $row++;
  }
  $build = [];
  $build['downloads'] = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No downloads found'),
  ];
  $build['pager'] = [
    '#theme' => 'pager',
    '#element' => 0,
    '#weight' => 5,
  ];
  $build['instructons'] = [
    '#markup' => '<div class="form-item"><p class="description">' . t('Once your download is finished, you must refresh the page to download again. (Provided you have permission)') . '<br />' . t('Downloads will not be counted until the file is finished transferring, even though the number may increment when you click.') . '<br /><b>' . t('Do not use any download acceleration feature to download the file, or you may lock yourself out of the download.') . '</b>' . '</p></div>',
  ];
  return drupal_render($build);
}