Piwik\

Piwik

Main piwik helper class.

Contains helper methods for a variety of common tasks. Plugin developers are encouraged to reuse these methods as much as possible.

Methods

The class defines the following methods:

getCurrentUserEmail()

Returns the current user's email address.

Signature

  • It returns a string value.

getCurrentUserLastSeen()

Returns the current user's Last Seen.

Signature

  • It returns a string value.

getCurrentUserLogin()

Returns the current user's username.

Signature

  • It returns a string value.

getCurrentUserTokenAuth()

Returns the current user's token auth.

Signature

  • It returns a string value.

hasUserSuperUserAccessOrIsTheUser()

Returns true if the current user is either the Super User or the user specified by $theUser.

Signature

  • It accepts the following parameter(s):
    • $theUser (string) — A username.
  • It returns a bool value.

checkUserHasSuperUserAccessOrIsTheUser()

Check that the current user is either the specified user or the superuser.

Signature

  • It accepts the following parameter(s):
    • $theUser (string) — A username.
  • It does not return anything or a mixed result.
  • It throws one of the following exceptions:

hasTheUserSuperUserAccess()

Check whether the given user has superuser access.

Signature

  • It accepts the following parameter(s):
    • $theUser (string) — A username.
  • It returns a bool value.

hasUserSuperUserAccess()

Returns true if the current user has Super User access.

Signature

  • It returns a bool value.

isUserIsAnonymous()

Returns true if the current user is the special anonymous user or not.

Signature

  • It returns a bool value.

checkUserIsNotAnonymous()

Checks that the user is not the anonymous user.

Signature

  • It does not return anything or a mixed result.
  • It throws one of the following exceptions:

checkUserHasSuperUserAccess()

Check that the current user has superuser access.

Signature

  • It does not return anything or a mixed result.
  • It throws one of the following exceptions:
    • Exception — if the current user is not the superuser.

isUserHasAdminAccess()

Returns true if the user has admin access to the requested sites, false if otherwise.

Signature

  • It accepts the following parameter(s):
    • $idSites (int|array) — The list of site IDs to check access for.
  • It returns a bool value.

checkUserHasAdminAccess()

Checks that the current user has admin access to the requested list of sites.

Signature

  • It accepts the following parameter(s):
    • $idSites (int|array) — One or more site IDs to check access for.
  • It does not return anything or a mixed result.
  • It throws one of the following exceptions:
    • Exception — If user doesn't have admin access.

isUserHasSomeAdminAccess()

Returns true if the current user has admin access to at least one site.

Signature

  • It returns a bool value.

checkUserHasSomeWriteAccess()

Checks that the current user has write access to at least one site.

Signature

  • It does not return anything or a mixed result.
  • It throws one of the following exceptions:
    • Exception — if user doesn't have write access to any site.

isUserHasSomeWriteAccess()

Returns true if the current user has write access to at least one site.

Signature

  • It returns a bool value.

isUserHasCapability()

Returns true if the current user has the given capability for the given sites.

Signature

  • It accepts the following parameter(s):

    • $idSites

    • $capability

  • It returns a bool value.

checkUserHasSomeAdminAccess()

Checks that the current user has admin access to at least one site.

Signature

  • It does not return anything or a mixed result.
  • It throws one of the following exceptions:
    • Exception — if user doesn't have admin access to any site.

isUserHasViewAccess()

Returns true if the user has view access to the requested list of sites.

Signature

  • It accepts the following parameter(s):
    • $idSites (int|array) — One or more site IDs to check access for.
  • It returns a bool value.

isUserHasWriteAccess()

Returns true if the user has write access to the requested list of sites.

Signature

  • It accepts the following parameter(s):
    • $idSites (int|array) — One or more site IDs to check access for.
  • It returns a bool value.

checkUserHasViewAccess()

Checks that the current user has view access to the requested list of sites

Signature

  • It accepts the following parameter(s):
    • $idSites (int|array) — The list of site IDs to check access for.
  • It does not return anything or a mixed result.
  • It throws one of the following exceptions:
    • Exception — if the current user does not have view access to every site in the list.

checkUserHasWriteAccess()

Checks that the current user has write access to the requested list of sites

Signature

  • It accepts the following parameter(s):
    • $idSites (int|array) — The list of site IDs to check access for.
  • It does not return anything or a mixed result.
  • It throws one of the following exceptions:
    • Exception — if the current user does not have write access to every site in the list.

isUserHasSomeViewAccess()

Returns true if the current user has view access to at least one site.

Signature

  • It returns a bool value.

checkUserHasSomeViewAccess()

Checks that the current user has view access to at least one site.

Signature

  • It does not return anything or a mixed result.
  • It throws one of the following exceptions:
    • Exception — if user doesn't have view access to any site.

getLoginPluginName()

Returns the name of the Login plugin currently being used.

Must be used since it is not allowed to hardcode 'Login' in URLs in case another Login plugin is being used.

Signature

  • It returns a string value.

redirectToModule()

Redirects the current request to a new module and action.

Signature

  • It accepts the following parameter(s):
    • $newModule (string) — The target module, eg, 'UserCountry'.
    • $newAction (string) — The target controller action, eg, 'index'.
    • $parameters (array) — The query parameter values to modify before redirecting.
  • It does not return anything or a mixed result.

isValidEmailString()

Returns true if supplied the email address is a valid.

Signature

  • It accepts the following parameter(s):

    • $emailAddress (string) —
  • It returns a bool value.

postEvent()

Post an event to Matomo's event dispatcher which will execute the event's observers.

Signature

  • It accepts the following parameter(s):
    • $eventName (string) — The event name.
    • $params (array) — The parameter array to forward to observer callbacks.
    • $pending (bool) — If true, plugins that are loaded after this event is fired will have their observers for this event executed.
    • $plugins (array|null) — The list of plugins to execute observers for. If null, all plugin observers will be executed.
  • It does not return anything or a mixed result.

addAction()

Register an observer to an event.

Note: Observers should normally be defined in plugin objects. It is unlikely that you will need to use this function.

Signature

  • It accepts the following parameter(s):
    • $eventName (string) — The event name.
    • $function (callable|array) — The observer.
  • It does not return anything or a mixed result.

translate()

Returns an internationalized string using a translation token. If a translation cannot be found for the token, the token is returned.

Signature

  • It accepts the following parameter(s):

    • $translationId (string) — Translation ID, eg, 'General_Date'.
    • $args (array|string|int) — sprintf arguments to be applied to the internationalized string.
    • $language (string|null) — Optionally force the language.
  • Returns: string — The translated string or $translationId.

getPeriod()

Returns the period provided in the current request.

If no $default is provided, this method will throw an Exception if period can't be found in the request

Signature

  • It accepts the following parameter(s):
    • $default (string|null) — default value to use
  • It returns a string value.
  • It throws one of the following exceptions:

getDate()

Returns the date provided in the current request.

If no $default is provided, this method will throw an Exception if date can't be found in the request

Signature

  • It accepts the following parameter(s):
    • $default (string|null) — default value to use
  • It returns a string value.
  • It throws one of the following exceptions: