You are here

public function ReportQueryBuilder::getQuery in Commerce Reporting 8

Builds the report query to be executed.

Parameters

\Drupal\commerce_reports\Plugin\Commerce\ReportType\ReportTypeInterface $report_type: The report type.

string $date_format: The date format.

Return value

\Drupal\Core\Entity\Query\QueryAggregateInterface The aggregate query.

File

src/ReportQueryBuilder.php, line 43

Class

ReportQueryBuilder
Provides an aggregate query builder for order reports.

Namespace

Drupal\commerce_reports

Code

public function getQuery(ReportTypeInterface $report_type, $date_format = 'F Y') {
  $query = $this->storage
    ->getAggregateQuery();

  // Always filter by the report type.
  $query
    ->condition('type', $report_type
    ->getPluginId());

  // Order ID should always have a count.
  $query
    ->aggregate('order_id', 'COUNT');

  // Tag so we can alter.
  $query
    ->addTag('commerce_reports');

  // Information to use in our alter.
  $query
    ->addMetaData('report_date_format', $date_format);
  $query
    ->addMetaData('report_type_id', $report_type
    ->getPluginId());

  // Let the report type plugin build the query.
  $report_type
    ->buildQuery($query);
  return $query;
}