PHP Class Piwik\Plugin\Metric

A metric metadata class is a class that describes how a metric is described, computed and formatted. There are two types of metrics: aggregated and processed. An aggregated metric is computed in the backend datastore and aggregated in PHP when archiving period reports. Currently, only processed metrics can be defined as metric metadata classes. Support for aggregated metrics will be added at a later date. See {@link Piwik\Plugin\ProcessedMetric} and {@link Piwik\Plugin|AggregatedMetric}.
Afficher le fichier Open project: piwik/piwik Class Usage Examples

Méthodes publiques

Méthode Description
beforeFormat ( Report $report, DataTable $table ) : boolean Executed before formatting all metrics for a report. Implementers can return false to skip formatting this metric and can use this method to access information needed for formatting (for example, the site ID).
format ( mixed $value, Piwik\Metrics\Formatter $formatter ) : mixed Returns a formatted metric value. This value is what appears in API output. From within Piwik, (core & plugins) the computed value is used. Only when outputting to the API does a metric get formatted.
getActualMetricColumn ( DataTable $table, string $columnName, int[] | null $mappingNameToId = null ) : string Helper method that determines the actual column for a metric in a {@link Piwik\DataTable}.
getDocumentation ( ) : string Returns a string describing what the metric represents. The result will be included in report metadata API output, including processed reports.
getMetric ( Row | array $row, string $columnName, int[] | null $mappingNameToId = null ) : mixed Helper method that will access a metric in a {@link Piwik\DataTable\Row} or array either by its name or by its special numerical index value.
getMetricValues ( DataTable $table, string $columnName, int[] | null $mappingNameToId = null ) : array Helper method that will determine the actual column name for a metric in a {@link Piwik\DataTable} and return every column value for this name.
getName ( ) : string Returns the column name of this metric, eg, "nb_visits" or "avg_time_on_site".
getTranslatedName ( ) : string Returns the human readable translated name of this metric, eg, "Visits" or "Avg. time on site".

Method Details

beforeFormat() public méthode

Executed before formatting all metrics for a report. Implementers can return false to skip formatting this metric and can use this method to access information needed for formatting (for example, the site ID).
public beforeFormat ( Report $report, DataTable $table ) : boolean
$report Report
$table Piwik\DataTable
Résultat boolean Return `true` to format the metric for the table, `false` to skip formatting.

format() public méthode

By default, just returns the value.
public format ( mixed $value, Piwik\Metrics\Formatter $formatter ) : mixed
$value mixed The metric value.
$formatter Piwik\Metrics\Formatter The formatter to use when formatting a value.
Résultat mixed $value

getActualMetricColumn() public static méthode

Helper method that determines the actual column for a metric in a {@link Piwik\DataTable}.
public static getActualMetricColumn ( DataTable $table, string $columnName, int[] | null $mappingNameToId = null ) : string
$table Piwik\DataTable
$columnName string
$mappingNameToId int[] | null A custom mapping of metric names to special index values. By default {@link Metrics::getMappingFromNameToId()} is used.
Résultat string

getDocumentation() public méthode

Implementing this method is optional.
public getDocumentation ( ) : string
Résultat string

getMetric() public static méthode

Helper method that will access a metric in a {@link Piwik\DataTable\Row} or array either by its name or by its special numerical index value.
public static getMetric ( Row | array $row, string $columnName, int[] | null $mappingNameToId = null ) : mixed
$row Piwik\DataTable\Row | array
$columnName string
$mappingNameToId int[] | null A custom mapping of metric names to special index values. By default {@link Metrics::getMappingFromNameToId()} is used.
Résultat mixed The metric value or false if none exists.

getMetricValues() public static méthode

Helper method that will determine the actual column name for a metric in a {@link Piwik\DataTable} and return every column value for this name.
public static getMetricValues ( DataTable $table, string $columnName, int[] | null $mappingNameToId = null ) : array
$table Piwik\DataTable
$columnName string
$mappingNameToId int[] | null A custom mapping of metric names to special index values. By default {@link Metrics::getMappingFromNameToId()} is used.
Résultat array

getName() abstract public méthode

This string is what appears in API output.
abstract public getName ( ) : string
Résultat string

getTranslatedName() abstract public méthode

This string is what appears in the UI.
abstract public getTranslatedName ( ) : string
Résultat string