? activity-539048.patch
Index: activity.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/activity/activity.install,v
retrieving revision 1.1.2.1.2.6.2.4
diff -u -p -r1.1.2.1.2.6.2.4 activity.install
--- activity.install	5 Mar 2009 04:38:11 -0000	1.1.2.1.2.6.2.4
+++ activity.install	8 Mar 2010 15:12:59 -0000
@@ -21,6 +21,11 @@ function activity_schema() {
         'not null' => TRUE,
         'default' => 0,
       ),
+      'gid' => array(
+        'type' => 'int',
+        'not null' => FALSE,
+        'default' => NULL,
+      ),
       'module' => array(
         'type' => 'varchar',
         'length' => 50,
Index: activity.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/activity/activity.module,v
retrieving revision 1.1.2.2.2.30.2.42
diff -u -p -r1.1.2.2.2.30.2.42 activity.module
--- activity.module	27 Apr 2009 01:45:25 -0000	1.1.2.2.2.30.2.42
+++ activity.module	8 Mar 2010 15:13:00 -0000
@@ -488,28 +488,49 @@ function activity_get_info() {
  *   This should be an identifier for the calling module to use.
  */
 function activity_insert($uid, $module, $type, $operation, $data, $target_users_roles) {
+
+  if (module_exists('og')) {
+    $n = og_get_group_context();
+    if ($n) {
+      $gid = $n->nid;
+    } else {
+    
+      if ($data['node-type'] == 'group') {
+        $gid = $data['node-id'];
+      } else {
+        $gid = 'NULL';
+      }
+    
+    }
+  } else {
+    $gid = 'NULL';
+  }
+
+  $gid = ($gid == 'NULL') ? 'NULL' : (int) $gid;
+
   // check time limit, ignore activity if within the limit
-  $result = db_query("SELECT COUNT(*) FROM {activity} WHERE uid = %d AND module = '%s' AND type = '%s' AND operation = '%s' AND data = '%s' AND created >= %d", $uid, $module, $type, $operation, serialize($data), (time() - variable_get('activity_time_limit', 30)));
+  $result = db_query("SELECT COUNT(*) FROM {activity} WHERE uid = %d AND module = '%s' AND type = '%s' AND operation = '%s' AND data = '%s' AND created >= %d AND gid = %s", $uid, $module, $type, $operation, serialize($data), (time() - variable_get('activity_time_limit', 30)), $gid);
   
   if (db_fetch_object($result)->count != 0) {
     return FALSE;
   }
 
-  db_query("INSERT INTO {activity} (uid, module,  type,  operation,  created, data)
-                            VALUES (%d,  '%s',    '%s',  '%s',       %d,      '%s')",
-                                   $uid, $module, $type, $operation, time(),  serialize($data));
+  db_query("INSERT INTO {activity} (uid, module,  type,  operation,  created, data,             gid)
+                            VALUES (%d,  '%s',    '%s',  '%s',       %d,      '%s',             %s)",
+                                   $uid, $module, $type, $operation, time(),  serialize($data), $gid);
   $aid = db_last_insert_id('activity', 'aid');
   foreach ($target_users_roles as $target_uid => $role) {
     db_query("INSERT INTO {activity_targets} (aid, target_uid, target_role) VALUES (%d, %d, '%s')", $aid, $target_uid, $role);
   }
 
   $activity = array(
-    'aid' 		=> $aid,
-    'uid' 		=> $uid,
-    'module' 	=> $module,
-    'type' 		=> $type,
+    'aid'     => $aid,
+    'uid'     => $uid,
+    'module'  => $module,
+    'type'    => $type,
     'operation' => $operation,
-    'data' 		=> $data,
+    'data'    => $data,
+    'gid'     => $gid,
     'target_user_roles' => $target_users_roles,
   );
 
@@ -697,12 +718,12 @@ function activity_get_activity($uids = A
   $activity = array();
   while ($row = db_fetch_array($result)) {
     $row['data'] = unserialize($row['data']);
-    $row['data']['aid'] 		= $row['aid'];
-    $row['data']['uid'] 		= $row['uid'];
-    $row['data']['module'] 		= $row['module'];
-    $row['data']['type'] 		= $row['type'];
-    $row['data']['operation'] 	= ($row['data']['operation'] ? $row['data']['operation'] : $row['operation']);
-    $row['data']['created'] 	= $row['created'];
+    $row['data']['aid']     = $row['aid'];
+    $row['data']['uid']     = $row['uid'];
+    $row['data']['module']    = $row['module'];
+    $row['data']['type']    = $row['type'];
+    $row['data']['operation']   = ($row['data']['operation'] ? $row['data']['operation'] : $row['operation']);
+    $row['data']['created']   = $row['created'];
 
     // Load Activity comments if user can view comments
     // Use a permissions check here to save comment loading if user cannot view
@@ -752,13 +773,17 @@ function activity_invoke_activityapi(&$a
 }
 
 function activity_get_tablesort_headers() {
-  return array(
+  $a = array(
     'activity_targets.aid' => array('field' => 'activity_targets.aid', 'data' => t('Id')),
     'activity.module' => array('field' => 'activity.module', 'data' => t('Module')),
     'activity.type' => array('field' => 'activity.type', 'data' => t('Type')),
     'activity.operation' => array('field' => 'activity.operation', 'data' => t('Operation')),
     'activity.created' => array('field' => 'activity.created', 'data' => t('Created')),
   );
+  if (module_exists('og')) {
+    $a['activity.gid'] = array('field' => 'activity.gid', 'data' => t('Group Id'));
+  }
+  return $a;
 }
 
 /**
@@ -772,6 +797,10 @@ function activity_block($op = 'list', $d
       $block['my']['info'] = t("Activity (Mine): show the current user's activity.");
       $block['all']['info'] = t("Activity (All): show all recent activity");
       $block['user']['info'] = t("Activity (User): show activity of the user being viewed");
+      if (module_exists('og')) {
+        $block['group']['info'] = t("Activity (Group): show activity of the current group");
+        $block['groupdetail']['info'] = t("Activity (Group) Detailed: show detailed activity of the current group");
+      }
       return $block;
       break;
 
@@ -861,6 +890,51 @@ function activity_block($op = 'list', $d
               }
             }
             break;
+            
+          case 'group':
+            if (module_exists('og')) {
+              if (user_access('view public activity')) {
+                $g = og_get_group_context();
+                $activity =  activity_get_activity(ACTIVITY_ALL, array('gid' => array('include',$g->nid)), variable_get('activity_block_'. $delta, 5) + 1);
+                if ($count = count($activity)) {
+                  drupal_add_css(drupal_get_path('module', 'activity') .'/activity.css');
+                  if ($count > variable_get('activity_block_'. $delta, 5)) {
+                    $more_link = theme('activity_more_link', 'activity');
+                    array_pop($activity);
+                  }
+                  $activities = array();
+                  foreach ($activity as $item) {
+                    $item['delete-link'] = activity_delete_link($item);
+                    $activities[] = theme('activity', activity_token_replace($item), $item);
+                  }
+                  return array(
+                    'subject' => t('Group activity'),
+                    'content' => theme('activity_block', $activities, $more_link)
+                  );
+                }
+              }
+            }
+            break;
+            
+          case 'groupdetail':
+            if (module_exists('og')) {
+              if (user_access('view public activity')) {
+                $g = og_get_group_context();
+                $activities =  activity_get_activity(ACTIVITY_ALL, array('gid' => array('include',$g->nid)), variable_get('activity_block_'. $delta, 5) + 1);
+                if ($count = count($activities)) {
+                  drupal_add_css(drupal_get_path('module', 'activity') .'/activity.css');
+
+                  $table = theme('activity_table', $activities);
+
+                  return array(
+                    'subject' => t('Group activity'),
+                    'content' => theme('activity_page', $activities, $table)
+                  );
+                }
+              }
+            }
+            break;
+            
       }
       break;
   }
@@ -986,16 +1060,16 @@ function activity_token_list($type = 'al
   if ($type == 'activity') {
     $tokens = array('activity' => array());
     $tokens['activity'] = array(
-      'author-uid' 		=> t('User Id of the person who initiated the activity'),
-      'author' 			=> t('Themed username of the person who initiated the activity (used for "author" role)'),
-      'author-all' 		=> t('Themed username of the person who initiated the activity (used for "all" role)'),
-      'author-name' 	=> t('Plain text username of the person who initiated the activity'),
-      'author-picture' 	=> t('The user picture of the person who initiated the activity'),
-      'operation' 		=> t('The verb of the operation that took place, eg. "create", "update", "delete"'),
-      'time-small' 		=> t('Date and time in small format: @example', array('@example' => format_date(time(), 'small'))),
-      'time-medium' 	=> t('Date and time in medium format: @example', array('@example' => format_date(time(), 'medium'))),
-      'time-large' 		=> t('Date and time in large format: @example', array('@example' => format_date(time(), 'large'))),
-      'time-ago' 		=> t('How long ago did this happen? Example: %time-ago', array('%time-ago' => format_interval(time() - 60 * 60 * 36))),
+      'author-uid'    => t('User Id of the person who initiated the activity'),
+      'author'      => t('Themed username of the person who initiated the activity (used for "author" role)'),
+      'author-all'    => t('Themed username of the person who initiated the activity (used for "all" role)'),
+      'author-name'   => t('Plain text username of the person who initiated the activity'),
+      'author-picture'  => t('The user picture of the person who initiated the activity'),
+      'operation'     => t('The verb of the operation that took place, eg. "create", "update", "delete"'),
+      'time-small'    => t('Date and time in small format: @example', array('@example' => format_date(time(), 'small'))),
+      'time-medium'   => t('Date and time in medium format: @example', array('@example' => format_date(time(), 'medium'))),
+      'time-large'    => t('Date and time in large format: @example', array('@example' => format_date(time(), 'large'))),
+      'time-ago'    => t('How long ago did this happen? Example: %time-ago', array('%time-ago' => format_interval(time() - 60 * 60 * 36))),
     );
     return $tokens;
   }
@@ -1008,15 +1082,15 @@ function activity_token_values($type, $d
   if ($type == 'activity' && !empty($data)) {
     $author = activity_user_load($data['uid']);
     $tokens = array(
-      'author' 			=> theme('activity_username', $author, TRUE),
-      'author-all' 		=> theme('activity_username', $author),
-      'author-name' 	=> $author->name,
+      'author'      => theme('activity_username', $author, TRUE),
+      'author-all'    => theme('activity_username', $author),
+      'author-name'   => $author->name,
       'author-picture'  => theme('activity_user_picture', $author),
-      'operation' 		=> $data['operation'],
-      'time-small' 		=> format_date($data['created'], 'small'),
-      'time-medium' 	=> format_date($data['created'], 'medium'),
-      'time-large' 		=> format_date($data['created'], 'large'),
-      'time-ago' 		=> format_interval(time() - $data['created']),
+      'operation'     => $data['operation'],
+      'time-small'    => format_date($data['created'], 'small'),
+      'time-medium'   => format_date($data['created'], 'medium'),
+      'time-large'    => format_date($data['created'], 'large'),
+      'time-ago'    => format_interval(time() - $data['created']),
     );
     return $tokens;
   }
