You are here

function ogactivity_og in Activity 6

Same name and namespace in other branches
  1. 5.4 contrib/ogactivity/ogactivity.module \ogactivity_og()

Implementation of hook_og().

File

contrib/ogactivity/ogactivity.module, line 76

Code

function ogactivity_og($op, $gid, $uid, $args) {
  switch ($op) {
    case 'user insert':
    case 'user delete':

      // If the group join action requires approval then the is_active
      // arg will be 0 so in this case we bail out.
      if (array_key_exists('is_active', $args) && $args['is_active'] == 0) {
        return FALSE;
      }
      $node = node_load($gid);
      $type = 'ogaction';
      $op = $op == 'user delete' ? 'leave' : 'join';

      // Check if both type and operation are
      // enabled for activity. If not then stop here
      if (!in_array($type, variable_get('ogactivity_token_types', array(
        $type,
      )), TRUE) || !in_array($op, variable_get('ogactivity_op_types', array(
        $op,
      )), TRUE)) {
        return FALSE;
      }

      // Privacy setting check
      $user = user_load(array(
        'uid' => $uid,
      ));
      if (activity_user_privacy_optout($user)) {
        return FALSE;
      }

      // User hide activity permission check
      if (user_access('hide activity', $user)) {
        return FALSE;
      }
      $data = array(
        'operation' => $op,
        'node-id' => $node->nid,
        'node-title' => $node->title,
        'node-type' => $node->type,
      );
      $target_users_roles = array(
        ACTIVITY_ALL => 'all',
        $user->uid => 'author',
      );
      activity_insert($user->uid, 'ogactivity', $type, $op, $data, $target_users_roles);
      break;
  }
}