diff --git a/contrib/subscriptions_og/subscriptions_og.install b/contrib/subscriptions_og/subscriptions_og.install new file mode 100644 index 0000000..741abe9 --- /dev/null +++ b/contrib/subscriptions_og/subscriptions_og.install @@ -0,0 +1,24 @@ +condition('module', 'node') + ->condition('field', 'group_audience') + ->execute(); +} + +/** + * Implements hook_uninstall(). + */ +function subscriptions_og_uninstall() { + variable_del('subscriptions_og_autosubscribe'); +} diff --git a/contrib/subscriptions_og/subscriptions_og.module b/contrib/subscriptions_og/subscriptions_og.module index a600857..7881b30 100644 --- a/contrib/subscriptions_og/subscriptions_og.module +++ b/contrib/subscriptions_og/subscriptions_og.module @@ -35,25 +35,39 @@ function subscriptions_og_subscriptions($op, $arg0 = NULL, $arg1 = NULL, $arg2 = 'weight' => -10, ); return $types; + // Queue: Define parameters used by Subscriptions to query which - // subscriptions should be sent. We search for subscriptions where the value - // is equal to the GID of any group that the newly saved $node is posted to. + // subscriptions should be sent. case 'queue': if ($arg0['module'] == 'node') { $node = $arg0['node']; + // Filter on subscriptions where the value is equal to the GID + // of any group that the newly saved $node is posted to. $params['node']['group_audience'] = array( 'join' => array( - 'table' => 'og_membership', - 'alias' => 'ga', - 'on' => "s.value = ga.gid AND ga.group_type = 'node'", + array( + 'table' => 'og_membership', + 'alias' => 'ga', + 'on' => "s.value = ga.gid AND ga.group_type = 'node'", + ), + // Filter on active OG members. + array( + 'table' => 'og_membership', + 'alias' => 'ga_user', + 'on' => "s.value = ga_user.gid AND u.uid = ga_user.etid", + ), ), 'where' => array( array('ga.etid', $node->nid, '='), array('ga.entity_type', 'node', '='), + array('ga.state', OG_STATE_ACTIVE, '='), + array('ga_user.entity_type', 'user', '='), + array('ga_user.state', OG_STATE_ACTIVE, '='), ), 'groupby' => 'ga.etid', ); + if ($arg0['type'] == 'comment') { $params['node']['group_audience']['where'][] = array('s.send_comments', 1, '='); } @@ -64,6 +78,7 @@ function subscriptions_og_subscriptions($op, $arg0 = NULL, $arg1 = NULL, $arg2 = return $params; } break; + case 'fields': // $arg0 is module. if ($arg0 == 'node' || $arg0 == 'comment') { @@ -77,6 +92,7 @@ function subscriptions_og_subscriptions($op, $arg0 = NULL, $arg1 = NULL, $arg2 = ); } break; + case 'mailkeys': $mailkeys = array(); $og_bundles = og_get_all_group_bundle(); @@ -84,6 +100,7 @@ function subscriptions_og_subscriptions($op, $arg0 = NULL, $arg1 = NULL, $arg2 = $mailkeys['group-type-' . $node_type] = t('Notifications for group content posted to %type groups', array('%type' => $node_name)); } return $mailkeys; + case 'mailkey_alter': if ($arg0 == 'group-type-') { $groups = og_get_entity_groups('node', $arg1); @@ -95,13 +112,15 @@ function subscriptions_og_subscriptions($op, $arg0 = NULL, $arg1 = NULL, $arg2 = } } break; + case 'token_types': if (strpos($arg0, 'group-type-') === 0) { return array('node', 'comment'); } break; + case 'node_options': - // $arg1 is the current node + // $arg1 is the current node. $options = array(); if (og_is_group('node', $arg1)) { $options['group_audience'][] = array( @@ -116,22 +135,33 @@ function subscriptions_og_subscriptions($op, $arg0 = NULL, $arg1 = NULL, $arg2 = } return $options; } + return NULL; } /** * Defines a user's overview of which groups she is subscribed to. * * @param array $form + * The form array. * @param int $uid - * The user's UID + * The user's UID. + * + * @return array + * The form array. */ function subscriptions_og_page(array $form, $uid) { $account = user_load($uid); - // Load all active OG subscriptions for this user + // Load all active OG subscriptions for this user. $query = db_select('subscriptions', 's', array('fetch' => PDO::FETCH_ASSOC)); $result = $query - ->fields('s', array('value', 'send_interval', 'author_uid', 'send_comments', 'send_updates')) + ->fields('s', array( + 'value', + 'send_interval', + 'author_uid', + 'send_comments', + 'send_updates', + )) ->condition('s.module', 'node') ->condition('s.field', 'group_audience') ->condition('s.recipient_uid', $uid) @@ -151,8 +181,8 @@ function subscriptions_og_page(array $form, $uid) { usort($groups, '_subscriptions_og_compare_groups'); foreach ($groups as $group) { - // Check that the user is a member of this group - if (!og_is_member('node', $group->nid, 'user', $account)) { + // Check that the user is a member of this group. + if (!og_is_member('node', $group->nid, 'user', $account) && !user_access('administer group')) { continue; } @@ -182,7 +212,9 @@ function subscriptions_og_page(array $form, $uid) { } else { $form = array( - array('#markup' => t('There are no available groups to subscribe to.')) + array( + '#markup' => t('There are no available groups to subscribe to.'), + ), ); } @@ -195,7 +227,6 @@ function subscriptions_og_page(array $form, $uid) { * Adds checkbox to allow enable/disable autosubscriptions. */ function subscriptions_og_form_subscriptions_settings_form_alter(&$form, &$form_state, $form_id) { - $form['subscriptions_og'] = array( '#type' => 'fieldset', '#title' => t('Organic Groups subscriptions'), @@ -221,14 +252,22 @@ function subscriptions_og_og_membership_insert($og_membership) { $send_comments = _subscriptions_get_setting('send_comments', $og_membership->etid); subscriptions_write_subscription( - 'node', // Module - 'group_audience', // Field - $og_membership->gid, // Value - -1, // Author uid - $og_membership->etid, // Recipient - $send_interval, // Send interval - $send_updates, // Send updates - $send_comments // Send comments + // Module. + 'node', + // Field. + 'group_audience', + // Value. + $og_membership->gid, + // Author uid. + -1, + // Recipient. + $og_membership->etid, + // Send interval. + $send_interval, + // Send updates. + $send_updates, + // Send comments. + $send_comments ); } } @@ -240,10 +279,14 @@ function subscriptions_og_og_membership_delete($og_membership) { $autosubscribe = variable_get('subscriptions_og_autosubscribe', FALSE); if ($autosubscribe && $og_membership->group_type == 'node' && $og_membership->entity_type == 'user') { subscriptions_delete( - $og_membership->etid, // Recipient - 'node', // Module - 'group_audience', // Field - $og_membership->gid // Value + // Recipient. + $og_membership->etid, + // Module. + 'node', + // Field. + 'group_audience', + // Value. + $og_membership->gid ); } } @@ -253,27 +296,15 @@ function subscriptions_og_og_membership_delete($og_membership) { * * Intended for use with usort() and similar functions. * - * @param OgGroup $first - * @param OgGroup $second + * @param object $first + * An organic group node. + * @param object $second + * An organic group node. * * @return int - * < 0 if $first comes before $second, > 0 if $second comes before $first, and - * 0 if they are equal in sorting order. + * < 0 if $first comes before $second, > 0 if $second comes before $first, and + * 0 if they are equal in sorting order. */ function _subscriptions_og_compare_groups($first, $second) { return strcmp($first->title, $second->title); } - -/** - * Implements hook_disable(). - * - * Removes our queue items. - * - * @ingroup hooks - */ -function subscriptions_og_disable() { - db_delete('subscriptions_queue') - ->condition('module', 'node') - ->condition('field', 'group_audience') - ->execute(); -} diff --git a/subscriptions.module b/subscriptions.module index 9dfc8c3..e36ef1a 100644 --- a/subscriptions.module +++ b/subscriptions.module @@ -478,9 +478,14 @@ function subscriptions_queue(array $event) { $select->innerJoin('subscriptions_user', 'su', 's.recipient_uid = su.uid'); $select->innerJoin('users', 'u', 'su.uid = u.uid'); $select->leftJoin('subscriptions_last_sent', 'sls', 'su.uid = sls.uid AND s.send_interval = sls.send_interval'); + if (!empty($query['join'])) { - $select->innerJoin($query['join']['table'], $query['join']['alias'], $query['join']['on']); + $joins = isset($query['join']['table']) ? array($query['join']) : $query['join']; + foreach ($joins as $join) { + $select->innerJoin($join['table'], $join['alias'], $join['on']); + } } + $select ->fields('u', array('uid', 'name', 'language')) ->fields('s', array('module', 'field', 'value', 'author_uid', 'send_interval'))