You are here

function flag_flag::_decrease_count in Flag 7.2

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

Decreases the flag count for a piece of content.

@private

Parameters

$content_id: For which item should the count be descreased.

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

1 call to flag_flag::_decrease_count()
flag_flag::_unflag in ./flag.inc
A low-level method to unflag content.

File

./flag.inc, line 882
Implements various flags. Uses 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($content_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('content_id', $content_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('content_id', $content_id)
    ->execute();
}