function flag_reset_flag in Flag 7.2
Same name and namespace in other branches
- 6.2 flag.module \flag_reset_flag()
- 7.3 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 1268 - The Flag module.
Code
function flag_reset_flag($flag, $content_id = NULL) {
$query = db_select('flag_content', 'fc')
->fields('fc')
->condition('fid', $flag->fid);
if ($content_id) {
$query
->condition('content_id', $content_id);
}
$result = $query
->execute()
->fetchAllAssoc('fcid', PDO::FETCH_ASSOC);
$rows = array();
foreach ($result as $row) {
$rows[] = $row;
}
module_invoke_all('flag_reset', $flag, $content_id, $rows);
$query = db_delete('flag_content')
->condition('fid', $flag->fid);
// Update the flag_counts table.
$count_query = db_delete('flag_counts')
->condition('fid', $flag->fid);
if ($content_id) {
$query
->condition('content_id', $content_id);
$count_query
->condition('content_id', $content_id);
}
$count_query
->execute();
return $query
->execute();
}