function subscriptions_og_subscriptions in Subscriptions 7
Same name and namespace in other branches
- 2.0.x subscriptions_og/subscriptions_og.module \subscriptions_og_subscriptions()
Implements hook_subscriptions().
File
- contrib/
subscriptions_og/ subscriptions_og.module, line 24 - Allow users to subscribe to content posted to an organic group.
Code
function subscriptions_og_subscriptions($op, $arg0 = NULL, $arg1 = NULL, $arg2 = NULL) {
switch ($op) {
case 'types':
$types['og'] = array(
'title' => 'Groups',
'access' => 'og subscribe',
'permission' => array(
'title' => t('Subscribe to notifications for Organic Groups'),
),
'page' => 'subscriptions_og_page',
'fields' => array(
'node',
'group_audience',
),
'weight' => -10,
);
return $types;
// Queue: Define parameters used by Subscriptions to query which
// 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(
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,
'=',
);
}
elseif ($arg0['type'] == 'node' && $arg0['action'] == 'update') {
$params['node']['group_audience']['where'][] = array(
's.send_updates',
1,
'=',
);
}
return $params;
}
break;
case 'fields':
// $arg0 is module.
if ($arg0 == 'node' || $arg0 == 'comment') {
return array(
'group_audience' => array(
'data_function' => 'subscriptions_content_data',
'subs_mod' => 'subscriptions_og',
'subs_type' => t('group'),
'mailkey' => 'group-type-',
),
);
}
break;
case 'mailkeys':
$mailkeys = array();
$og_bundles = og_get_all_group_bundle();
foreach ($og_bundles['node'] as $node_type => $node_name) {
$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);
// We take only the first group to which this node is posted. This won't
// be correct if this node is posted to multiple, different group types.
if (!empty($groups) && !empty($groups['node'])) {
$group = node_load(current($groups['node']));
return 'group-type-' . $group->type;
}
}
break;
case 'token_types':
if (strpos($arg0, 'group-type-') === 0) {
return array(
'node',
'comment',
);
}
break;
case 'node_options':
// $arg1 is the current node.
$options = array();
if (og_is_group('node', $arg1)) {
$options['group_audience'][] = array(
'name' => t('To content posted in %name', array(
'%name' => $arg1->title,
)),
'link' => 'node/' . $arg1->nid,
'params' => array(
'module' => 'node',
'field' => 'group_audience',
'value' => $arg1->nid,
),
);
}
return $options;
}
return NULL;
}