You are here

function antispam_set_counter in AntiSpam 7

Same name and namespace in other branches
  1. 6 antispam.module \antispam_set_counter()

Set today's counter value for the specified counter type.

1 call to antispam_set_counter()
antispam_increase_counter in ./antispam.module
Increase today's counter value for the specified counter type by 1.

File

./antispam.module, line 291
Primary hook implementations for the Antispam module.

Code

function antispam_set_counter($counter_type, $count) {
  switch ($counter_type) {
    case ANTISPAM_COUNT_ALL:
      return;
    case ANTISPAM_COUNT_SPAM_DETECTED:
      $field = 'spam_detected';
      break;
    case ANTISPAM_COUNT_HAM_DETECTED:
      $field = 'ham_detected';
      break;
    case ANTISPAM_COUNT_FALSE_NEGATIVE:
      $field = 'false_negative';
      break;
    case ANTISPAM_COUNT_FALSE_POSITIVE:
      $field = 'false_positive';
      break;
    default:
      return;
  }
  $today = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  $result = db_query("SELECT * FROM {antispam_counter} WHERE date=:date", array(
    ':date' => $today,
  ));
  if ($result
    ->rowCount()) {

    // Update.
    db_update('antispam_counter')
      ->fields(array(
      $field => $count,
    ))
      ->condition('date', $today)
      ->execute();
  }
  else {

    // Insert.
    $provider = antispam_get_service_provider();
    db_insert('antispam_counter')
      ->fields(array(
      'date' => strtotime(date('Y-m-d 00:00:00')),
      'provider' => $provider,
      $field => $count,
    ))
      ->execute();
  }
}