You are here

function olark_check_role_access in Olark Chat 6

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

Method which checks whether or not current user contains a role which would restrict display of Olark Chat

Return value

Bool TRUE if user can view Olark Chat. FALSE if user is prevented from seeing Olark Chat

2 calls to olark_check_role_access()
olark_footer in ./olark.module
Implements hook_footer().
olark_init in ./olark.module
Implements hook_init().

File

./olark.module, line 28
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)) {

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

  //return the result
  return $display_olark_chat;
}