Organic Groups integration
jct - July 9, 2009 - 19:16
| Project: | Facebook-style Statuses (Microblog) |
| Version: | 6.x-2.0-rc1 |
| Component: | Code - Functionality |
| Category: | support request |
| Priority: | normal |
| Assigned: | IceCreamYou |
| Status: | closed |
Jump to:
Description
I have a large site and would like to limit a view of status updates to only show organic group members. I saw you posted a bit of code for the 1.5 version (http://drupal.org/node/340306), but couldn't get it to work for 2.0.
The ideal solution would be a filter or argument for OG in FBSS views, but a quick hack would also do the trick.
Thanks for considering it!

#1
I'm going to assume you're working with 2.x because I have no interest in developing code for a branch of OG that will soon be deprecated.
Quick hack that could potentially get pretty slow on very large sites:
<?php/**
* The if() clause wrapping the code below will cause this snippet to show only to users in the relevant group.
* This code assumes it will only appear on node pages AND that OG is enabled.
*/
if (og_is_group_member(arg(1))) {
$users = array();
$items = array();
$total = 5; //Change this to the number of results you want.
$latest_only = FALSE; //Changing to TRUE will cause only the latest status for each user to appear.
$result = db_query("SELECT uid FROM {og_uid} WHERE is_active = 1 AND nid = %d", arg(1));
while ($user = db_fetch_object($result)) {
$users[] = $user->uid;
}
$statuses = facebook_status_get_statuses($users, $users, $total, $latest_only);
foreach ($statuses as $status) {
$items[] = theme('facebook_status_item', $status);
}
echo theme('item_list', $items);
}
?>
I like the idea of Views integration but I don't have time to look into it right now. I'm thinking a simple relationship should do the trick though.
#2
Thanks for such an amazingly quick response!
The code was a good start, but didn't quite associate itself with groups. My php skills aren't very good, but I was able to tweak things so that the list only shows on group pages were the user is a member (using this in a block).
<?php/**
* The if() clause wrapping the code below will cause this snippet to show only to users in the relevant group.
* This code assumes it will only appear on node pages AND that OG is enabled.
*/
if (og_is_group_member(arg(1))) {
$users = array();
$items = array();
$total = 5; //Change this to the number of results you want.
$latest_only = FALSE; //Changing to TRUE will cause only the latest status for each user to appear.
$result = db_query("SELECT uid FROM {og_uid} WHERE is_active = 1 AND nid = %d OR nid IN (SELECT group_nid FROM {og_ancestry} WHERE nid = %d)", arg(1));
while ($user = db_fetch_object($result)) {
$users[] = $user->uid;
}
$statuses = facebook_status_get_statuses($users, $users, $total, $latest_only);
foreach ($statuses as $status) {
$items[] = theme('facebook_status_item', $status);
}
echo theme('item_list', $items);
}
?>
My only problem at this point is that the status list isn't limited to group members (statuses from all site users show in the list).
Thanks again for the help.
#3
Your change just made it so users in any child or parent group of the currently viewed group would be included in the list of status updates. Probably I wasn't clear: the code only works on group pages, not node pages. I don't have the time or resources to help you more than this but I'll probably get to OG integration via Views before the next stable release.
#4
Thanks for the clarification. I greatly appreciate the help you've given--thanks for considering Views 2 integration sometime in the future.
#5
It turns out you can do this with a User view. Facebook-style Statuses fields/filters/sorts/arguments should work in User views and Organic Group arguments/filters appear there too.
#6
Automatically closed -- issue fixed for 2 weeks with no activity.