PHP 클래스 Piwik\Plugin\ViewDataTable

ViewDataTable instances load analytics data via Piwik's Reporting API and then output some type of visualization of that data. Visualizations can be in any format. HTML-based visualizations should extend {@link Visualization}. Visualizations that use other formats, such as visualizations that output an image, should extend ViewDataTable directly. ### Creating ViewDataTables ViewDataTable instances are not created via the new operator, instead the {@link Piwik\ViewDataTable\Factory} class is used. The specific subclass to create is determined, first, by the **viewDataTable** query paramater. If this parameter is not set, then the default visualization type for the report being displayed is used. ### Configuring ViewDataTables **Display properties** ViewDataTable output can be customized by setting one of many available display properties. Display properties are stored as fields in {@link Piwik\ViewDataTable\Config} objects. ViewDataTables store a {@link Piwik\ViewDataTable\Config} object in the {@link $config} field. Display properties can be set at any time before rendering. **Request properties** Request properties are similar to display properties in the way they are set. They are, however, not used to customize ViewDataTable instances, but in the request to Piwik's API when loading analytics data. Request properties are set by setting the fields of a {@link Piwik\ViewDataTable\RequestConfig} object stored in the {@link $requestConfig} field. They can be set at any time before rendering. Setting them after data is loaded will have no effect. **Customizing how reports are displayed** Each individual report should be rendered in its own controller method. There are two ways to render a report within its controller method. You can either: 1. manually create and configure a ViewDataTable instance 2. invoke {@link Piwik\Plugin\Controller::renderReport} and configure the ViewDataTable instance in the {@hook ViewDataTable.configure} event. ViewDataTable instances are configured by setting and modifying display properties and request properties. ### Creating new visualizations New visualizations can be created by extending the ViewDataTable class or one of its descendants. To learn more read our guide on creating new visualizations. ### Examples **Manually configuring a ViewDataTable** a controller method that displays a single report public function myReport() { $view = \Piwik\ViewDataTable\Factory::build('table', 'MyPlugin.myReport'); $view->config->show_limit_control = true; $view->config->translations['myFancyMetric'] = "My Fancy Metric"; ... return $view->render(); } **Using {@link Piwik\Plugin\Controller::renderReport}** First, a controller method that displays a single report: public function myReport() { return $this->renderReport(__FUNCTION__);` } Then the event handler for the {@hook ViewDataTable.configure} event: public function configureViewDataTable(ViewDataTable $view) { switch ($view->requestConfig->apiMethodToRequestDataTable) { case 'MyPlugin.myReport': $view->config->show_limit_control = true; $view->config->translations['myFancyMetric'] = "My Fancy Metric"; ... break; } } **Using custom configuration objects in a new visualization** class MyVisualizationConfig extends Piwik\ViewDataTable\Config { public $my_new_property = true; } class MyVisualizationRequestConfig extends Piwik\ViewDataTable\RequestConfig { public $my_new_property = false; } class MyVisualization extends Piwik\Plugin\ViewDataTable { public static function getDefaultConfig() { return new MyVisualizationConfig(); } public static function getDefaultRequestConfig() { return new MyVisualizationRequestConfig(); } }
상속: implements Piwik\View\ViewInterface
파일 보기 프로젝트 열기: piwik/piwik 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$config Piwik\ViewDataTable\Config Contains display properties for this visualization.
$requestConfig Piwik\ViewDataTable\RequestConfig Contains request properties for this visualization.

보호된 프로퍼티들

프로퍼티 타입 설명
$dataTable Piwik\DataTable DataTable loaded from the API for this ViewDataTable.
$request Piwik\ViewDataTable\Request

공개 메소드들

메소드 설명
__construct ( $controllerAction, $apiMethodToRequestDataTable, $overrideParams = [] ) Constructor. Initializes display and request properties to their default values.
canDisplayViewDataTable ( ViewDataTable $view ) : boolean Returns true if this visualization can display some type of data or not.
getDataTable ( ) : DataTable Returns the DataTable loaded from the API.
getDefaultConfig ( ) : Config Returns the default config instance.
getDefaultRequestConfig ( ) : RequestConfig Returns the default request config instance.
getNonOverridableParams ( $overrideParams ) : array
getViewDataTableId ( ) : string Returns the viewDataTable ID for this DataTable visualization.
isRequestingSingleDataTable ( ) : boolean Returns true if this instance will request a single DataTable, false if requesting more than one.
isViewDataTableId ( string $viewDataTableId ) : boolean Returns true if this instance's or any of its ancestors' viewDataTable IDs equals the supplied ID, false if otherwise.
render ( ) : string Requests all needed data and renders the view.
setDataTable ( DataTable $dataTable ) : void To prevent calling an API multiple times, the DataTable can be set directly.
throwWhenSettingNonOverridableParameter ( $overrideParams ) Display a meaningful error message when any invalid parameter is being set.

보호된 메소드들

메소드 설명
checkStandardDataTable ( ) : void Checks that the API returned a normal DataTable (as opposed to DataTable\Map)
getDefaultDataTableCssClass ( )
getOverridableProperties ( ) : array Returns the list of view properties that can be overriden by query parameters.
getPropertyFromQueryParam ( $name, $defaultValue )
loadDataTableFromAPI ( )

비공개 메소드들

메소드 설명
assignRelatedReportsTitle ( )
overrideViewPropertiesWithParams ( $overrideParams )
overrideViewPropertiesWithQueryParams ( )

메소드 상세

__construct() 공개 메소드

Posts the {@hook ViewDataTable.configure} event which plugins can use to configure the way reports are displayed.
public __construct ( $controllerAction, $apiMethodToRequestDataTable, $overrideParams = [] )

canDisplayViewDataTable() 공개 정적인 메소드

New visualization classes should override this method if they can only visualize certain types of data. The evolution graph visualization, for example, can only visualize sets of DataTables. If the API method used results in a single DataTable, the evolution graph footer icon should not be displayed.
public static canDisplayViewDataTable ( ViewDataTable $view ) : boolean
$view ViewDataTable Contains the API request being checked.
리턴 boolean

checkStandardDataTable() 보호된 메소드

Checks that the API returned a normal DataTable (as opposed to DataTable\Map)
protected checkStandardDataTable ( ) : void
리턴 void

getDataTable() 공개 메소드

Returns the DataTable loaded from the API.
public getDataTable ( ) : DataTable
리턴 Piwik\DataTable

getDefaultConfig() 공개 정적인 메소드

Visualizations that define their own display properties should override this method and return an instance of their new {@link Piwik\ViewDataTable\Config} descendant. See the last example {@link ViewDataTable here} for more information.
public static getDefaultConfig ( ) : Config
리턴 Piwik\ViewDataTable\Config

getDefaultDataTableCssClass() 보호된 메소드

getDefaultRequestConfig() 공개 정적인 메소드

Visualizations that define their own request properties should override this method and return an instance of their new {@link Piwik\ViewDataTable\RequestConfig} descendant. See the last example {@link ViewDataTable here} for more information.
public static getDefaultRequestConfig ( ) : RequestConfig
리턴 Piwik\ViewDataTable\RequestConfig

getNonOverridableParams() 공개 메소드

public getNonOverridableParams ( $overrideParams ) : array
$overrideParams
리턴 array

getOverridableProperties() 보호된 메소드

Returns the list of view properties that can be overriden by query parameters.
protected getOverridableProperties ( ) : array
리턴 array

getPropertyFromQueryParam() 보호된 메소드

protected getPropertyFromQueryParam ( $name, $defaultValue )

getViewDataTableId() 공개 정적인 메소드

Derived classes should not override this method. They should instead declare a const ID field with the viewDataTable ID.
public static getViewDataTableId ( ) : string
리턴 string

isRequestingSingleDataTable() 공개 메소드

Returns true if this instance will request a single DataTable, false if requesting more than one.

isViewDataTableId() 공개 메소드

Can be used to test whether a ViewDataTable object is an instance of a certain visualization or not, without having to know where that visualization is.
public isViewDataTableId ( string $viewDataTableId ) : boolean
$viewDataTableId string The viewDataTable ID to check for, eg, `'table'`.
리턴 boolean

loadDataTableFromAPI() 보호된 메소드

protected loadDataTableFromAPI ( )

render() 공개 메소드

Requests all needed data and renders the view.
public render ( ) : string
리턴 string The result of rendering.

setDataTable() 공개 메소드

It won't be loaded from the API in this case.
public setDataTable ( DataTable $dataTable ) : void
$dataTable Piwik\DataTable The DataTable to use.
리턴 void

throwWhenSettingNonOverridableParameter() 공개 메소드

Display a meaningful error message when any invalid parameter is being set.
public throwWhenSettingNonOverridableParameter ( $overrideParams )
$overrideParams

프로퍼티 상세

$config 공개적으로 프로퍼티

Contains display properties for this visualization.
public Config,Piwik\ViewDataTable $config
리턴 Piwik\ViewDataTable\Config

$dataTable 보호되어 있는 프로퍼티

DataTable loaded from the API for this ViewDataTable.
protected DataTable,Piwik $dataTable
리턴 Piwik\DataTable

$request 보호되어 있는 프로퍼티

protected Request,Piwik\ViewDataTable $request
리턴 Piwik\ViewDataTable\Request

$requestConfig 공개적으로 프로퍼티

Contains request properties for this visualization.
public RequestConfig,Piwik\ViewDataTable $requestConfig
리턴 Piwik\ViewDataTable\RequestConfig