You are here

function track_da_files_roles in Track da files 7

Same name and namespace in other branches
  1. 8 track_da_files.module \track_da_files_roles()

This function returns TRUE if role should be tracked.

2 calls to track_da_files_roles()
track_da_files_file_download_access_alter in ./track_da_files.module
Implements hook_file_download_access_alter().
track_da_files_tracking in ./track_da_files.module
Analyses uri of file, updates counter and redirects user to file url.
2 string references to 'track_da_files_roles'
track_da_files_config_form in includes/track_da_files.admin.inc
Settings form.
track_da_files_uninstall in ./track_da_files.install
Implements hook_uninstall().

File

./track_da_files.module, line 103
This file contains Track da files main functions.

Code

function track_da_files_roles($user) {
  $track = variable_get('track_da_files_roles', 0);
  $enabled = $track;
  $roles = variable_get('track_da_files_specific_roles', array());
  if (array_sum($roles) > 0) {

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

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

        // User has a role that should be tracked/excluded from tracking.
        $enabled = !$track;
        break;
      }
    }
  }
  else {

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