function flag_get_counts in Flag 5
Same name and namespace in other branches
- 6.2 flag.module \flag_get_counts()
- 6 flag.module \flag_get_counts()
- 7.3 flag.module \flag_get_counts()
- 7.2 flag.module \flag_get_counts()
Get flag counts for all flags on a node.
Parameters
$content_type: The content type (usually 'node').
$content_id: The content ID (usually the node ID).
$reset: Reset the internal cache and execute the SQL query another time.
Return value
$flags An array of the structure [name] => [number of flags].
2 calls to flag_get_counts()
- flag_flag::flag in ./
flag.inc - Flags, on unflags, an item.
- flag_flag::get_count in ./
flag.inc - Returns the number of times an item is flagged.
File
- ./
flag.module, line 849 - The Flag module.
Code
function flag_get_counts($content_type, $content_id, $reset = FALSE) {
static $counts;
if ($reset) {
$counts = array();
if (!isset($content_type)) {
return;
}
}
if (!isset($counts[$content_type][$content_id])) {
$counts[$content_type][$content_id] = array();
$result = db_query("SELECT f.name, fc.count FROM {flags} f LEFT JOIN {flag_counts} fc ON f.fid = fc.fid WHERE fc.content_type = '%s' AND fc.content_id = %d", $content_type, $content_id);
while ($row = db_fetch_object($result)) {
$counts[$content_type][$content_id][$row->name] = $row->count;
}
}
return $counts[$content_type][$content_id];
}