PHP Класс Piwik\Plugin\Report

You can create a new report using the console command ./console generate:report. The generated report will guide you through the creation of a report.
С версии: 2.5.0
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$action string The name of the action. The action is detected automatically depending on the file name. A corresponding action should exist in the API as well.
$actionToLoadSubTables string The name of the API action to load a subtable if supported. The action has to be of the same module. For instance a report "getKeywords" might support a subtable "getSearchEngines" which shows how often a keyword was searched via a specific search engine.
$categoryId string The translation key of the category the report belongs to.
$constantRowsCount boolean Set it to boolean true if your report always returns a constant count of rows, for instance always 24 rows for 1-24 hours.
$defaultSortColumn string | integer Default sort column. Either a column name or a column id.
$defaultSortOrderDesc boolean Default sort desc. If true will sort by default desc, if false will sort by default asc
$dimension Piwik\Columns\Dimension An instance of a dimension if the report has one. You can create a new dimension using the Piwik console CLI tool if needed.
$documentation string A translated documentation which explains the report.
$hasGoalMetrics boolean Set this property to true in case your report supports goal metrics. In this case, the goal metrics will be automatically added to the report metadata and the report will be displayed in the Goals UI.
$isSubtableReport boolean Set it to boolean true if this report is a subtable report and won't be used as a standalone report.
$metrics array ..)`. Defaults to the platform default metrics see {@link Metrics::getDefaultProcessedMetrics()}.
$module string The name of the module which is supposed to be equal to the name of the plugin. The module is detected automatically.
$name string The translated name of the report. The name will be used for instance in the mobile app or if another report defines this report as a related report.
$order integer The order of the report. Depending on the order the report gets a different position in the list of widgets, the menu and the mobile app.
$parameters null | array Some reports may require additional URL parameters that need to be sent when a report is requested. For instance a "goal" report might need a "goalId": array('idgoal' => 5).
$processedMetrics array Eg array('avg_time_on_site', 'nb_actions_per_visit', ...)
$recursiveLabelSeparator string Separator for building recursive labels (or paths)
$subcategoryId string The translation key of the subcategory the report belongs to.

Открытые методы

Метод Описание
__construct ( ) The constructur initializes the module, action and the default metrics. If you want to overwrite any of those values or if you want to do any work during initializing overwrite the method {@link init()}.
alwaysUseDefaultViewDataTable ( ) : boolean Returns if the default viewDataTable type should always be used. e.g. the type won't be changeable through config or url params.
checkIsEnabled ( ) This method checks whether the report is available, see {@isEnabled()}. If not, it triggers an exception containing a message that will be displayed to the user. You can overwrite this message in case you want to customize the error message. Eg.
configureReportMetadata ( &$availableReports, $infos ) If the report is enabled the report metadata for this report will be built and added to the list of available reports. Overwrite this method and leave it empty in case you do not want your report to be added to the report metadata. In this case your report won't be visible for instance in the mobile app and scheduled reports generator. We recommend to change this behavior only if you are familiar with the Piwik core. $infos contains the current requested date, period and site.
configureView ( ViewDataTable $view ) Here you can configure how your report should be displayed and which capabilities your report has. For instance whether your report supports a "search" or not. EG $view->config->show_search = false. You can also change the default request config. For instance you can change how many rows are displayed by default: $view->requestConfig->filter_limit = 10;. See {@link ViewDataTable} for more information.
configureWidgets ( WidgetsList $widgetsList, ReportWidgetFactory $factory ) lets you add any amount of widgets for this report. If a report defines a {@link $categoryId} and a {@link $subcategoryId} a widget will be generated automatically.
fetch ( array $paramOverride = [] ) : DataTable Fetches the report represented by this instance.
fetchSubtable ( integer $idSubtable, array $paramOverride = [] ) : DataTable Fetches a subtable for the report represented by this instance.
getAction ( ) : string Get the name of the action.
getActionToLoadSubTables ( ) : string Get the action to load sub tables if one is defined.
getAllMetrics ( ) : array Returns the array of all metrics displayed by this report.
getCategoryId ( ) : string Get the translated name of the category the report belongs to.
getDefaultSortColumn ( )
getDefaultSortOrder ( )
getDefaultTypeViewDataTable ( ) : string Returns the id of the default visualization for this report. Eg 'table' or 'pie'. Defaults to the HTML table.
getDimension ( ) : Dimension
getDocumentation ( ) : string Get report documentation.
getForDimension ( Dimension $dimension ) : Report | null Finds a top level report that provides stats for a specific Dimension.
getMetrics ( ) : array Returns an array of supported metrics and their corresponding translations. Eg array('nb_visits' => 'Visits').
getMetricsForTable ( DataTable $dataTable, Report $report = null, string $baseType = 'Piwik\Plugin\Metric' ) : Metric[] Returns the Metrics that are displayed by a DataTable of a certain Report type.
getMetricsRequiredForReport ( string[] | null $allMetrics = null, string[] | null $restrictToColumns = null ) : string[] Returns the list of metrics required at minimum for a report factoring in the columns requested by the report requester.
getModule ( ) : string Get the name of the module.
getName ( ) : string Get the name of the report
getOrder ( ) : integer Returns the order of the report
getParameters ( )
getProcessedMetrics ( ) : array | mixed Returns an array of supported processed metrics and their corresponding translations. Eg array('nb_visits' => 'Visits'). By default the given {@link $processedMetrics} are used and their corresponding translations are looked up automatically. If a metric is not translated, you should add the default metric translation for this metric using the {@hook Metrics.getDefaultMetricTranslations} event. If you want to overwrite any default metric translation you should overwrite this method, call this parent method to get all default translations and overwrite any custom metric translations.
getProcessedMetricsById ( ) : Piwik\Plugin\ProcessedMetric[] Returns an array mapping the ProcessedMetrics served by this report by their string names.
getProcessedMetricsForTable ( DataTable $dataTable, Report $report = null ) : Piwik\Plugin\ProcessedMetric[] Returns the ProcessedMetrics that should be computed and formatted for a DataTable of a certain report. The ProcessedMetrics returned are those specified by the Report metadata as well as the DataTable metadata.
getRecursiveLabelSeparator ( )
getRelatedReports ( ) : Report[] Get the list of related reports if there are any. They will be displayed for instance below a report as a recommended related report.
getSubcategoryId ( ) : string Get the translated name of the subcategory the report belongs to.
getSubtableDimension ( ) : Dimension | null Returns the Dimension instance of this report's subtable report.
hasGoalMetrics ( ) : boolean
isEnabled ( ) : boolean Defines whether a report is enabled or not. For instance some reports might not be available to every user or might depend on a setting (such as Ecommerce) of a site. In such a case you can perform any checks and then return true or false. If your report is only available to users having super user access you can do the following: return Piwik::hasUserSuperUserAccess();
isSubtableReport ( ) : boolean Returns true if the report is for another report's subtable, false if otherwise.
render ( ) : string Renders a report depending on the configured ViewDataTable see {@link configureView()} and {@link getDefaultTypeViewDataTable()}. If you want to customize the render process or just render any custom view you can overwrite this method.

Защищенные методы

Метод Описание
buildReportMetadata ( ) : array Builts the report metadata for this report. Can be useful in case you want to change the behavior of {@link configureReportMetadata()}.
getMetricsDocumentation ( ) : array Returns an array of metric documentations and their corresponding translations. Eg `array('nb_visits' => 'If a visitor comes to your website for the first time or if he visits a page more than 30 minutes after.
init ( ) Here you can do any instance initialization and overwrite any default values. You should avoid doing time consuming initialization here and if possible delay as long as possible. An instance of this report will be created in most page requests.

Приватные методы

Метод Описание
getMetricTranslations ( $metricsToTranslate )
getSubtableApiMethod ( )

Описание методов

__construct() закрытый публичный Метод

The constructur initializes the module, action and the default metrics. If you want to overwrite any of those values or if you want to do any work during initializing overwrite the method {@link init()}.
final public __construct ( )

alwaysUseDefaultViewDataTable() публичный Метод

Defaults to false
public alwaysUseDefaultViewDataTable ( ) : boolean
Результат boolean

buildReportMetadata() защищенный Метод

Builts the report metadata for this report. Can be useful in case you want to change the behavior of {@link configureReportMetadata()}.
protected buildReportMetadata ( ) : array
Результат array

checkIsEnabled() публичный Метод

if (!$this->isEnabled()) { throw new Exception('Setting XYZ is not enabled or the user has not enough permission'); }
public checkIsEnabled ( )

configureReportMetadata() публичный Метод

If the report is enabled the report metadata for this report will be built and added to the list of available reports. Overwrite this method and leave it empty in case you do not want your report to be added to the report metadata. In this case your report won't be visible for instance in the mobile app and scheduled reports generator. We recommend to change this behavior only if you are familiar with the Piwik core. $infos contains the current requested date, period and site.
public configureReportMetadata ( &$availableReports, $infos )
$availableReports
$infos

configureView() публичный Метод

Here you can configure how your report should be displayed and which capabilities your report has. For instance whether your report supports a "search" or not. EG $view->config->show_search = false. You can also change the default request config. For instance you can change how many rows are displayed by default: $view->requestConfig->filter_limit = 10;. See {@link ViewDataTable} for more information.
public configureView ( ViewDataTable $view )
$view ViewDataTable

configureWidgets() публичный Метод

Example to add a widget manually by overwriting this method in your report: $widgetsList->addWidgetConfig($factory->createWidget()); If you want to have the name and the order of the widget differently to the name and order of the report you can do the following: $widgetsList->addWidgetConfig($factory->createWidget()->setName('Custom')->setOrder(5)); If you want to add a widget to any container defined by your plugin or by another plugin you can do this: $widgetsList->addToContainerWidget($containerId = 'Products', $factory->createWidget());
public configureWidgets ( WidgetsList $widgetsList, ReportWidgetFactory $factory )
$widgetsList Piwik\Widget\WidgetsList
$factory Piwik\Report\ReportWidgetFactory

fetch() публичный Метод

Fetches the report represented by this instance.
public fetch ( array $paramOverride = [] ) : DataTable
$paramOverride array Query parameter overrides.
Результат Piwik\DataTable

fetchSubtable() публичный Метод

Fetches a subtable for the report represented by this instance.
public fetchSubtable ( integer $idSubtable, array $paramOverride = [] ) : DataTable
$idSubtable integer The subtable ID.
$paramOverride array Query parameter overrides.
Результат Piwik\DataTable

getAction() публичный Метод

Get the name of the action.
public getAction ( ) : string
Результат string

getActionToLoadSubTables() публичный Метод

Get the action to load sub tables if one is defined.
public getActionToLoadSubTables ( ) : string
Результат string

getAllMetrics() публичный Метод

Returns the array of all metrics displayed by this report.
public getAllMetrics ( ) : array
Результат array

getCategoryId() публичный Метод

Get the translated name of the category the report belongs to.
public getCategoryId ( ) : string
Результат string

getDefaultSortColumn() публичный Метод

getDefaultSortOrder() публичный Метод

public getDefaultSortOrder ( )

getDefaultTypeViewDataTable() публичный Метод

Returns the id of the default visualization for this report. Eg 'table' or 'pie'. Defaults to the HTML table.
public getDefaultTypeViewDataTable ( ) : string
Результат string

getDimension() публичный Метод

public getDimension ( ) : Dimension
Результат Piwik\Columns\Dimension

getDocumentation() публичный Метод

Get report documentation.
public getDocumentation ( ) : string
Результат string

getForDimension() публичный статический Метод

Finds a top level report that provides stats for a specific Dimension.
public static getForDimension ( Dimension $dimension ) : Report | null
$dimension Piwik\Columns\Dimension The dimension whose report we're looking for.
Результат Report | null The

getMetrics() публичный Метод

By default the given {@link $metrics} are used and their corresponding translations are looked up automatically. If a metric is not translated, you should add the default metric translation for this metric using the {@hook Metrics.getDefaultMetricTranslations} event. If you want to overwrite any default metric translation you should overwrite this method, call this parent method to get all default translations and overwrite any custom metric translations.
public getMetrics ( ) : array
Результат array

getMetricsDocumentation() защищенный Метод

..')`. By default the given {@link $metrics} are used and their corresponding translations are looked up automatically. If there is a metric documentation not found, you should add the default metric documentation translation for this metric using the {@hook Metrics.getDefaultMetricDocumentationTranslations} event. If you want to overwrite any default metric translation you should overwrite this method, call this parent method to get all default translations and overwrite any custom metric translations.
protected getMetricsDocumentation ( ) : array
Результат array

getMetricsForTable() публичный статический Метод

Includes ProcessedMetrics and Metrics.
public static getMetricsForTable ( DataTable $dataTable, Report $report = null, string $baseType = 'Piwik\Plugin\Metric' ) : Metric[]
$dataTable Piwik\DataTable
$report Report
$baseType string The base type each metric class needs to be of.
Результат Metric[]

getMetricsRequiredForReport() публичный Метод

This will return all the metrics requested (or all the metrics in the report if nothing is requested) **plus** the metrics required to calculate the requested processed metrics. This method should be used in **Plugin.get** API methods.
public getMetricsRequiredForReport ( string[] | null $allMetrics = null, string[] | null $restrictToColumns = null ) : string[]
$allMetrics string[] | null The list of all available unprocessed metrics. Defaults to this report's metrics.
$restrictToColumns string[] | null The requested columns.
Результат string[]

getModule() публичный Метод

Get the name of the module.
public getModule ( ) : string
Результат string

getName() публичный Метод

Get the name of the report
public getName ( ) : string
Результат string

getOrder() публичный Метод

Returns the order of the report
public getOrder ( ) : integer
Результат integer

getParameters() публичный Метод

public getParameters ( )

getProcessedMetrics() публичный Метод

Returns an array of supported processed metrics and their corresponding translations. Eg array('nb_visits' => 'Visits'). By default the given {@link $processedMetrics} are used and their corresponding translations are looked up automatically. If a metric is not translated, you should add the default metric translation for this metric using the {@hook Metrics.getDefaultMetricTranslations} event. If you want to overwrite any default metric translation you should overwrite this method, call this parent method to get all default translations and overwrite any custom metric translations.
public getProcessedMetrics ( ) : array | mixed
Результат array | mixed

getProcessedMetricsById() публичный Метод

Returns an array mapping the ProcessedMetrics served by this report by their string names.
public getProcessedMetricsById ( ) : Piwik\Plugin\ProcessedMetric[]
Результат Piwik\Plugin\ProcessedMetric[]

getProcessedMetricsForTable() публичный статический Метод

Returns the ProcessedMetrics that should be computed and formatted for a DataTable of a certain report. The ProcessedMetrics returned are those specified by the Report metadata as well as the DataTable metadata.
public static getProcessedMetricsForTable ( DataTable $dataTable, Report $report = null ) : Piwik\Plugin\ProcessedMetric[]
$dataTable Piwik\DataTable
$report Report
Результат Piwik\Plugin\ProcessedMetric[]

getRecursiveLabelSeparator() публичный Метод

getRelatedReports() публичный Метод

Get the list of related reports if there are any. They will be displayed for instance below a report as a recommended related report.
public getRelatedReports ( ) : Report[]
Результат Report[]

getSubcategoryId() публичный Метод

Get the translated name of the subcategory the report belongs to.
public getSubcategoryId ( ) : string
Результат string

getSubtableDimension() публичный Метод

Returns the Dimension instance of this report's subtable report.
public getSubtableDimension ( ) : Dimension | null
Результат Piwik\Columns\Dimension | null The subtable report's dimension or null if there is subtable report or no dimension for the subtable report.

hasGoalMetrics() публичный Метод

public hasGoalMetrics ( ) : boolean
Результат boolean

init() защищенный Метод

Here you can do any instance initialization and overwrite any default values. You should avoid doing time consuming initialization here and if possible delay as long as possible. An instance of this report will be created in most page requests.
protected init ( )

isEnabled() публичный Метод

Defines whether a report is enabled or not. For instance some reports might not be available to every user or might depend on a setting (such as Ecommerce) of a site. In such a case you can perform any checks and then return true or false. If your report is only available to users having super user access you can do the following: return Piwik::hasUserSuperUserAccess();
public isEnabled ( ) : boolean
Результат boolean

isSubtableReport() публичный Метод

Returns true if the report is for another report's subtable, false if otherwise.
public isSubtableReport ( ) : boolean
Результат boolean

render() публичный Метод

Renders a report depending on the configured ViewDataTable see {@link configureView()} and {@link getDefaultTypeViewDataTable()}. If you want to customize the render process or just render any custom view you can overwrite this method.
public render ( ) : string
Результат string

Описание свойств

$action защищенное свойство

The name of the action. The action is detected automatically depending on the file name. A corresponding action should exist in the API as well.
protected string $action
Результат string

$actionToLoadSubTables защищенное свойство

The name of the API action to load a subtable if supported. The action has to be of the same module. For instance a report "getKeywords" might support a subtable "getSearchEngines" which shows how often a keyword was searched via a specific search engine.
protected string $actionToLoadSubTables
Результат string

$categoryId защищенное свойство

The translation key of the category the report belongs to.
protected string $categoryId
Результат string

$constantRowsCount защищенное свойство

Set it to boolean true if your report always returns a constant count of rows, for instance always 24 rows for 1-24 hours.
protected bool $constantRowsCount
Результат boolean

$defaultSortColumn защищенное свойство

Default sort column. Either a column name or a column id.
protected string|int $defaultSortColumn
Результат string | integer

$defaultSortOrderDesc защищенное свойство

Default sort desc. If true will sort by default desc, if false will sort by default asc
protected bool $defaultSortOrderDesc
Результат boolean

$dimension защищенное свойство

An instance of a dimension if the report has one. You can create a new dimension using the Piwik console CLI tool if needed.
protected Dimension,Piwik\Columns $dimension
Результат Piwik\Columns\Dimension

$documentation защищенное свойство

A translated documentation which explains the report.
protected string $documentation
Результат string

$hasGoalMetrics защищенное свойство

Set this property to true in case your report supports goal metrics. In this case, the goal metrics will be automatically added to the report metadata and the report will be displayed in the Goals UI.
protected bool $hasGoalMetrics
Результат boolean

$isSubtableReport защищенное свойство

Set it to boolean true if this report is a subtable report and won't be used as a standalone report.
protected bool $isSubtableReport
Результат boolean

$metrics защищенное свойство

..)`. Defaults to the platform default metrics see {@link Metrics::getDefaultProcessedMetrics()}.
protected array $metrics
Результат array

$module защищенное свойство

The name of the module which is supposed to be equal to the name of the plugin. The module is detected automatically.
protected string $module
Результат string

$name защищенное свойство

The translated name of the report. The name will be used for instance in the mobile app or if another report defines this report as a related report.
protected string $name
Результат string

$order защищенное свойство

The order of the report. Depending on the order the report gets a different position in the list of widgets, the menu and the mobile app.
protected int $order
Результат integer

$parameters защищенное свойство

Some reports may require additional URL parameters that need to be sent when a report is requested. For instance a "goal" report might need a "goalId": array('idgoal' => 5).
protected null|array $parameters
Результат null | array

$processedMetrics защищенное свойство

Eg array('avg_time_on_site', 'nb_actions_per_visit', ...)
protected array $processedMetrics
Результат array

$recursiveLabelSeparator защищенное свойство

Separator for building recursive labels (or paths)
protected string $recursiveLabelSeparator
Результат string

$subcategoryId защищенное свойство

The translation key of the subcategory the report belongs to.
protected string $subcategoryId
Результат string