? abstract_membership_source.patch ? og_membership.inc ? og_user_load_revised.patch ? rmt.notes Index: og.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og/og.module,v retrieving revision 1.110.2.133 diff -u -r1.110.2.133 og.module --- og.module 17 Oct 2006 19:39:09 -0000 1.110.2.133 +++ og.module 21 Oct 2006 00:34:48 -0000 @@ -1,6 +1,9 @@ start(); + + $txt = format_plural($ms->count(), 'the sole subscriber', 'all %count subscribers'); drupal_set_message(t('Your email will be sent to %count in this group. Please use this feature sparingly.', array('%count' => l($txt, "og/users/$gid")))); $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#size' => 70, '#maxlength' => 250, '#description' => t("Enter a subject for your email."), '#required' => true); @@ -298,9 +304,11 @@ global $user; $from = $user->mail; $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from"; - $sql = og_list_users_sql(1); - $result = db_query($sql, $form_values['gid']); - while ($row = db_fetch_object($result)) { + //$sql = og_list_users_sql(1); + //$result = db_query($sql, $form_values['gid']); + $ms = new og_uid_table_sub_list($form_values['gid'], 1); + $ms->start(); + while ($row = $ms->next()) { $emails[] = $row->mail; } foreach ($emails as $mail) { @@ -642,9 +650,11 @@ switch ($node->og_selective) { case OG_MODERATED: og_save_subscription($gid, $account->uid, array('is_active' => 0)); - $sql = og_list_users_sql(1, 1); - $res = db_query($sql, $node->nid); - while ($row = db_fetch_object($res)) { + //$sql = og_list_users_sql(1, 1); + //$res = db_query($sql, $node->nid); + $ms = new og_uid_table_sub_list($node->nid, 1, 1); + $ms->start(); + while ($row = $ms->next()) { if ($row->mail) { $admins[] = $row->mail; } @@ -698,6 +708,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 +755,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)) { @@ -785,9 +839,12 @@ $i++; $sql = og_list_users_sql(0,0,'ou.is_admin DESC, ou.is_active ASC, u.name ASC'); + $ms = new og_uid_table_sub_list($gid, 0, 0, + 'ou.is_admin DESC, ou.is_active ASC, u.name ASC'); + $ms->start(TRUE, 0, 500); /* list group admins first, pending subscribers second, regular subscribers last. Alphabetize within each of these catergories */ - $result = pager_query($sql, 500, 0, NULL, $gid); - while ($account = db_fetch_object($result)) { + //$result = pager_query($sql, 500, 0, NULL, $gid); + while ($account = $ms->next()) { if ($account->uid != $node->uid) { $username = theme('username', $account); if (!$account->is_active) { $username .= ' '.t('(approval needed)'). ''; } @@ -811,6 +868,9 @@ $i++; } } + //RMT: this is not guaranteed to work on a non-native + //membership source, since we can't use Drupal's native paging. + //better to provide a link to the foreign source. if ($pager = theme('pager', NULL, 500)) { $rows[$i][] = array('data' => $pager, 'colspan' => 2); } @@ -830,6 +890,8 @@ } else { // Retrieve only current user's group + //RMT: this really ought to use og_get_subscriptions instead of + //doing its own query as it is doing here. $result = pager_query(db_rewrite_sql("SELECT og.nid, n.title, r.body, n.uid, u.name, og.description FROM {og} og INNER JOIN {node} n ON og.nid = n.nid INNER JOIN {node_revisions} r ON r.vid = n.vid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {og_uid} ou ON ou.uid = u.uid WHERE og.nid IN (". implode(',', array_keys($user->og_groups)) .") ORDER BY og.nid DESC", 'og', 'nid'), 50); } if ($format == 'opml') { @@ -2076,10 +2138,14 @@ global $user; if ($node = og_get_group_context()) { - $result = db_query(og_list_users_sql(0), $node->nid); - $cntall = db_num_rows($result); + //$result = db_query(og_list_users_sql(0), $node->nid); + //$cntall = db_num_rows($result); + $ms = new og_uid_table_sub_list($node->nid, 0); + $ms->start(); + $cntall = $ms->count(); + $cntpending = 0; - while ($row = db_fetch_object($result)) { + while ($row = $ms->next()) { if ($row->is_active == 0) { $cntpending++; } Index: og_views.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og/og_views.inc,v retrieving revision 1.1.2.3 diff -u -r1.1.2.3 og_views.inc --- og_views.inc 30 Jun 2006 16:54:37 -0000 1.1.2.3 +++ og_views.inc 21 Oct 2006 00:34:48 -0000 @@ -431,7 +431,9 @@ function og_handler_field_count($fieldinfo, $fielddata, $value, $data) { global $user; - $cnt = db_num_rows(db_query(og_list_users_sql(), $data->nid)); + $iter = new og_uid_table_sub_list($data->nid); + $iter->start(); + $cnt = $iter->count(); return in_array($data->nid, array_keys($user->og_groups)) ? l($cnt, "og/users/$data->nid") : $cnt; } Index: og_xmlrpc.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og/og_xmlrpc.inc,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 og_xmlrpc.inc --- og_xmlrpc.inc 15 May 2006 19:20:27 -0000 1.1.2.2 +++ og_xmlrpc.inc 21 Oct 2006 00:34:49 -0000 @@ -22,9 +22,9 @@ $account = user_authenticate($username, $password); if ($account->uid) { if (in_array($gid, array_keys($account->og_groups)) || user_access('administer organic groups', $account)) { - $sql = og_list_users_sql($min_is_active, $min_is_admin); - $result = db_query($sql, $gid); - while ($row = db_fetch_array($result)) { + $iter = new og_uid_table_sub_list($gid, $min_is_active, $min_is_admin); + $iter->start(); + while ($row = (array) $iter->next()) { $users[$row['uid']] = $row; } return $users;