PHP 클래스 Piwik\Plugin\Controller

Plugins that wish to add display HTML should create a Controller that either extends from this class or from {@link ControllerAdmin}. Every public method in the controller will be exposed as a controller method and can be invoked via an HTTP request. Learn more about Piwik's MVC system here. ### Examples **Defining a controller** class Controller extends \Piwik\Plugin\Controller { public function index() { $view = new View("@MyPlugin/index.twig"); ... setup view ... return $view->render(); } } **Linking to a controller action** Link
파일 보기 프로젝트 열기: piwik/piwik 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$date Piwik\Date | null The Date object created with ($strDate)[#strDate] or null if the requested date is a range.
$idSite integer The value of the **idSite** query parameter.
$pluginName string The plugin name, eg. 'Referrers'.
$site Piwik\Site The Site object created with {@link $idSite}.
$strDate string The value of the **date** query parameter.

공개 메소드들

메소드 설명
__construct ( ) Constructor.
getCalendarPrettyDate ( Piwik\Period $period ) : string Returns a prettified date string for use in period selector widget.
getDefaultAction ( ) : string Returns the name of the default method that will be called when visiting: index.php?module=PluginName without the action parameter.
getPrettyDate ( $date, $period ) : string Returns the pretty date representation
redirectToIndex ( string $moduleToRedirect, string $actionToRedirect, integer | null $websiteId = null, string | null $defaultPeriod = null, string | null $defaultDate = null, array $parameters = [] ) Helper method used to redirect the current HTTP request to another module/action.
setHostValidationVariablesView ( View $view ) Checks if the current host is valid and sets variables on the given view, including:
setPeriodVariablesView ( View $view ) Sets general period variables on a view, including:

보호된 메소드들

메소드 설명
addCustomLogoInfo ( $view )
checkSitePermission ( )
checkTokenInUrl ( ) Checks that the token_auth in the URL matches the currently logged-in user's token_auth.
getDateParameterInTimezone ( string $date, string $timezone ) : Date Helper method that converts "today" or "yesterday" to the specified timezone.
getEnabledPeriodsInUI ( ) : array Returns values that are enabled for the parameter &period=
getGraphParamsModified ( array $paramsToSet = [] ) : array Returns the array of new processed parameters once the parameters are applied.
getLastUnitGraph ( string $currentModuleName, string $currentControllerAction, string $apiMethod ) : ViewDataTable Returns a ViewDataTable object that will render a jqPlot evolution graph for the last30 days/weeks/etc. of the current period, relative to the current date.
getLastUnitGraphAcrossPlugins ( string $currentModuleName, string $currentControllerAction, array $columnsToDisplay = false, array $selectableColumns = [], boolean | string $reportDocumentation = false, string $apiMethod = 'API.get' ) : ViewDataTable Same as {@link getLastUnitGraph()}, but will set some properties of the ViewDataTable object based on the arguments supplied.
getNumericValue ( string $methodToCall, boolean | string $date = false ) : integer | float Returns a numeric value from the API.
getUrlSparkline ( string $action, array $customParameters = [] ) : string Returns a URL to a sparkline image for a report served by the current plugin.
init ( )
renderReport ( string | Report $apiAction, boolean $controllerAction = false ) : string | void Convenience method that creates and renders a ViewDataTable for a API method.
renderTemplate ( string $template, array $variables = [] ) : string Assigns the given variables to the template and renders it.
renderView ( Piwik\View\ViewInterface $view ) : string | void A helper method that renders a view either to the screen or to a string.
setBasicVariablesView ( View $view ) Assigns a set of generally useful variables to a {@link Piwik\View} instance.
setDate ( Date $date ) : void Sets the date to be used by all other methods in the controller.
setGeneralVariablesView ( View $view ) : void Assigns variables to {@link Piwik\View} instances that display an entire page.
setMaxDateView ( Date $maxDate, View $view ) Sets the last date available in the period selector's calendar. Usually this is just the "today" date for a site (which varies based on the timezone of a site).
setMinDateView ( Date $minDate, View $view ) Sets the first date available in the period selector's calendar.

비공개 메소드들

메소드 설명
doRedirectToUrl ( $moduleToRedirect, $actionToRedirect, $websiteId, $defaultPeriod, $defaultDate, $parameters )
getEnabledPeriodsNames ( ) : array
getValidDate ( Date $date, Date $minDate, Date $maxDate )

메소드 상세

__construct() 공개 메소드

Constructor.
public __construct ( )

addCustomLogoInfo() 보호된 메소드

protected addCustomLogoInfo ( $view )

checkSitePermission() 보호된 메소드

protected checkSitePermission ( )

checkTokenInUrl() 보호된 메소드

This is a protection against CSRF and should be used in all controller methods that modify Piwik or any user settings. If called from JavaScript by using the ajaxHelper you have to call ajaxHelper.withTokenInUrl(); before ajaxHandler.send(); to send the token along with the request. **The token_auth should never appear in the browser's address bar.**
protected checkTokenInUrl ( )

getCalendarPrettyDate() 공개 정적인 메소드

Returns a prettified date string for use in period selector widget.
public static getCalendarPrettyDate ( Piwik\Period $period ) : string
$period Piwik\Period The period to return a pretty string for.
리턴 string

getDateParameterInTimezone() 보호된 메소드

If the date is absolute, ie. YYYY-MM-DD, it will not be converted to the timezone.
protected getDateParameterInTimezone ( string $date, string $timezone ) : Date
$date string `'today'`, `'yesterday'`, `'YYYY-MM-DD'`
$timezone string The timezone to use.
리턴 Piwik\Date

getDefaultAction() 공개 메소드

Returns the name of the default method that will be called when visiting: index.php?module=PluginName without the action parameter.
public getDefaultAction ( ) : string
리턴 string

getEnabledPeriodsInUI() 보호된 정적인 메소드

Returns values that are enabled for the parameter &period=
protected static getEnabledPeriodsInUI ( ) : array
리턴 array eg. array('day', 'week', 'month', 'year', 'range')

getGraphParamsModified() 보호된 메소드

For example: if you set range=last30 and date=2008-03-10, the date element of the returned array will be "2008-02-10,2008-03-10" Parameters you can set: - range: last30, previous10, etc. - date: YYYY-MM-DD, today, yesterday - period: day, week, month, year
protected getGraphParamsModified ( array $paramsToSet = [] ) : array
$paramsToSet array array( 'date' => 'last50', 'viewDataTable' =>'sparkline' )
리턴 array

getLastUnitGraph() 보호된 메소드

Returns a ViewDataTable object that will render a jqPlot evolution graph for the last30 days/weeks/etc. of the current period, relative to the current date.
protected getLastUnitGraph ( string $currentModuleName, string $currentControllerAction, string $apiMethod ) : ViewDataTable
$currentModuleName string The name of the current plugin.
$currentControllerAction string The name of the action that renders the desired report.
$apiMethod string The API method that the ViewDataTable will use to get graph data.
리턴 ViewDataTable

getLastUnitGraphAcrossPlugins() 보호된 메소드

Same as {@link getLastUnitGraph()}, but will set some properties of the ViewDataTable object based on the arguments supplied.
protected getLastUnitGraphAcrossPlugins ( string $currentModuleName, string $currentControllerAction, array $columnsToDisplay = false, array $selectableColumns = [], boolean | string $reportDocumentation = false, string $apiMethod = 'API.get' ) : ViewDataTable
$currentModuleName string The name of the current plugin.
$currentControllerAction string The name of the action that renders the desired report.
$columnsToDisplay array The value to use for the ViewDataTable's columns_to_display config property.
$selectableColumns array The value to use for the ViewDataTable's selectable_columns config property.
$reportDocumentation boolean | string The value to use for the ViewDataTable's documentation config property.
$apiMethod string The API method that the ViewDataTable will use to get graph data.
리턴 ViewDataTable

getNumericValue() 보호된 메소드

Works only for API methods that originally returns numeric values (there is no cast here)
protected getNumericValue ( string $methodToCall, boolean | string $date = false ) : integer | float
$methodToCall string Name of method to call, eg. Referrers.getNumberOfDistinctSearchEngines
$date boolean | string A custom date to use when getting the value. If false, the 'date' query parameter is used.
리턴 integer | float

getPrettyDate() 공개 정적인 메소드

Returns the pretty date representation
public static getPrettyDate ( $date, $period ) : string
$date string
$period string
리턴 string Pretty date

getUrlSparkline() 보호된 메소드

The result of this URL should be used with the sparkline() twig function. The current site ID and period will be used.
protected getUrlSparkline ( string $action, array $customParameters = [] ) : string
$action string Method name of the controller that serves the report.
$customParameters array The array of query parameter name/value pairs that should be set in result URL.
리턴 string The generated URL.

init() 보호된 메소드

protected init ( )

redirectToIndex() 공개 메소드

This function will exit immediately after executing.
public redirectToIndex ( string $moduleToRedirect, string $actionToRedirect, integer | null $websiteId = null, string | null $defaultPeriod = null, string | null $defaultDate = null, array $parameters = [] )
$moduleToRedirect string The plugin to redirect to, eg. `"MultiSites"`.
$actionToRedirect string Action, eg. `"index"`.
$websiteId integer | null The new idSite query parameter, eg, `1`.
$defaultPeriod string | null The new period query parameter, eg, `'day'`.
$defaultDate string | null The new date query parameter, eg, `'today'`.
$parameters array Other query parameters to append to the URL.

renderReport() 보호된 메소드

Convenience method that creates and renders a ViewDataTable for a API method.
protected renderReport ( string | Report $apiAction, boolean $controllerAction = false ) : string | void
$apiAction string | Report The name of the API action (eg, `'getResolution'`) or an instance of an report.
$controllerAction boolean The name of the Controller action name that is rendering the report. Defaults to the `$apiAction`.
리턴 string | void See `$fetch`.

renderTemplate() 보호된 메소드

Example: public function myControllerAction () { return $this->renderTemplate('index', array( 'answerToLife' => '42' )); } This will render the 'index.twig' file within the plugin templates folder and assign the view variable answerToLife to 42.
부터: 2.5.0
protected renderTemplate ( string $template, array $variables = [] ) : string
$template string The name of the template file. If only a name is given it will automatically use the template within the plugin folder. For instance 'myTemplate' will result in '@$pluginName/myTemplate.twig'. Alternatively you can include the full path: '@anyOtherFolder/otherTemplate'. The trailing '.twig' is not needed.
$variables array For instance array('myViewVar' => 'myValue'). In template you can use {{ myViewVar }}
리턴 string

renderView() 보호된 메소드

A helper method that renders a view either to the screen or to a string.
protected renderView ( Piwik\View\ViewInterface $view ) : string | void
$view Piwik\View\ViewInterface The view to render.
리턴 string | void

setBasicVariablesView() 보호된 메소드

The following variables assigned: **isSuperUser** - True if the current user is the Super User, false if otherwise. **hasSomeAdminAccess** - True if the current user has admin access to at least one site, false if otherwise. **isCustomLogo** - The value of the branding_use_custom_logo option. **logoHeader** - The header logo URL to use. **logoLarge** - The large logo URL to use. **logoSVG** - The SVG logo URL to use. **hasSVGLogo** - True if there is a SVG logo, false if otherwise. **enableFrames** - The value of the [General] enable_framed_pages INI config option. If true, {@link Piwik\View::setXFrameOptions()} is called on the view. Also calls {@link setHostValidationVariablesView()}.
protected setBasicVariablesView ( View $view )
$view Piwik\View

setDate() 보호된 메소드

If the date has to be modified, this method should be called just after construction.
protected setDate ( Date $date ) : void
$date Piwik\Date The new Date.
리턴 void

setGeneralVariablesView() 보호된 메소드

The following variables assigned: **date** - The value of the **date** query parameter. **idSite** - The value of the **idSite** query parameter. **rawDate** - The value of the **date** query parameter. **prettyDate** - A pretty string description of the current period. **siteName** - The current site's name. **siteMainUrl** - The URL of the current site. **startDate** - The start date of the current period. A {@link Piwik\Date} instance. **endDate** - The end date of the current period. A {@link Piwik\Date} instance. **language** - The current language's language code. **config_action_url_category_delimiter** - The value of the [General] action_url_category_delimiter INI config option. **topMenu** - The result of MenuTop::getInstance()->getMenu(). As well as the variables set by {@link setPeriodVariablesView()}. Will exit on error.
protected setGeneralVariablesView ( View $view ) : void
$view Piwik\View
리턴 void

setHostValidationVariablesView() 공개 정적인 메소드

- **isValidHost** - true if host is valid, false if otherwise - **invalidHostMessage** - message to display if host is invalid (only set if host is invalid) - **invalidHost** - the invalid hostname (only set if host is invalid) - **mailLinkStart** - the open tag of a link to email the Super User of this problem (only set if host is invalid)
public static setHostValidationVariablesView ( View $view )
$view Piwik\View

setMaxDateView() 보호된 메소드

Sets the last date available in the period selector's calendar. Usually this is just the "today" date for a site (which varies based on the timezone of a site).
protected setMaxDateView ( Date $maxDate, View $view )
$maxDate Piwik\Date The max date.
$view Piwik\View The view that contains the period selector.

setMinDateView() 보호된 메소드

Sets the first date available in the period selector's calendar.
protected setMinDateView ( Date $minDate, View $view )
$minDate Piwik\Date The min date.
$view Piwik\View The view that contains the period selector.

setPeriodVariablesView() 공개 정적인 메소드

- **displayUniqueVisitors** - Whether unique visitors should be displayed for the current period. - **period** - The value of the **period** query parameter. - **otherPeriods** - array('day', 'week', 'month', 'year', 'range') - **periodsNames** - List of available periods mapped to their singular and plural translations.
public static setPeriodVariablesView ( View $view )
$view Piwik\View

프로퍼티 상세

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

The Date object created with ($strDate)[#strDate] or null if the requested date is a range.
protected Date,Piwik|null $date
리턴 Piwik\Date | null

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

The value of the **idSite** query parameter.
protected int $idSite
리턴 integer

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

The plugin name, eg. 'Referrers'.
protected string $pluginName
리턴 string

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

The Site object created with {@link $idSite}.
protected Site,Piwik $site
리턴 Piwik\Site

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

The value of the **date** query parameter.
protected string $strDate
리턴 string