Contents

Dashboard\Classes\ReportMetric

Overview

ReportMetric represents a report data source metric.


Public Methods

public __construct()

public __construct(
    string $code,
    string $databaseColumnName,
    string $displayName,
    string $aggregateFunction,
    ?array $intlFormatOptions = null
): void

__construct a new metric instance.

public static findMetricByCode()

public static findMetricByCode(
    array $availableMetrics,
    string $metricCode
): ReportMetric|null 

Finds a metric by its code.

public static findMetricByCodeStrict()

public static findMetricByCodeStrict(
    array $availableMetrics,
    string $metricCode,
    bool $throw = true
): ?ReportMetric 

Finds a metric by its code. Throws an exception if the metric is not found.

public formatDisplayValue()

public formatDisplayValue(mixed $value): ?string 

Formats a value using the display formatter callback. Returns null if no formatter is set.

public getAggregateFunction()

public getAggregateFunction(): string 

Returns the metric aggregate function.

public getCacheUniqueCode()

public getCacheUniqueCode(): string 

Returns code unique for this metric to be used as a part of a cache key.

public getCode()

public getCode(): string 

Returns the metric code.

public getDataSetColumName()

public getDataSetColumName(): string 

public getDataSetColumnName()

public getDataSetColumnName(): string 

Returns a query column name corresponding to this metric.

public getDatabaseColumnName()

public getDatabaseColumnName(): string 

Returns the database column name for this metric.

public getDisplayName()

public getDisplayName(): string 

Returns the metric display name.

public getIntlFormatOptions()

public getIntlFormatOptions(): ?array 

Returns client-side data formatting options.

public hasDisplayFormatter()

public hasDisplayFormatter(): bool 

Returns whether this metric has a custom display formatter.

public setDisplayFormatter()

public setDisplayFormatter(callable $formatter): static 

Sets a server-side display formatter callback for human-readable display strings. The callback receives the raw value and should return a formatted string. Used for non-graph displays (tables, indicators) where custom formatting is needed (e.g., durations).