You are here

function flag_get_flag_counts in Flag 7.2

Same name and namespace in other branches
  1. 6.2 flag.module \flag_get_flag_counts()
  2. 7.3 flag.module \flag_get_flag_counts()

Get the total count of items flagged within a flag.

Parameters

$flag_name: The flag name for which to retrieve a flag count.

$reset: Reset the internal cache and execute the SQL query another time.

File

./flag.module, line 1590
The Flag module.

Code

function flag_get_flag_counts($flag_name, $reset = FALSE) {
  $counts =& drupal_static(__FUNCTION__);
  if ($reset) {
    $counts = array();
  }
  if (!isset($counts[$flag_name])) {
    $flag = flag_get_flag($flag_name);
    $counts[$flag_name] = db_select('flag_counts', 'fc')
      ->fields('fc', array(
      'fcid',
    ))
      ->condition('fid', $flag->fid)
      ->countQuery()
      ->execute()
      ->fetchField();
  }
  return $counts[$flag_name];
}