You are here

public function DownloadCountController::downloadCountDetailsTable in Download Count 8

Create and output details table.

1 call to DownloadCountController::downloadCountDetailsTable()
DownloadCountController::downloadCountDetails in src/Controller/DownloadCountController.php
Download_count details page callback.

File

src/Controller/DownloadCountController.php, line 414

Class

DownloadCountController
Returns responses for download_count module routes.

Namespace

Drupal\download_count\Controller

Code

public function downloadCountDetailsTable($result, $caption, $range) {
  $header = [
    [
      'data' => $this
        ->t('#'),
      'class' => 'number',
    ],
    [
      'data' => $this
        ->t('@range', [
        '@range' => $range,
      ]),
      'class' => 'range',
    ],
    [
      'data' => $this
        ->t('Downloads'),
      'class' => 'count',
    ],
  ];
  $count = 1;
  $rows = [];
  $values = [];
  foreach ($result as $download) {
    $row = [];
    $row[] = $count;
    $row[] = $download->time_interval;
    $row[] = number_format($download->count);
    $values[] = $download->count;
    $rows[] = $row;
    $count++;
  }
  $output = [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => [
      'id' => 'download-count-' . Unicode::strtolower($caption),
      'class' => 'download-count-details download-count-table',
    ],
    '#caption' => $caption,
    '#sticky' => FALSE,
  ];
  return [
    'output' => $output,
    'values' => $values,
  ];
}