You are here

function og_role_watchdog_og in Role Watchdog 6

Same name and namespace in other branches
  1. 6.2 modules/og_role_watchdog/og_role_watchdog.module \og_role_watchdog_og()

Implementation of hook_og

File

modules/og_role_watchdog/og_role_watchdog.module, line 134
Logs changes to user roles.

Code

function og_role_watchdog_og($op, $nid, $uid, $args = array()) {
  $account = user_load($uid);
  switch ($op) {
    case 'user insert':

      // If a default role is configured, log that it was granted to the user.
      if ($default_role = og_user_roles_get_group_default_role($nid)) {
        if (array_key_exists('is_active', $args) && $args['is_active'] == 0) {
          _og_role_watchdog_request_role($default_role, $account, $nid);
        }
        else {
          _og_role_watchdog_process_role_changes($account, array(
            $default_role,
          ), array(), $nid);
        }
      }
      break;
    case 'user approve':
      if ($default_role = og_user_roles_get_group_default_role($nid)) {
        _og_role_watchdog_approve_role($default_role, $account, $nid);
      }
      break;
    case 'user delete':

      // og_user_roles_og() has already run, so we no longer know which roles in that
      // group the user formerly had. An auditor can search down in the role history
      // to find out, if necessary.
      if ($default_role = og_user_roles_get_group_default_role($nid)) {
        _og_role_watchdog_process_role_changes($account, array(), array(
          $default_role,
        ), $nid);
      }
      break;
    case 'admin new':
      $default_admin_role = variable_get('og_user_roles_default_admin_role', 0);
      $default_role = og_user_roles_get_group_default_role($nid);
      if ($default_admin_role > 0 && $default_admin_role != $default_role) {
        _og_role_watchdog_process_role_changes($account, array(
          $default_admin_role,
        ), array(), $nid);
      }
      break;
    case 'admin remove':
      $default_admin_role = variable_get('og_user_roles_default_admin_role', 0);
      $default_role = og_user_roles_get_group_default_role($nid);
      if ($default_admin_role > 0 && $default_admin_role != $default_role) {
        _og_role_watchdog_process_role_changes($account, array(), array(
          $default_admin_role,
        ), $nid);
      }
      break;
  }
}