Community Documentation

OG- list the groups managed by the current user

Last updated October 6, 2006. Created by pwolanin on June 11, 2006.
Log in to edit this page.

PLEASE NOTE! The following snippet is user submitted. Use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

Here's a snippet for use with the organic groups module. The output is similar to what's on the "/og" page, but restricted to those groups where the current user is a manager of the group. This could be useful for a site where individual users are managers for several groups, and they want a shortcut to find just those groups.

<p> Group managers -- Click on the name of a group below to see all group content, e-mail your group members, or edit the group name or information.  Click on the number of members to see your list of group members and to add/delete members. </p>

<h2>Groups you are an admin for:</h2>
<br/>
<?php

 
global $user;

  if (!
$user->uid) {
    return;
// Only for logged-in users
 
}
   
// 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 = $user->uid AND n.status=1 AND ou.is_admin > 0 ORDER BY n.title ASC", 50);
 
 
$header =array(
     array(
'data'=> t('Title')),
     array(
'data' => t('Subscribers')));

  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("List all $cnt users", "og/users/$node->nid") ),
    );
  }
  if (!
$rows) {
   
$rows[] = array(array('data' => t('No groups'), 'colspan' => 2));
  }
 
$output = theme('table', $header, $rows). theme('pager', NULL, 50,0);
  print
$output;
?>


<br/>
<p>You can also go to the <a href="/og">groups</a> page.  Click on the number of members for any group you're a member of to see the list of committee members.  All groups you belong to are also listed under the <?php print(l(t('my account'),"user/$user->uid"));?> page</p>

About this page

Drupal version
Drupal 4.7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here