You are here

public function DefaultController::backgroundBatchOverviewPage in Background Process 8

Implements Background Batch Overview Page.

1 string reference to 'DefaultController::backgroundBatchOverviewPage'
background_batch.routing.yml in background_batch/background_batch.routing.yml
background_batch/background_batch.routing.yml

File

background_batch/src/Controller/DefaultController.php, line 16

Class

DefaultController
Default controller for the background_batch module.

Namespace

Drupal\background_batch\Controller

Code

public function backgroundBatchOverviewPage() {
  $data = [];
  $bids = db_select('batch', 'b')
    ->fields('b', [
    'bid',
  ])
    ->orderBy('b.bid', 'ASC')
    ->execute()
    ->fetchAllKeyed(0, 0);
  foreach ($bids as $bid) {
    $progress = progress_get_progress('_background_batch:' . $bid);
    if (!$progress) {
      $progress = (object) [
        'start' => 0,
        'end' => 0,
        'progress' => 0,
        'message' => $this
          ->t('N/A'),
      ];
    }
    $eta = progress_estimate_completion($progress);
    $data[] = [
      $progress->end ? $bid : $this
        ->l($bid, Url::fromRoute('system.batch_page.html')),
      sprintf("%.2f%%", $progress->progress * 100),
      $progress->message,
      $progress->start ? \Drupal::service('date.formatter')
        ->format((int) $progress->start, 'small') : $this
        ->t('N/A'),
      $progress->end ? \Drupal::service('date.formatter')
        ->format((int) $progress->end, 'small') : ($eta ? \Drupal::service('date.formatter')
        ->format((int) $eta, 'small') : $this
        ->t('N/A')),
    ];
  }
  $header = [
    'Batch ID',
    'Progress',
    'Message',
    'Started',
    'Finished/ETA',
  ];
  $markup = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $data,
  ];
  return $markup;
}