You are here

function olark_check_role_access in Olark Chat 7

Same name and namespace in other branches
  1. 6 olark.module \olark_check_role_access()

Does current user have a role which would restrict display of Olark Chat.

Return value

bool Whether or not the user is prevented from seeing Olark Chat.

1 call to olark_check_role_access()
olark_page_alter in ./olark.module
Implements hook_page_alter().

File

./olark.module, line 94
Integrates Olark Chat in a Drupal site.

Code

function olark_check_role_access() {

  // Check to see if current user has access to view Olark Chat.
  global $user;

  // Create a bool with value set to TRUE for if statement down below on whether
  // to display Olark Chat.
  $display_olark_chat = TRUE;

  // Obtain the list from the settings page, and call array_unique to remove
  // duplicate 0's, and obtain only the array_values.
  $olark_ignore_user_roles = array_unique(variable_get('olark_ignore_user_roles', array()));
  if (count($olark_ignore_user_roles) > 0) {
    $olark_ignore_user_roles = array_flip($olark_ignore_user_roles);

    // Check to see if key 0 is set, which is not a rid, but a result of
    // array_unique.
    if (isset($olark_ignore_user_roles[0])) {

      // Unset the key to reduce load on foreach.
      unset($olark_ignore_user_roles[0]);
    }

    // Check to make sure that there is at least one rid that should be ignored
    // to save resources. Access all of the user roles to see if one of their
    // roles in is in the disallowed list.
    foreach ($user->roles as $rid => $role) {
      if (in_array($rid, $olark_ignore_user_roles)) {

        // An rid that should ignore Olark Chat has been found. Setting bool to
        // FALSE and breaking out.
        $display_olark_chat = FALSE;
        break;
      }
    }
  }
  return $display_olark_chat;
}