Contents

Dashboard\Classes\ReportDataQueryBuilder

Overview

ReportDataQueryBuilder helps building queries for report data sources.

See Also

Public Methods

public __construct()

public __construct(
    string $tableName,
    ReportDimension $dimension,
    array $metrics,
    ReportDataOrderRule $orderRule,
    array $dimensionFilters,
    int $limit,
    ?ReportDataPaginationParams $paginationParams,
    string $groupInterval,
    bool $hideEmptyDimensionValues,
    ?Carbon $startDate,
    ?Carbon $endDate,
    ?int $startTimestamp,
    ?string $dateColumnName,
    ?string $timestampColumnName,
    bool $totalsOnly
): void

Creates a new instance of the query builder.

public static fromFetchData()

public static fromFetchData(
    ReportFetchData $data,
    string $tableName,
    ?string $dateColumnName = null,
    ?string $timestampColumnName = null
): static 

fromFetchData creates a new instance from ReportFetchData.

public getFetchDataResult()

public getFetchDataResult(
    array $metricsConfiguration,
    ?string $recordUrlTemplate = null
): ReportFetchDataResult 

Fetches the report data based on the initialized query and configuration.

This method does the following:

  1. Initializes a query using the initQuery method.
  2. Executes the database queries and constructs a ReportFetchDataResult object.
  3. If pagination is set, it also calculates the total number of records.
  4. Computes metric totals based on the given metric configuration.

This method should be used if no extra configuration is required on the query returned by the initQuery method. If additional configurations are needed, create and configure the ReportFetchDataResult object directly, instead of using this method.

public getMetricTotals()

public getMetricTotals(array $metricsConfiguration): array 

getMetricTotals returns totals for metric with the metric totals or the relative bar enabled.

public getTotalRecords()

public getTotalRecords(): int 

getTotalRecords returns the total number of unpaginated records.

public initQuery()

public initQuery(): Illuminate\Database\Query\Builder 

initQuery initializes a Laravel query based on the provided configuration.

public onConfigureMetric()

public onConfigureMetric(callable $callback): void

Registers a callback to be called when the query is being built to configure a specific metric. Use this method to a metric column to the query. The added metric column name must have the format ocmetric[metric code]

If the callback returns true, the report data query builder doesn't add any additional SQL for the metric.

public onConfigureMetrics()

public onConfigureMetrics(callable $callback): void

Registers a callback to be called when the query is being built to configure metrics. Use this method to add joins to the query for metrics that belong to tables other than the one specified in the constructor.

public onConfigureQuery()

public onConfigureQuery(callable $callback): void

Registers a callback for the final query configuration. Use this method to add dimension fields or filters to the query. The callback must not add pagination filters. The same callback is used for calculating the total number of unpaginated records.

Protected Methods

protected aggregateFunctionToSql()

protected aggregateFunctionToSql($function): string 

protected applyFilter()

protected applyFilter($query, $dimensionFilter): void

protected applyFilters()

protected applyFilters($query): void

protected applyOrderRule()

protected applyOrderRule($query): void

protected createQueryBuilder()

protected createQueryBuilder(
    $forceSkipGrouping = false,
    $forceMetrics = []
): Illuminate\Database\Query\Builder 

protected evalDbObjectName()

protected evalDbObjectName($name): void

evalDbObjectName is a point to check object names for validity

protected makeDateDimensionGroupingColumnName()

protected makeDateDimensionGroupingColumnName($dimensionColumnName): string