You are here

public function ReportTable::viewReport in Commerce Reporting 8

Views a report.

Parameters

string $report_type_id: The report type plugin ID.

string $type: The report type. valid values are week, day, or month fallback.

Return value

array The render array.

1 string reference to 'ReportTable::viewReport'
commerce_reports.routing.yml in ./commerce_reports.routing.yml
commerce_reports.routing.yml

File

src/Controller/ReportTable.php, line 63

Class

ReportTable
Table report controller.

Namespace

Drupal\commerce_reports\Controller

Code

public function viewReport($report_type_id, $type = 'month') {
  if ($type == 'week') {
    $date_format = 'W - Y';
  }
  elseif ($type == 'day') {
    $date_format = 'j F Y';
  }
  else {
    $date_format = 'F Y';
  }
  if (!$this->reportTypeManager
    ->hasDefinition($report_type_id)) {
    throw new \InvalidArgumentException("Invalid report type ID for {$report_type_id}");
  }

  /** @var \Drupal\commerce_reports\Plugin\Commerce\ReportType\ReportTypeInterface $report_type */
  $report_type = $this->reportTypeManager
    ->createInstance($report_type_id);
  $query = $this->reportQueryBuilder
    ->getQuery($report_type, $date_format);
  $results = $query
    ->execute();
  return $report_type
    ->buildReportTable($results);
}