You are here

function _flag_lists_update_count in Flag Lists 7.3

Same name and namespace in other branches
  1. 6 flag_lists.module \_flag_lists_update_count()
  2. 7 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 1626
The Flag Lists module.

Code

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