You are here

function flag_get_content_flags in Flag 6.2

Same name and namespace in other branches
  1. 5 flag.module \flag_get_content_flags()
  2. 6 flag.module \flag_get_content_flags()
  3. 7.2 flag.module \flag_get_content_flags()

Return a list of users who have flagged a piece of content.

Parameters

$content_type: The type of content that will be retrieved. Usually 'node'.

$content_id: The content ID to check for flagging.

$flag_name: Optional. The name of a flag if wanting a list specific to a single flag.

$reset: Reset the internal cache of flagged content.

Return value

If no flag name is given, an array of flagged content, keyed by the user ID that flagged the content. Each flagged content array is structured as an array of flag information for each flag, keyed by the flag name. If a flag name is specified, only the information for that flag is returned.

File

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

Code

function flag_get_content_flags($content_type, $content_id, $flag_name = NULL, $reset = FALSE) {
  static $content_flags;
  if (!isset($content_flags[$content_type][$content_id]) || $reset) {
    $flag_names = _flag_get_flag_names();
    $result = db_query("SELECT * FROM {flag_content} WHERE content_type = '%s' AND content_id = %d ORDER BY timestamp DESC", $content_type, $content_id);
    while ($flag_content = db_fetch_object($result)) {

      // Build a list of flaggings for all flags by user.
      $content_flags[$content_type][$content_id]['users'][$flag_content->uid][$flag_names[$flag_content->fid]] = $flag_content;

      // Build a list of flaggings for each individual flag.
      $content_flags[$content_type][$content_id]['flags'][$flag_names[$flag_content->fid]][$flag_content->uid] = $flag_content;
    }
  }
  return isset($flag_name) ? $content_flags[$content_type][$content_id]['flags'][$flag_name] : $content_flags[$content_type][$content_id]['users'];
}