This should allow us to filter activity by group, showing you any activity in the groups that you belong to OR specify in an argument.

OG is the group solution of choice, so we need a views filter for this.

Views filters are now created automagically by any module who implements our hook_activity_access_grants() (@see DEVELOPER.txt for more information). So, let's come up with a patch against the latest OG implementation and submit it to them after we get it worked out here.

Comments

sirkitree’s picture

Title: Additional filter » Additional views filter
sirkitree’s picture

Title: Additional views filter » Additional views filter for OG
moshe weitzman’s picture

I'd love to support activity. I'll take a look at any patches that arise here.

Jackinloadup’s picture

Im digging through the module at the moment working on this feature. I will post any headway I make.

likewhoa’s picture

subscribing.

tdombos’s picture

Isn't it very easy with Views? You simply define a relationship between activity and organic groups tables.

Something like this:

function YOURMODULE_views_data_alter(&$data) {
  $data['activity']['nid'] = array(
    'group' => t('Organic groups'),
    'title' => t('OG to activities'),
    'help' => t('Attach Organic Group to activities.'),
    'relationship' => array(
      'handler' => 'views_handler_relationship',
      'base' => 'og_ancestry',
      'field' => 'group_nid',
      'label' => t('OG to activities'),
    ),
  );
}
Scott Reynolds’s picture

But what if you want to display group activity on user/14/activity. something like

  • Sally posted "Come party with us at my place" in "Cool Party Group"
  • Julie joined "Cool Party Group"

There is a whole access implementation to facilitate this. Lot more then building a relationship.

Read the Developers.txt and related discussion: http://groups.drupal.org/node/21033

The api has changed since then, but there is a good discussion on the motivations for the system.

igorik’s picture

subscribe

izmeez’s picture

subscribe

JerryH’s picture

Would this be adding a filter to a view that allows you to show content types for that og ?

I have a situation now where I'm trying to just list content types for a og, and I have "Organic groups: OG: Posts in current group = " though I can't add TRUE to the end of that.

Is this additional view what I'm talking about and need ?

sirkitree’s picture

@JerryH: that sounds correct. However OG will still have to know if an activity is within a group

@Scott Reynolds: can we share here what we have for community.module as to how it handles this and then maybe someone can work on an og implementation?

JerryH’s picture

StatusFileSize
new68.94 KB

In my case all the content types are create inside a group (as I understand how OG works).

Were this SQL-ish I'd use "SELECT content_type FROM moo WHERE type=(the types I want) AND group_id=(the group context were in)";

Though I'm learning views & groups atm so thinking there might be another way of doing it as I've just watched webchick do something like it with the 48 hour basecamp build here : http://www.doitwithdrupal.com/free-videos

The highlighted bit is from a D5 og& views build that I'm trying to replicated (it's a site rebuild into D6).

JerryH’s picture

Well so far I've found these :

http://drupal.org/node/66145

http://groups.drupal.org/node/13428

http://drupal.org/node/213448

And it looks like this would do what I want, though it's not for D6 is seems :(

http://groups.drupal.org/node/10445

JerryH’s picture

Have part hacked this in for now, storing the last group viewed in the session.

Then have added a filter "OG Post in current group"

dugh’s picture

subscribe

ngstigator’s picture

subscribe

dayre’s picture

subscribe

lelizondo’s picture

subscribe

Scott Reynolds’s picture

Title: Additional views filter for OG » Activity Integration with OG
Project: Activity » Organic Groups
Component: User interface » og.module
Assigned: sirkitree » Scott Reynolds
Category: task » feature
Status: Active » Needs review
Issue tags: +activity2-integration
StatusFileSize
new4.28 KB

Here is the patch against 6-2

It exposes all hook_og() $ops to Triggers (and therefore Activity).

It then implements Activity's Access API to create an og_membership access role. Therefore, in your Activity streams you can add in any and all OG group activity using the Activity Access filter.

gábor hojtsy’s picture

I've never written activity integration for a module before, but will soon start due to localize.drupal.org needing such functionality (see #599322: Add activity 2.x integration). This OG integration patch is of big help to our efforts. On localize.drupal.org, most of the action happens outside of areas users could track on a Drupal site. People join and leave groups, new people become admins, others import .po files or submit massive amounts of translations. Because these are "invisible" to the members of the site, the sense of progress does not form.

We are in the process of implementing, testing and rolling out activity integration on localize.drupal.org to help with this, and the basic OG activities would be among the first steps for that.

amitaibu’s picture

Status: Needs review » Needs work

Thanks Scott! From going visually over code:

+  $info->objects = array('group creator' => 'node', 'actor' => 'user');

Why do we call it group creator and not group? also insted of actor, how about "acting user" (like Rules)?

+  $info->eid_field = NULL;

Can you add in the comment what the eid field is.

+  $info->realms = array('og_member' => 'Organic Group');

If the realm is the member lets have the value be Organic groups member. Also, only first letter should be capital (Please change it also in the @file)

+    $groups_result = og_get_node_groups_result($activity->nid);

Although it will require node_lod(), I think it's more apropriate to use og_get_node_groups().

+  // $account is granted access to all activities within the groups $account

$account should be Account.

Scott Reynolds’s picture

Status: Needs work » Needs review
StatusFileSize
new5.29 KB

Ok here is an updated version.

Why do we call it group creator and not group? also inste[a]d of actor, how about "acting user" (like Rules)?

Sorry about that, I forgot about this feature I wanted to add. Basically for all the OG activities, I want the group admins to have their own messages. So when someone approves a member perhaps the group admin messages has a link to the application where normal members do not. (Sorry I actually don't use OG for anything so not sure that is actually a use case). At the most basic level it can say "User X joined your group Y you can remove them here: Z" and normal users would see "User X joined group Y".

In order for this feature to work, Activity has to be updated to the latest with these commits (http://drupal.org/cvs?commit=323158, http://drupal.org/cvs?commit=323170)

The rest of your comments should be addressed in this patch.

And the change to og_get_node_groups($node) is because it should ALWAYS return an array, even if its empty.

joeytheman’s picture

I cannot get this filter to work. Can you please export a view with the Og Access Filter configured correctly?

Thanks

Scott Reynolds’s picture

I use Views3 for my contrib work (and production work actually) so the export won't work in Views2 because Views3 has a very compact export. But here is a couple of screen shots.

You turn the filter on by choosing this: http://skitch.com/supermanscott/nuki5/og

if it doesn't work, you can rebuild the access table: http://skitch.com/supermanscott/nukse/access-rebuild

joeytheman’s picture

I don't have the "Og access control" option or have "OG" option listed under realms either. The "Available Updates" page confirmed I have the latest version of the module released today. Any suggestions?

Scott Reynolds’s picture

Im betting your og.activity.inc isn't in og/includes but in og/

amitaibu’s picture

@Scott Reynolds,

I tried to set-up acitivity (6-2.X-dev version), but it didn't work. I have added actions, but I see that $aids = _trigger_get_hook_aids('og', $op); returns an empty array. What is missing?

Also few more minor issues:

+++ og.module	2 Feb 2010 03:05:29 -0000
@@ -2361,3 +2380,71 @@ function og_check_token($token, $seed) {
+  $info->name = 'og';

Can we change it to "organic groups", so it won't appear as Og in the activity type.

+++ includes/og.activity.inc	2 Feb 2010 03:05:29 -0000
@@ -0,0 +1,66 @@
+    $groups = array_keys(og_get_node_groups(node_load($activity->nid)));

I think more readable to have

$group = node_load($activity->nid);
$groups = array_keys(og_get_node_groups($group));
+++ includes/og.activity.inc	2 Feb 2010 03:05:29 -0000
@@ -0,0 +1,66 @@
+    // for every group admin, add the message per language.

First letter should be capital.

Powered by Dreditor.

gábor hojtsy’s picture

@joeytheman: maybe you'll need to check the box to record og activity realm data on admin/settings/activity.

Scott Reynolds’s picture

So I haven't rerolled it with those minor changes. Don't have time this morning got a late start.

But instructions for how to test.

Assuming patch is applied and og.activity.inc is in the og/includes folder
1.) Goto admin/build/activity and create a template for Og
2.) Do the action that should fire the activity message
3.) check the activity stream (activity/all)
4.) create a node insert template at admin/build/activity
5.) Create a post in the newly created group
6.) create a comment template and add a comment to that node
7.) edit the activity/all view and add a filter Activity Access: Og's module's access control
8.) add an argument Node: nid and use the node relationship. This argument will serve as the groups nid.
9.) Enter the groups nid into the Arguments for the preview and you should see all the activities that happened in that group

The access filter works as the following.

Allow the following modules with the following realms to insert activity into the stream.

So this allows you to create a user stream as well by the following
1.) create a new Activity View.
2.) Add the user relationship
3.) Add the user name field using that relationship
4.) add the activity message field
5.) Add Filters Activity Access: Activity module's access control. This will put the users activity into the stream.
6.) Add node module's access control. This will put all activities around Nodes that the user creates into the stream.
7.) add comment module's access control. This will put all activites around Nodes that the user Comments on into the stream.

That View will show the current user all those Activities.

Now for the cooler View :-D.
8.) Add argument Activity: Activity Actor. This argument will take the Uid and use that as the basis for all those filters. Essentially, think of it as setting the context for those filters.

So as user 1, if i were to use as this argument with value of 2, I would see
a.) all user 2's activity
b.) all activity around the nodes user 2 created (say user 3 commented on one of his nodes).
c.) all activity around nodes user 2 commented on (say user 2 commented on a node created by user 3. Then user 3 replied to that comment)

Then by adding the Activity Access: Og module's access control, you can see all activities in groups user 2 is a member of.

Its important to note that Activity DOES respect node access control through db_rewrite_sql(). So do not add the Views Filter. #694162: Remove node_access filter from default View

Please note you must use the admin/build/activity, as noted here: #635264: Add back in activity_record_form ?. Sorry for that but we needed more information then what the standard actions workflow allowed. It is on the roadmap to be fixed prior to release so that if you enter from the standard actions section things wont be borked.

I hope all that is clear, Activity is severely lacking documentation and sorry for that.

likewhoa’s picture

#22 applies properly but I am not getting any activity on group "joins or user subscription changes". I have setup the views properly and here is an export of it.

$view = new view;
$view->name = 'Activity';
$view->description = 'Activity module views';
$view->tag = 'activity';
$view->view_php = '';
$view->base_table = 'activity';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Activity: Message */
$handler->display->display_options['fields']['message']['id'] = 'message';
$handler->display->display_options['fields']['message']['table'] = 'activity_messages';
$handler->display->display_options['fields']['message']['field'] = 'message';
$handler->display->display_options['fields']['message']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['message']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['message']['alter']['trim'] = 0;
$handler->display->display_options['fields']['message']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['message']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['message']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['message']['alter']['html'] = 0;
$handler->display->display_options['fields']['message']['hide_empty'] = 0;
$handler->display->display_options['fields']['message']['empty_zero'] = 0;
/* Sort criterion: Activity: Activity Creation Date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'activity';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter: Activity Access: Og module's access control */
$handler->display->display_options['filters']['value_og']['id'] = 'value_og';
$handler->display->display_options['filters']['value_og']['table'] = 'activity_access';
$handler->display->display_options['filters']['value_og']['field'] = 'value_og';

The only activity being shown on that view is ALL activity minus og activity which i triggered by joining a group & removing myself from a group. The activity templates are setup properly btw.

edit: just as a side note, I am getting

warning: Invalid argument supplied for foreach() in activity/views/activity_views_handler_filter_access.inc on line 64.

when enabling the og_module's access control filter.

Scott Reynolds’s picture

that would mean you don't have the og.activity.inc in the right spot. move it to og/includes

likewhoa’s picture

it's in the right spot and here is the content from it to verify.

modules # cat og/includes/og.activity.inc
<?php
// $Id: $

/**
 * @file:
 * Provides Activity module hooks for Organic groups.
 */

/**
 * Implementation of hook_activity_grants().
 */
function og_activity_grants($activity) {
  $groups = array();
  $grants = array();

  if ($activity->type == 'og') {
    $groups = array($activity->nid);
  }
  elseif (!empty($activity->nid)) {
    // Find all the groups the node belongs to.
    $groups = array_keys(og_get_node_groups(node_load($activity->nid)));
  }

  if (!empty($groups)) {
    $grants = array(
      'og_member' => $groups,
    );
  }

  return $grants;
}

/**
 * Implementation of hook_activity_access_grants().
 */
function og_actvity_access_grants($account) {
  $grants = array();

  // Account is granted access to all activities within the groups account
  // is a member of.
  $groups = og_get_subscriptions($account->uid);
  if (!empty($groups)) {
    $grants['og_member'] = array_keys($groups);
  }
  return $grants;
}

root@ma5 modules # cat og/includes/og.activity.inc 
<?php
// $Id: $

/**
 * @file:
 * Provides Activity module hooks for Organic groups.
 */

/**
 * Implementation of hook_activity_grants().
 */
function og_activity_grants($activity) {
  $groups = array();
  $grants = array();

  if ($activity->type == 'og') {
    $groups = array($activity->nid);
  }
  elseif (!empty($activity->nid)) {
    // Find all the groups the node belongs to.
    $groups = array_keys(og_get_node_groups(node_load($activity->nid)));
  }

  if (!empty($groups)) {
    $grants = array(
      'og_member' => $groups,
    );
  }

  return $grants;
}

/**
 * Implementation of hook_activity_access_grants().
 */
function og_actvity_access_grants($account) {
  $grants = array();

  // Account is granted access to all activities within the groups account
  // is a member of.
  $groups = og_get_subscriptions($account->uid);
  if (!empty($groups)) {
    $grants['og_member'] = array_keys($groups);
  }
  return $grants;
}

/**
 * Implementation of hook_activity_messages_alter().
 */
function og_activity_messages_alter(&$messages, $type, $objects) {
  // If its been invoked from hook_og.
  if ($type == 'og') {
    $sql = og_list_users_sql(1, 1, 'u.uid');
    $admin_members = db_query($sql, $objects['node']->nid);

    // for every group admin, add the message per language.
    while ($member = db_fetch_object($admin_members)) {
      foreach (array_keys($messages) as $language_id) {
        if (!empty($messages[$language_id][$objects['node']->uid])) {
          $messages[$language_id][$member->uid] = $messages[$language_id][$objects['node']->uid];
        }
      }
    }
  }
}
amitaibu’s picture

Status: Needs review » Needs work

@Scott Reynolds,
Thanks for the docs - we'll add them to OG's documentation as this patch will be committed.
I still have problems with making it work:
1) I'm using the 6--2.x-dev version.
2) I've set up an action on Og => insert member.
3) New member added to group, but nothing is added to {activity} - see problem in #27.

BenK’s picture

Subscribing....

Scott Reynolds’s picture

interesting i wonder what magik is on my machine that makes it work. I will dig in again soon.

Scott Reynolds’s picture

Status: Needs work » Needs review
StatusFileSize
new5.98 KB

I cannot figure out why it works for me. If this doesn't work people are really going to have to give really ridiculously detailed reports because I have literally tried everything I can think of. I have done EVERY op for hook_og in a number of different scenarios and group configurations.

And because I have done every $op i think I found a bug in og.pages.inc, where it uses the $op 'admin create' instead of 'admin new'. And I adjusted that. I have also double check the trigger_assignments table and the actions table to make sure that the Activity template got saved correctly.

I then tested to make sure that when I insert a node into a group, the activity_access table gets the Og access realm. Everything worked nice.

Perhaps its OG node access getting in the way. Activity automagikly joins node_access table (LEFT JOIN) to the query to ensure that it never surfaces Activity that the $GLOBALS['user'] cannot see and maybe that is in error? Can't imagine it is, as at my work we use a custom groups solution that behaves in a very similar way. (And I have written plenty of node access modules before for custom business goals).

Here is a patch with the Dreditor changes.

edit: I also deleted my entire og/ directory and then used CVS to checkout DRUPAL--6-2 and then applied the patch. It is working just fine. I have NO idea what makes my computer so special :-D

Scott Reynolds’s picture

@joeytheman: maybe you'll need to check the box to record og activity realm data on admin/settings/activity.

Removed this requirement with the latest Activity commits from today.
http://drupal.org/cvs?commit=329756

rnjthkmr88’s picture

Status: Needs work » Needs review

How to add an event within a group. the functionality of og_forums and og_events are different. By using og_forums we can view/create/edit forums within our groups.This is not the case with og_events. For creating an event to the group we have to change the content type of event and create an event under create content.
Is there any other way ?? any module available for creating/editing/viewing events of groups in a seperate tab(along with view, forums, edit etc. in a group)

Thank you.

amitaibu’s picture

Status: Needs review » Needs work

I think I found the problem:
_trigger_get_hook_aids() get's the $op == 'user_insert', but in the DB {trigger_assignments} has op == 'user insert' (no underscore).

Scott Reynolds’s picture

Status: Needs review » Needs work

In og.module, lines
453
657

Use 'user insert'

Where is 'user_insert' used?

amitaibu’s picture

Committed.
The problem was that $op changed if Rules module exists. I have fixed it and committed -- great work Scott, thank you.
I keep on needs work, as a book page is needed.

gábor hojtsy’s picture

Perfect. Is there a release expected with this included? :) Or is this branch stable enough to use on live sites, such as groups.drupal.org and localize.drupal.org?

amitaibu’s picture

If there are no surprises I'm planing to create a new release on the beginning of March.

amitaibu’s picture

@Scott,

Maybe not a bug, but more of a design thing I'd like to better understand:

+function og_activity_messages_alter(&$messages, $type, $objects) {
+  // If its been invoked from hook_og.
+  if ($type == 'og') {
+    $sql = og_list_users_sql(1, 1, 'u.uid');
+    $admin_members = db_query($sql, $objects['node']->nid);
+
+    // For every group admin, add the message per language.
+    while ($member = db_fetch_object($admin_members)) {

The problems that I see here are:
1) Duplication of the same message.
2) When a *new* admin get into the group, they will not see the admin messages

Can't we move this logic to og_actvity_access_grants() ?

Scott Reynolds’s picture

Well that is true. The messages table is set up for a direct UID => Message. Perhaps it should be Group_identifier_of_users => message. Not sure im willing to change Activity API though at this point.

amitaibu’s picture

> Not sure im willing to change Activity API though at this point.

Right. I think in Activity for D7 a message should be related to an entity_type/ entity_id/ conditions. So you can relate it the message to a group entity. The conditions in the case above will be a certain og_permission.

btw, do you have time to make #29 a help page -- and maybe attach there an exported view for the lazy ones ;)

jenlampton’s picture

Version: 6.x-2.x-dev » 6.x-2.1

I'm using the latest 6.x-2.1 branch of og.

I'd like to get an activity stream for a group that includes people joining the group and leaving the group, but - I think - the nid for the user joining the group is entered into the activity table incorrectly, so an argument for group nid doesn't catch og subscriptions.

Jen

AntiNSA’s picture

subscribe

amitaibu’s picture

Status: Needs work » Fixed

> When a *new* admin get into the group, they will not see the admin messages
I have come up with the Message module, to solves this problem.

@jenlampton,
Please open a new issue, and try to explain what is the "incorrect" nid.

Let's keep this issue closed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

oxford-dev’s picture

I have an issue, not sure if it is a bug or just an oversight.

I have lots of different activity types working fine but I've recently created a new type of activity 'joining a group'.

In my view, as well as the activity message, i have a relationship with content profile to display the users avatar in their activity feeds, so far so good.

However, when someone now joins a room, the avatar of the room author is displayed instead of the avatar of the person who joined the room.

After looking at admin/settings/activity/maintenance, its clear that the room author is the owner of activity feeds where other people join their room instead of the feed belonging to the actor who joined the room.

In terms of user experience, I would much rather know that a couple of my friends joined particular rooms instead of knowing that hundreds or thousands of people have joined one of my friends' room.

Not entirely sure how you might solve this.

dalad’s picture

Hello oxford-dev,
I had the same problem of og confusing between subjects of the activities.
I made this patch to fix the behaviour:
#819942: OG Activities on a moderated group are wrong and duplicated

AntiNSA’s picture

Status: Closed (fixed) » Needs review
amitaibu’s picture

Status: Needs review » Closed (fixed)

@AntiNSA,
Nothing to review here, so let's keep it closed.

AntiNSA’s picture

the patch in #52 needs review. doesnt it?

oxford-dev’s picture

Thanks dalad but i'm still not sure if your changes which achieve what i'm after.

I think the simplest solution for me is to have the activity assigned to the acting user (ie the person joining the group) as opposed to the group owner as it currently is.

[edit] by assigning to the actor what I mean is the uid in the activity table should be the actors uid not the node authors id.

yosisays’s picture

Has this functionality been added(per #7)? I wish to show very similar activity updates in my activity feed (I'm using the latest version of OG and Activity2). What I've been seeing is that when I set the activity publisher template for og's to output a message as something like "[user] joined the group [ogname]" everything works except for [ogname] token which does not show the name of the group a user has joined. I saw you posted a patch in #32 that from what i can tell has been committed but I'm still having trouble. am i missing something?

happysnowmantech’s picture

I had a use case like #7. I tried the Activity module, but it didn't do what I needed. I'm now using the Message module and it does handle my use case.