function flag_reset_flag in Flag 7.3
Same name and namespace in other branches
- 6.2 flag.module \flag_reset_flag()
- 7.2 flag.module \flag_reset_flag()
Remove all flagged entities from a flag.
Parameters
$flag: The flag object.
$entity_id: (optional) The entity ID on which all flaggings will be removed. If left empty, this will remove all of this flag's entities.
File
- ./
flag.module, line 2333 - The Flag module.
Code
function flag_reset_flag($flag, $entity_id = NULL) {
$query = db_select('flagging', 'fc')
->fields('fc')
->condition('fid', $flag->fid);
if ($entity_id) {
$query
->condition('entity_id', $entity_id);
}
$result = $query
->execute()
->fetchAllAssoc('flagging_id', PDO::FETCH_ASSOC);
$rows = array();
foreach ($result as $row) {
$rows[] = $row;
}
module_invoke_all('flag_reset', $flag, $entity_id, $rows);
$query = db_delete('flagging')
->condition('fid', $flag->fid);
// Update the flag_counts table.
$count_query = db_delete('flag_counts')
->condition('fid', $flag->fid);
if ($entity_id) {
$query
->condition('entity_id', $entity_id);
$count_query
->condition('entity_id', $entity_id);
}
$count_query
->execute();
return $query
->execute();
}