You are here

function _flag_lists_update_count in Flag Lists 6

Same name and namespace in other branches
  1. 7.3 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 1080
The Flag Lists module.

Code

function _flag_lists_update_count($flag, $content_id) {
  $count = db_result(db_query("SELECT COUNT(*) FROM {flag_lists_content} WHERE fid = %d AND content_id = %d", $flag->fid, $content_id));
  if ($count == 0) {
    db_query("DELETE FROM {flag_lists_counts} WHERE fid = %d AND content_id = %d", $flag->fid, $content_id);
  }
  else {
    db_query("UPDATE {flag_lists_counts} SET count = %d WHERE fid = %d AND content_id = %d", $count, $flag->fid, $content_id);
    if (!db_affected_rows()) {
      db_query("INSERT INTO {flag_lists_counts} (fid, content_type, content_id, count) VALUES (%d, '%s', %d, %d)", $flag->fid, $flag->content_type, $content_id, $count);
    }
  }
}