show listing of user's groups

Tannerjf - January 29, 2008 - 21:32
Project:Advanced Profile Kit
Version:5.x-1.x-dev
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:won't fix
Description

I've gotten my advanced profiles mostly configured. The one thing I'm missing is a way to display a list of the groups the user is subscribed to. I've tried making a view, and I also tried the snippet available here: http://drupal.org/node/141522. However, both of those will only show a list of groups for the currently logged in user, and not of the user who's profile is being viewed. How can I get it to work this way? This is just about the last thing I need to have my profiles complete, so I'd really appreciate any help that can be offered. Thanks!

#1

Michelle - January 30, 2008 - 05:36

I don't have OG installed to test, but try this:

<?php
$uid
= arg(1);
$profileuser = user_load((array('uid' => $uid)));
$groups = $profileuser->og_groups;
if(
$groups){
    foreach(
$groups as $group){
    echo
"<li>";
        print
l($group[title], 'node/'.$group[nid]);
    echo
"</li>";
    }
}
else {
    echo
"<li>$profileuser->name has joined no groups</li>";
}
?>

A better way is actually to make a content type, but that's more than I can explain tonight. I'm going to leave this set to active for now as a content type for this would be a useful addition.

Michelle

#2

Tannerjf - January 30, 2008 - 09:22

That works great, thanks :)

#3

txcrew - February 2, 2008 - 20:37

+1, works like a charm!

Thanks!

txcrew

#4

Michelle - February 3, 2008 - 16:33
Status:active» postponed

Setting this postponed for now as it will be a little while until I can get to adding it to advprofile.

Michelle

#5

scedwar - February 29, 2008 - 11:42

I placed a request in og sometime ago for this type of functionality on the user profile page to be extended to take into account users that are creators or admins of ogs. This is redundant now I'm moving to the advanced_profile.

The code above produces a listing of all groups that the user is a member of, whatever the level. In sites with many groups this needs breaking down.

What I would like is:
1) Improve the listing above to indicate if a user is the admin or creator of a group (e.g. in parentheses after the name)
2) Produce alternative listings that are a combination of:
a) only groups that the user is the owner/creator of;
b) only groups that the user is an admin of; and/or
b) only groups that the user is (merely) a member of.

So we could have panes that are combinations such as "All my Groups", "Groups I Admin for", etc

Has anyone looked at this? If not, I'll try and do something on this.

FWIW I use this snippet in blocks where I want to know if a group is owned by the current user, but I'm not sure how you pull out the admin status.

<?php
global $user;
$group = og_set_group_context();
$node_id_test = $group->nid;
if (
$group->uid == $user->uid) {
echo
"YOU ARE THE GROUP OWNER";
}
?>

Michelle - can you expand a little or give me some pointers on your comment: "A better way is actually to make a content type, but that's more than I can explain tonight. I'm going to leave this set to active for now as a content type for this would be a useful addition." ?

Thanks, Stephen

#6

Michelle - February 29, 2008 - 14:26

If you look at panels-content_userinfo.inc in the includes directory of advprofile, that's a content type. "Content type" in the panels sense is a bit of content that you can add to a panel, not a node type as it means in CCK. If you need to add complex custom content, it's better to make a new content type than to just dump it all in the custom content option. You also get access to the context by making your own content type.

I don't know much about OG so I can't help a lot, but I can tell you that you don't want global $user. That will give you the logged in user, not the profile owner. For that you need to use the context, and you can see it in action in that .inc.

Michelle

#7

scedwar - February 29, 2008 - 16:01

Thanks Michelle. I'm new to Panels so will explore and report back.

#8

digitalYours - June 8, 2008 - 11:57

Hi Michelle,

Where should I add this code?

Thanks,
Christoph

#9

Michelle - June 8, 2008 - 12:59

Add content then choose custom. Make sure you set the input format to PHP.

Michelle

#10

Michelle - September 12, 2008 - 23:11
Status:postponed» won't fix

APK will not be getting new features.

Michelle

#11

scedwar - September 13, 2008 - 13:02

I fixed this with a view taking the user uid as an arg (this allows you to put it in a panel). I then grab the uid arg in the empty text and do something like:

<?php
global $current_view;
$current_uid = (int)$current_view->args[0];

   
// Retrieve current user's groups where they are an admin
   
$result = pager_query("SELECT ou.nid, n.title FROM {og_uid} ou INNER JOIN {node} n ON ou.nid = n.nid WHERE ou.uid = $current_uid AND n.status=1 AND ou.is_admin > 0 ORDER BY n.title ASC", 50);
 
 
$header =array(
     array(
'data'=> t('My Groups')),
     array(
'data' => t('Num Group Members')));

  while (
$node = db_fetch_object($result)) {
   
$cnt = db_num_rows(db_query(og_list_users_sql(1), $node->nid));
   
$rows[] = array(
      array(
"data" => l($node->title, "node/$node->nid")),
      array(
"data" => l("$cnt", "og/users/$node->nid") ),
    );
  }
  if (!
$rows) {
   
//print("No Groups");
 
}else{
 
$output = theme('table', $header, $rows). theme('pager', NULL, 50,0);
  print
$output;
}
?>

If you want to show all groups and not just administered, just change the bit of SQL "ou.is_admin > 0" as appropriate.

 
 

Drupal is a registered trademark of Dries Buytaert.