You are here

function flag_flag::_decrease_count in Flag 7.3

Same name and namespace in other branches
  1. 6.2 flag.inc \flag_flag::_decrease_count()
  2. 7.2 flag.inc \flag_flag::_decrease_count()

Decreases the flag count for an object and clears the static counts cache.

@private

Parameters

int $entity_id: For which item should the count be descreased.

int $number: The amount of counts to decrease. Defaults to 1.

1 call to flag_flag::_decrease_count()
flag_flag::flagging_delete in includes/flag/flag_flag.inc
Unflag an entity by deleting a Flagging.

File

includes/flag/flag_flag.inc, line 1107
Contains the flag_flag class. Flag type classes use an object oriented style inspired by that of Views 2.

Class

flag_flag
This abstract class represents a flag, or, in Views 2 terminology, "a handler".

Code

function _decrease_count($entity_id, $number = 1) {

  // Delete rows with count 0, for data consistency and space-saving.
  // Done before the db_update() to prevent out-of-bounds errors on "count".
  db_delete('flag_counts')
    ->condition('fid', $this->fid)
    ->condition('entity_id', $entity_id)
    ->condition('count', $number, '<=')
    ->execute();

  // Update the count with the new value otherwise.
  db_update('flag_counts')
    ->expression('count', 'count - :inc', array(
    ':inc' => $number,
  ))
    ->fields(array(
    'last_updated' => REQUEST_TIME,
  ))
    ->condition('fid', $this->fid)
    ->condition('entity_id', $entity_id)
    ->execute();

  // Reset the static cache of flag counts, so code running after this gets
  // correct counts.
  drupal_static_reset('flag_get_counts');
  drupal_static_reset('flag_get_flag_counts');
}