You are here

function context_condition_user::execute in Context 7.3

Same name and namespace in other branches
  1. 6.3 plugins/context_condition_user.inc \context_condition_user::execute()
  2. 6 plugins/context_condition_user.inc \context_condition_user::execute()

File

plugins/context_condition_user.inc, line 35

Class

context_condition_user
Expose current user role as a context condition.

Code

function execute($account) {
  $all_roles = user_roles();
  $users_roles = $account->roles;
  foreach ($all_roles as $rid => $role) {
    foreach ($this
      ->get_contexts($role) as $context) {
      $options = $this
        ->fetch_from_context($context, 'options');
      if (empty($options['negate_role'])) {
        if (in_array($role, $users_roles)) {
          $this
            ->condition_met($context, $role);
        }
      }
      else {
        $negate_flag = TRUE;
        foreach ($this
          ->fetch_from_context($context, 'values') as $nid => $negated_role) {
          if (!in_array($negated_role, $users_roles)) {
            $negate_flag &= TRUE;
          }
          else {
            $negate_flag &= FALSE;
          }
        }
        if ($negate_flag) {
          $this
            ->condition_met($context, $role);
        }
      }
    }
  }
}