You are here

function _piwik_visibility_roles in Piwik Web Analytics 7

Same name and namespace in other branches
  1. 8 piwik.module \_piwik_visibility_roles()
  2. 5 piwik.module \_piwik_visibility_roles()
  3. 6.2 piwik.module \_piwik_visibility_roles()
  4. 6 piwik.module \_piwik_visibility_roles()
  5. 7.2 piwik.module \_piwik_visibility_roles()

Based on visibility setting this function returns TRUE if GA code should be added for the current role and otherwise FALSE.

2 calls to _piwik_visibility_roles()
piwik_form_user_profile_form_alter in ./piwik.module
Implement hook_form_FORM_ID_alter().
_piwik_visibility_user in ./piwik.module
Tracking visibility check for an user object.

File

./piwik.module, line 351
Drupal Module: Piwik Adds the required Javascript to the bottom of all your Drupal pages to allow tracking by the Piwik statistics package.

Code

function _piwik_visibility_roles($account) {
  $enabled = FALSE;
  $roles = variable_get('piwik_roles', array());
  if (array_sum($roles) > 0) {

    // One or more roles are selected for tracking.
    foreach (array_keys($account->roles) as $rid) {

      // Is the current user a member of one role enabled for tracking?
      if (isset($roles[$rid]) && $rid == $roles[$rid]) {

        // Current user is a member of a role that should be tracked.
        $enabled = TRUE;
        break;
      }
    }
  }
  else {

    // No role is selected for tracking, therefor all roles should be tracked.
    $enabled = TRUE;
  }
  return $enabled;
}