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
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

IceCreamYou - July 10, 2009 - 00:02
Assigned to:Anonymous» IceCreamYou
Status:active» postponed

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

jct - July 10, 2009 - 17:40

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

IceCreamYou - July 11, 2009 - 00:14
Title:Organic Groups» Organic Groups integration

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

jct - July 13, 2009 - 13:58

Thanks for the clarification. I greatly appreciate the help you've given--thanks for considering Views 2 integration sometime in the future.

#5

IceCreamYou - August 13, 2009 - 19:30
Category:feature request» support request
Status:postponed» fixed

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

System Message - August 27, 2009 - 19:40
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.