ogactivity does not track join events for groups requiring admin approval

matteusx - August 5, 2009 - 16:25
Project:Activity
Version:6.x-1.2
Component:Activity Contrib
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Here's a modified version of ogactivity_og that properly handles the 'user approve' operation:

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

     
// 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';
     
      switch (
$op) {
        case
'user insert':
        case
'user approve':
         
$op = 'join';
          break;
        case
'user delete':
         
$op = 'leave';
          break;
      }

     
// 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;
  }
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.