You are here

function userpoints_get_categories in User Points 7.2

Same name and namespace in other branches
  1. 5.3 userpoints.module \userpoints_get_categories()
  2. 6 userpoints.module \userpoints_get_categories()
  3. 7 userpoints.module \userpoints_get_categories()

Returns an array of possible categories, suitable for inclusion in FAPI.

Related topics

20 calls to userpoints_get_categories()
UserpointsAdminTestCase::testAddEditPoints in ./userpoints.test
UserpointsBaseTestCase::addPoints in ./userpoints.test
Add points through the admin form.
UserpointsTransaction::getCategory in ./userpoints.transaction.inc
The category of this transaction.
UserpointsTransaction::getMessage in ./userpoints.transaction.inc
A message that can be displayed to the current user.
UserpointsTransaction::getTableRow in ./userpoints.transaction.inc
Returns a single row for a transaction listing.

... See full list

File

./userpoints.module, line 1224

Code

function userpoints_get_categories($account = NULL) {
  $cache = drupal_static(__FUNCTION__, array());
  $key = $account ? $account->uid : 0;
  if (!isset($cache[$key])) {

    // Create the "Uncategorized" category.
    $options = array();
    $options[0] = t('!Uncategorized', userpoints_translation());
    if (module_exists('taxonomy')) {
      $vid = userpoints_get_vid();
      if ($vid) {

        // If an account is passed, load the terms directly from the database.
        if ($account) {
          $query = db_select('taxonomy_term_data', 't')
            ->fields('t', array(
            'tid',
            'name',
          ))
            ->condition('t.vid', userpoints_get_vid())
            ->groupBy('t.tid')
            ->groupBy('t.name')
            ->groupBy('t.weight')
            ->orderBy('t.weight');
          $query
            ->join('userpoints_txn', 'p', 't.tid = p.tid AND p.uid = :uid', array(
            ':uid' => $account->uid,
          ));
          $terms = $query
            ->execute();
        }
        else {
          $terms = taxonomy_get_tree($vid);
        }
        foreach ($terms as $term) {
          $options[$term->tid] = $term->name;
        }
      }
    }
    $cache[$key] = $options;
  }
  return $cache[$key];
}