Index: og.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og/og.module,v retrieving revision 1.110.2.130 diff -u -r1.110.2.130 og.module --- og.module 7 Oct 2006 06:24:45 -0000 1.110.2.130 +++ og.module 10 Oct 2006 23:55:15 -0000 @@ -698,6 +698,46 @@ drupal_goto("node/$gid"); } +// RMT: handling of dynamic subscriptions. This function manages a +// 'user load' option of hook_og. An implementation of the hook +// needs to return an of "subscription records" +// +// To match what og_get_subscriptions needs, each record should contain the +// keys 'nid' (the OG gid), and the fields that are normally stored in the +// {og_uid} table, which are 'og_role' and 'is_admin'. This function +// guarantees that 'is_active' will be set true, and 'uid' will be stamped +// as called, to prevent funny business :-) + +function og_fetch_dynamic_subscriptions($uid){ + $args = array(); //Mosh: what can be in this argument? + $subs = module_invoke_all('og', 'user load', NULL, $uid, $args); + if (!is_array($subs)) + return array(); + $munged_subs = array(); + foreach ($subs as $sub) { + //check for required fields + if (!isset($sub['nid']) or !isset($sub['is_admin'])) + continue; + //for now, we can only subscribe once. It may make sense to + //"merge" some fields later + if (isset($munged_subs[$sub['nid']])) + continue; + //Make sure actually have a node here + $group = node_load($sub['nid']); + if ($group) { + $sub['is_active'] = 1; + $sub['uid'] = $uid; + $sub['title'] = $group->title; + $sub['type'] = $group->type; + $sub['status'] = $group->status; + $munged_subs[$sub['nid']] = $sub; + } + } + return $munged_subs; +} + + + // since a user's subscriptions are loaded into $user object, this function is only occassionally useful to get group subs for users other than the current user // even then, it often makes sense to call user_load() instead of this function. // load all subscriptions for a given user @@ -705,6 +745,10 @@ static $subscriptions = array(); if (!isset($subscriptions[$uid])) { + //We first check for dynamic subscriptions. A explicit subscription on + //the Drupal side overrides a dynamic setting. + $subscriptions[$uid] = og_fetch_dynamic_subscriptions($uid); + //Get explicit subscriptions $sql = "SELECT n.title, n.type, n.status, ou.* FROM {og_uid} ou INNER JOIN {node} n ON ou.nid = n.nid WHERE ou.uid = %d AND ou.is_active >= %d ORDER BY n.title"; $result = db_query($sql, $uid, $min_is_active); while ($row = db_fetch_array($result)) {