Backend\Classes\ReportDataSourceBase

Overview

ReportDataSourceBase class are used by report widgets to get their data.


Public Properties

public array $vars

vars is a list of variables to pass to the page

public string $layout

layout to use for the view

public bool $suppressLayout

suppressLayout prevents the use of a layout

Protected Properties

protected string|array $viewPath

viewPath specifies a path to the views directory

protected string $layoutPath

layoutPath specifies a path to the layout directory

protected array $viewPathGuessCache

viewPathGuessCache remembers path guesses for performance.


Public Methods

public addViewPath()

public addViewPath(string|array $path, $append = false): void 

addViewPath prepends a path on the available view path locations

public getAvailableDimensions()

public getAvailableDimensions(): ReportDimension[] 

Returns the available dimensions for this data source. Dimensions are attributes of data, e.g. date or "page_path".

public getAvailableMetrics()

public getAvailableMetrics(): ReportMetric[] 

Returns the available metrics for this data source. Metrics are measures of data, e.g. "page views".

public getData()

public getData(
    string $dimensionCode,
    array $metricCodes,
    array $metricsConfiguration,
    ?Carbon $startDate,
    ?Carbon $endDate,
    ?int $startTimestamp,
    array $dimensionFilters,
    ?string $groupInterval,
    ?ReportDataOrderRule $orderRule,
    ?int $limit,
    ?ReportDataPaginationParams $paginationParams,
    ReportDataCache $reportDataCache,
    bool $hideEmptyDimensionValues,
    bool $totalsOnly
): ReportFetchDataResult 

Returns the data for the specified report.

public getViewPath()

public getViewPath(string $fileName, mixed $viewPath = null): string 

getViewPath locates a file based on its definition. The file name can be prefixed with a symbol (~|$) to return in context of the application or plugin base path, otherwise it will be returned in context of this object view path.

public getViewPaths()

public getViewPaths(): array 

getViewPaths returns the active view path locations

public guessViewPath()

public guessViewPath(
    string $suffix = '',
    bool $isPublic = false
): string 

guessViewPath guesses the package path for the called class

public guessViewPathFrom()

public guessViewPathFrom(
    string $class,
    string $suffix = '',
    bool $isPublic = false
): string 

guessViewPathFrom guesses the package path from a specified class, including an optional suffix to attach at the end, and the option to return a public path instead of a local one.

public makeFileContents()

public makeFileContents(
    string $filePath,
    array $extraParams = []
): string 

makeFileContents includes a file path using output buffering

public makeLayout()

public makeLayout(
    string $name = null,
    array $params = [],
    bool $throwException = true
): mixed 

makeLayout renders a layout

public makeLayoutPartial()

public makeLayoutPartial(string $partial, array $params = []): string 

makeLayoutPartial renders a layout partial

public makePartial()

public makePartial(
    string $partial,
    array $params = [],
    bool $throwException = true
): mixed 

makePartial renders a partial file contents located in the views folder

public makeView()

public makeView(string $view): string 

makeView loads a view with the name specified. Applies layout if its name is provided by the parent object. The view file must be situated in the views directory, and has the extension "htm" or "php"

public makeViewContent()

public makeViewContent(
    string $contents,
    string $layout = null
): string 

makeViewContent renders supplied contents inside a layout

public runHandler()

public runHandler(string $handlerName): mixed 

Runs a data source event handler.

Protected Methods

protected addCalculatedDimension()

protected addCalculatedDimension(
    string $code,
    string $displayName
): ReportDimension 

A shorthand version of registerDimension. Adds a calculated dimension that doesn't have a corresponding database column.

protected fetchData()

protected fetchData(
    ReportDimension $dimension,
    array $metrics,
    array $metricsConfiguration,
    ?Carbon $startDate,
    ?Carbon $endDate,
    ?int $startTimestamp,
    array $dimensionFilters,
    ?string $groupInterval,
    ?ReportDataOrderRule $orderRule,
    ?int $limit,
    ?ReportDataPaginationParams $paginationParams,
    bool $hideEmptyDimensionValues,
    bool $totalsOnly
): ReportFetchDataResult 

Returns the data for the specified report.

protected handleViewException()

protected handleViewException($e, $obLevel): void 

handleViewException handles a view exception

protected makeResultRow()

protected makeResultRow(
    ReportDimension $dimension,
    array $metricsAndValues
): array 

Helps format a result row expected in the fetchData return value.

protected registerDimension()

protected registerDimension(ReportDimension $dimension): ReportDimension 

Registers a new dimension.

protected registerMetric()

protected registerMetric($metric): void

Registers a new common metric. Common metrics can be used with any dimension provided by the data source.