You are here

function _flag_lists_update_count in Flag Lists 7

Same name and namespace in other branches
  1. 6 flag_lists.module \_flag_lists_update_count()
  2. 7.3 flag_lists.module \_flag_lists_update_count()

Updates the flag count for this content

2 calls to _flag_lists_update_count()
_flag_lists_flag in ./flag_lists.module
A low-level method to flag content.
_flag_lists_unflag in ./flag_lists.module
A low-level method to unflag content.

File

./flag_lists.module, line 1550
The Flag Lists module.

Code

function _flag_lists_update_count($flag, $content_id) {
  $count = db_select('flag_lists_content', 'f')
    ->fields('f')
    ->condition('fid', $flag->fid)
    ->condition('content_id', $content_id)
    ->countQuery()
    ->execute()
    ->fetchField();
  if (empty($count)) {
    $num_deleted = db_delete('flag_lists_counts')
      ->condition('fid', $flag->fid)
      ->condition('content_id', $content_id)
      ->execute();
  }
  else {
    $num_updated = db_update('flag_lists_counts')
      ->fields(array(
      'count' => $count,
    ))
      ->condition('fid', $flag->fid)
      ->condition('content_id', $content_id)
      ->execute();
    if (empty($num_updated)) {
      db_insert('flag_lists_counts')
        ->fields(array(
        'fid' => $flag->fid,
        'content_type' => $flag->content_type,
        'content_id' => $content_id,
        'count' => $count,
      ))
        ->execute();
    }
  }
}