You are here

function subscriptions_page_user_overview in Subscriptions 5.2

Same name and namespace in other branches
  1. 6 subscriptions.admin.inc \subscriptions_page_user_overview()
  2. 7 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.

@params $account Must be a valid user account from user_load() or NULL (for the admin form).

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

File

./subscriptions.admin.inc, line 290

Code

function subscriptions_page_user_overview($account) {

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

  // give other modules a chance to add their count(s)
  $more_counts = module_invoke_all('count_user_subscriptions', $counts, $uid);
  $counts = array_merge($counts, $more_counts);
  $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');
  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')) {
      $rows[] = array(
        $has_access ? l($type['title'], $uid < 0 ? "admin/settings/subscriptions/userdefaults/{$stype}" : "user/{$account->uid}/subscriptions/{$stype}") : $type['title'],
        isset($counts[$type['fields'][0]][$type['fields'][1]]) ? $counts[$type['fields'][0]][$type['fields'][1]] : 0,
      );
    }
  }
  $output = theme('table', $header, $rows);
  $output .= theme('item', array(
    '#value' => '',
    '#description' => t('Note: The counts on this page may differ from the ones on the detail pages for various technical reasons.'),
  ));
  $output .= '<br />';
  $output .= drupal_get_form('subscriptions_user_settings_form', $account);
  drupal_set_title($uid < 0 ? t('Subscriptions') : check_plain($account->name));
  return $output;
}