You are here

function subscriptions_page_user_overview in Subscriptions 7

Same name and namespace in other branches
  1. 5.2 subscriptions.admin.inc \subscriptions_page_user_overview()
  2. 6 subscriptions.admin.inc \subscriptions_page_user_overview()
  3. 2.0.x subscriptions.admin.old.php \subscriptions_page_user_overview()

Construct the overview page, which displays a summary of subscriptions per type as well as the user settings at user/UID/subscriptions. This form is also used for admin/settings/subscriptions/userdefaults.

_state

Parameters

array $form:

object|null $account: Must be a valid user account from user_load() or NULL (for the admin form).

Return value

array|null

1 string reference to 'subscriptions_page_user_overview'
subscriptions_menu in ./subscriptions.module
Implements hook_menu().

File

./subscriptions.admin.inc, line 378
Subscriptions module (load-on-demand admin functions).

Code

function subscriptions_page_user_overview(array $form, array &$form_state, $account) {

  // Build summary
  $uid = !empty($account) ? $account->uid : -DRUPAL_AUTHENTICATED_RID;
  $counts = array();
  $result = db_query("SELECT module, field, COUNT(1) AS number FROM {subscriptions} WHERE recipient_uid = :recipient_uid GROUP BY module, field", array(
    ':recipient_uid' => $uid,
  ));
  foreach ($result as $subs) {
    if (!empty($subs->module)) {
      $counts[$subs->module][$subs->field] = $subs->number;
    }
  }

  // Give other modules a chance to add their count(s).
  drupal_alter('subscriptions_counts', $counts, $uid);
  $tr = 't';
  $header = array(
    array(
      'data' => $tr('Type'),
      'width' => '20%',
    ),
    t('Number'),
  );
  $types = subscriptions_types();
  if ($uid < 0) {
    unset($types['node']);
  }
  uasort($types, '_subscriptions_cmp_by_weight');
  $rows = array();
  foreach ($types as $stype => $type) {
    $has_access = $uid < 0 && user_access('administer site configuration') || user_access($type['access'], $account);
    if (($has_access || user_access('administer user subscriptions')) && isset($type['fields'])) {
      $rows[] = array(
        $has_access ? l($tr($type['title']), $uid < 0 ? SUBSCRIPTIONS_CONFIG_PATH . "/userdefaults/{$stype}" : "user/{$uid}/subscriptions/{$stype}") : $type['title'],
        isset($type['fields'][2]) && isset($counts[$type['fields'][0]][$type['fields'][2]]) ? $counts[$type['fields'][0]][$type['fields'][2]] : (isset($counts[$type['fields'][0]][$type['fields'][1]]) ? $counts[$type['fields'][0]][$type['fields'][1]] : 0),
      );
    }
  }
  $form['overview']['table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  $form['overview']['note'] = array(
    '#type' => 'item',
    '#description' => t('Note: The counts on this page may differ from the ones on the detail pages for various technical reasons.'),
    '#suffix' => '<br />',
  );
  $form['#submit'] = array();
  if ($uid > 0) {
    subscriptions_user_suspend_form($form, $form_state, $account);
  }
  $form = subscriptions_user_settings_form($form, $form_state, $account);
  drupal_set_title($uid < 0 ? t('Subscriptions') : format_username($account));
  return $form;
}