You are here

function _taxonomy_menu_term_count in Taxonomy menu 7

Same name and namespace in other branches
  1. 8 taxonomy_menu.database.inc \_taxonomy_menu_term_count()
  2. 6.3 taxonomy_menu.database.inc \_taxonomy_menu_term_count()
  3. 6.2 taxonomy_menu.database.inc \_taxonomy_menu_term_count()
  4. 7.2 taxonomy_menu.database.inc \_taxonomy_menu_term_count()

Gets the count of nodes for each term (without children).

@todo Needs updating since terms are related via fields now.

Parameters

int $tid: Taxonomy term ID.

Return value

int Count of nodes that reference the term.

4 calls to _taxonomy_menu_term_count()
taxonomy_menu_term_count_nodes in ./taxonomy_menu.module
Calculates the number of nodes linked to the term and all children.
taxonomy_menu_translated_menu_link_alter in ./taxonomy_menu.module
Implements hook_translated_menu_link_alter().
_taxonomy_menu_children_has_nodes in ./taxonomy_menu.module
Helper function: See if any of the children have any nodes.
_taxonomy_menu_item in ./taxonomy_menu.module
Helper function: Inserts and updates menu along with taxonomy changes.

File

./taxonomy_menu.database.inc, line 170
Database functions

Code

function _taxonomy_menu_term_count($tid) {

  // Construct a cache ID
  $cid = 'taxonomy_menu:term_count:' . $tid;

  // Try to get the count from the cache.
  $cache = cache_get($cid);
  if ($cache) {
    return $cache->data;
  }

  // It is not in the cache, so issue a query.
  $result = db_select('taxonomy_index', 'tn');
  $result
    ->condition('tid', $tid);
  $result
    ->join('node', 'n', 'n.nid = tn.nid AND n.status = 1');
  $result
    ->addExpression('COUNT(n.nid)', 'term_count');
  $temp = $result
    ->execute();
  $temp = $temp
    ->fetchObject();
  $data = $temp->term_count;

  // Store the count in the cache.
  cache_set($cid, $data, 'cache', REQUEST_TIME + 1215);

  // Return the result.
  return $data;
}