You are here

function subscriptions_og_page in Subscriptions 7

Same name and namespace in other branches
  1. 2.0.x subscriptions_og/subscriptions_og.module \subscriptions_og_page()

Defines a user's overview of which groups she is subscribed to.

Parameters

array $form: The form array.

int $uid: The user's UID.

Return value

array The form array.

1 string reference to 'subscriptions_og_page'
subscriptions_og_subscriptions in contrib/subscriptions_og/subscriptions_og.module
Implements hook_subscriptions().

File

contrib/subscriptions_og/subscriptions_og.module, line 152
Allow users to subscribe to content posted to an organic group.

Code

function subscriptions_og_page(array $form, $uid) {
  $account = user_load($uid);

  // 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',
  ))
    ->condition('s.module', 'node')
    ->condition('s.field', 'group_audience')
    ->condition('s.recipient_uid', $uid)
    ->orderBy('s.author_uid')
    ->execute();
  foreach ($result as $s) {
    $subscriptions[$s['value']][$s['author_uid']] = $s;
  }
  $form[0] = array(
    '#theme' => 'subscriptions_form_table',
  );
  $defaults = array();
  $groups = og_get_all_group('node');
  $groups = node_load_multiple($groups);
  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) && !user_access('administer group')) {
      continue;
    }

    // Add the active subscriptions.
    $group_name = check_plain($group->title);
    if (!isset($subscriptions[$group->nid][-1])) {

      // author-less item is missing -- add it here.
      $subscriptions[$group->nid][-1] = array(
        'send_interval' => _subscriptions_get_setting('send_interval', $uid),
        'send_comments' => _subscriptions_get_setting('send_comments', $uid),
        'send_updates' => _subscriptions_get_setting('send_updates', $uid),
        'author_uid' => FALSE,
      );
    }
    foreach ($subscriptions[$group->nid] as $author_uid => $subscription) {
      subscriptions_form_helper($form[0], $defaults, $author_uid, $group->nid, $group_name, $subscription);
    }
  }
  if (isset($form[0]['checkboxes'])) {
    $form[0]['defaults'] = array(
      '#type' => 'value',
      '#value' => $defaults,
    );
    subscriptions_form_column_filter($form[0], $uid);
  }
  else {
    $form = array(
      array(
        '#markup' => t('There are no available groups to subscribe to.'),
      ),
    );
  }
  return $form;
}