You are here

function track_da_files_roles in Track da files 8

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

This function returns TRUE if role should be tracked.

2 calls to track_da_files_roles()
TrackDaFilesController::tracking in src/Controller/TrackDaFilesController.php
TrackDaFilesController::tracking_private in src/Controller/TrackDaFilesController.php
1 string reference to 'track_da_files_roles'
track_da_files_config_form in includes/track_da_files.admin.inc
Settings form.

File

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

Code

function track_da_files_roles($user) {
  $track = \Drupal::config('track_da_files.settings')
    ->get('roles');
  $enabled = $track;
  $roles = \Drupal::config('track_da_files.settings')
    ->get('specific_roles');
  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;
}