You are here

function commons_notifications_is_group_subscribed in Drupal Commons 6.2

Determine if a user has any subscriptions for a given group

Parameters

$group: The group object

$user: Optionally supply the user, otherwise use current

Return value

TRUE if the user has at least one subscription to the given group, otherwise FALSE

1 call to commons_notifications_is_group_subscribed()
commons_notifications_og_links_alter in modules/features/commons_notifications/commons_notifications.module
Implementation of hook_og_links_alter()

File

modules/features/commons_notifications/commons_notifications.module, line 83

Code

function commons_notifications_is_group_subscribed($group, $user = NULL) {

  // If user not provided, load the current
  if (!$user) {
    global $user;
  }

  // Just in case, to avoid false-positives
  if (!$group->nid) {
    return FALSE;
  }

  // Build subscription query information for notifications
  $params = array(
    'type' => 'grouptype',
    'uid' => $user->uid,
  );
  $conditions = array(
    array(
      'type' => 'group',
      'value' => $group->nid,
    ),
  );

  // Fetch the subscriptions for the given group
  $subscriptions = notifications_get_subscriptions($params, $conditions, FALSE, 'sid');
  return !empty($subscriptions);
}