You are here

function flag_reset_flag in Flag 6.2

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

Remove all flagged content from a flag.

Parameters

$flag: The flag object.

$content_id: Optional. The content ID on which all flaggings will be removed. If left empty, this will remove all of this flag's content.

File

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

Code

function flag_reset_flag($flag, $content_id = NULL) {
  $result = db_query("SELECT * FROM {flag_content} WHERE fid = %d" . ($content_id ? " AND content_id = %d" : ''), $flag->fid, $content_id);
  $rows = array();
  while ($row = db_fetch_array($result)) {
    $rows[] = $row;
  }
  module_invoke_all('flag_reset', $flag, $content_id, $rows);

  // Update the flag_counts table.
  db_query("DELETE FROM {flag_counts} WHERE fid = %d" . ($content_id ? " AND content_id = %d" : ''), $flag->fid, $content_id);
  db_query("DELETE FROM {flag_content} WHERE fid = %d" . ($content_id ? " AND content_id = %d" : ''), $flag->fid, $content_id);
  return db_affected_rows();
}