You are here

function spam_logs_statistics in Spam 6

Same name and namespace in other branches
  1. 5.3 spam.module \spam_logs_statistics()

Display statistics overview.

1 string reference to 'spam_logs_statistics'
spam_menu in ./spam.module
Drupal _menu() hook.

File

./spam.module, line 1920
Spam module, v3 Copyright(c) 2006-2008 Jeremy Andrews <jeremy@tag1consulting.com>. All rights reserved.

Code

function spam_logs_statistics() {
  drupal_set_title("Spam statistics");
  $statistics = array();
  $stats = array(
    array(
      'title' => 'scanned @module',
      'query' => 'scan %s',
    ),
    array(
      'title' => 'prevented @module spam',
      'query' => 'prevented spam %s',
    ),
    array(
      'title' => 'marked @module as spam',
      'query' => '%s marked as spam',
    ),
    array(
      'title' => 'manually marked @module as spam',
      'query' => '%s manually marked as spam',
    ),
    array(
      'title' => 'marked @module as not spam',
      'query' => '%s marked as not spam',
    ),
    array(
      'title' => 'manually marked @module as not spam',
      'query' => '%s manually marked as not spam',
    ),
  );
  $header = array(
    '',
    t('Action'),
    t('Count'),
    t('Last'),
  );
  $displayed = array();
  $modules = spam_invoke_api('content_module');
  foreach ($modules as $module) {
    foreach ($stats as $stat) {
      $query = str_replace('@name', $stat['query'], "SELECT * FROM {spam_statistics} WHERE name = '@name'");
      if ($result = db_fetch_object(db_query($query, $module))) {
        $row = array();
        if (!isset($displayed[$module])) {
          $displayed[$module] = TRUE;
          $row[] = array(
            'data' => "<b>{$module}</b>",
            'colspan' => 4,
          );
          $rows[] = $row;
          $row = array();
        }
        $row[] = '';
        $row[] = array(
          'data' => t($stat['title'], array(
            '@module' => $module,
          )),
        );
        $row[] = array(
          'data' => number_format($result->count),
        );
        $row[] = array(
          'data' => t('@time ago', array(
            '@time' => format_interval(time() - $result->timestamp),
          )),
        );
        $rows[] = $row;
      }
    }
  }
  $output = theme('table', $header, $rows);
  return $output;
}