You are here

function uc_roles_user_view in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_roles/uc_roles.module \uc_roles_user_view()

Implements hook_user_view().

Displays role expirations on the user account screen.

File

uc_roles/uc_roles.module, line 351
Grants roles upon accepted payment of products.

Code

function uc_roles_user_view($account, $view_mode) {
  global $user;

  // Kick out anonymous.
  if (!$user->uid) {
    return;
  }

  // Only show if this user can access all role expirations, or if it's the same
  // user and the expirations are showing on the user pages.
  $show_expiration = variable_get('uc_roles_default_show_expiration', TRUE);
  if (!user_access('view all role expirations') && ($user->uid != $account->uid || !$show_expiration)) {
    return;
  }
  $items = array();
  $form = array();
  $expirations = db_query("SELECT * FROM {uc_roles_expirations} WHERE uid = :uid", array(
    ':uid' => $account->uid,
  ));
  foreach ($expirations as $expiration) {
    $form[$expiration->rid] = array(
      '#type' => 'user_profile_item',
      '#title' => check_plain(_uc_roles_get_name($expiration->rid)),
      '#markup' => t('This role will expire on !date', array(
        '!date' => format_date($expiration->expiration, 'short'),
      )),
    );
  }

  // Don't display anything if there aren't any expirations.
  if (!count($form)) {
    return;
  }
  $item = array(
    '#type' => 'user_profile_category',
    '#weight' => '-1',
    '#title' => t('Expiring roles'),
  );
  $account->content['uc_roles'] = $item + $form;
}