You are here

function flag_trim_flag in Flag 7.2

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

Trim a flag to a certain size.

Parameters

$fid: The flag object.

$account: The user object on behalf the trimming will occur.

$cutoff_size: The number of flaggings allowed. Any flaggings beyond that will be trimmed.

1 call to flag_trim_flag()
flag_rules_action_trim in ./flag.rules.inc
Base action implementation: Trim flag.

File

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

Code

function flag_trim_flag($flag, $account, $cutoff_size) {
  $result = db_select('flag_content', 'fc')
    ->fields('fc')
    ->condition('fid', $flag->fid)
    ->condition(db_or()
    ->condition('uid', $account->uid)
    ->condition('uid', 0))
    ->orderBy('timestamp', 'DESC')
    ->execute();
  $i = 1;
  foreach ($result as $row) {
    if ($i++ > $cutoff_size) {
      flag('unflag', $flag->name, $row->content_id, $account);
    }
  }
}