You are here

function userpoints_get_points_list in User Points 7

Same name and namespace in other branches
  1. 7.2 userpoints.module \userpoints_get_points_list()

Returns a render array that displays the points and action links.

Parameters

$account: User object for which the points should be displayed.

Return value

Render array with the points and actions.

2 calls to userpoints_get_points_list()
userpoints_block_view in ./userpoints.module
Implements hook_block_view().
userpoints_user_view in ./userpoints.module
Implements hook_user_view().

File

./userpoints.module, line 1276

Code

function userpoints_get_points_list($account = NULL) {
  global $user;
  if (empty($account)) {
    $account = $user;
  }
  $output = array();
  $categories = userpoints_get_categories();

  // 0 can not be used as a checkbox value.
  $categories = array(
    'uncategorized' => $categories[0],
  ) + $categories + array(
    'all' => t('Total !points in all categories', userpoints_translation()),
  );
  unset($categories[0]);
  $tids = array_filter(variable_get(USERPOINTS_CATEGORY_PROFILE_DISPLAY_TID, array_keys($categories)));
  if (!empty($tids)) {
    $points_list = array();
    $total = NULL;
    foreach ($tids as $tid) {

      // Which points are we displaying. Special case for uncategorized.
      $points = userpoints_get_current_points($account->uid, $tid == 'uncategorized' ? 0 : $tid);
      if ($tid == 'all') {
        $total = t('Total (all categories): @points', userpoints_translation() + array(
          '@points' => $points,
        ));
      }
      else {
        $points_list[] = t('%category: @points', userpoints_translation() + array(
          '@points' => $points,
          '%category' => $categories[$tid],
        ));
      }
    }

    // If there are multiple categories, create a list.
    $output['list'] = array(
      '#theme' => 'item_list',
      '#items' => $points_list,
      '#attributes' => array(
        'class' => array(
          'userpoints-points',
        ),
      ),
    );
    if ($total) {
      $output['total'] = array(
        '#markup' => '<div class="userpoints-total">' . $total . '</div>',
      );
    }
  }
  $links = array();
  if (userpoints_access_my_points($account)) {
    $links['userpoints-view'] = array(
      'title' => t('View !points transactions', userpoints_translation()),
      'href' => $user->uid == $account->uid ? 'myuserpoints' : 'user/' . $account->uid . '/points',
    );
  }
  if (userpoints_admin_access('add')) {
    $links['userpoints-adjust'] = array(
      'title' => t('Add or deduct !points', userpoints_translation()),
      'href' => 'admin/config/people/userpoints/add/' . $account->uid,
    );
  }
  $output['actions'] = array(
    '#theme' => 'links__userpoints_actions',
    '#links' => $links,
    '#attributes' => array(
      'class' => array(
        'links',
        'userpoints-links',
      ),
    ),
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'userpoints') . '/userpoints.css',
      ),
    ),
  );
  return $output;
}