context_condition_user.inc 796 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * Expose current user role as a context condition.
  4. */
  5. class context_condition_user extends context_condition {
  6. function condition_values() {
  7. $values = array();
  8. foreach (user_roles() as $rid => $role_name) {
  9. if ($rid == DRUPAL_ANONYMOUS_RID) {
  10. $values['anonymous user'] = check_plain($role_name);
  11. }
  12. elseif ($rid == DRUPAL_AUTHENTICATED_RID) {
  13. $values['authenticated user'] = check_plain($role_name);
  14. }
  15. else {
  16. $values[$role_name] = check_plain($role_name);
  17. }
  18. }
  19. return $values;
  20. }
  21. function execute($account) {
  22. $roles = $account->roles;
  23. foreach ($roles as $rid => $role) {
  24. foreach ($this->get_contexts($role) as $context) {
  25. $this->condition_met($context, $role);
  26. }
  27. }
  28. }
  29. }