You are here

function apachesolr_stats_report in Apache Solr Statistics 6

Same name and namespace in other branches
  1. 6.3 apachesolr_stats.module \apachesolr_stats_report()
  2. 7 apachesolr_stats.module \apachesolr_stats_report()

Callback for admin/reports/apachesolr/stats.

Parameters

string $granularity: Granularity to use for report.

Return value

string The page output as HTML.

See also

apachesolr_stats_menu()

1 string reference to 'apachesolr_stats_report'
apachesolr_stats_menu in ./apachesolr_stats.module
Implementation of hook_menu().

File

./apachesolr_stats.module, line 361
Keeps and reports statistics about Apache Solr usage and performance.

Code

function apachesolr_stats_report($picked_granularity = "minute") {
  drupal_set_title(t("Apache Solr statistics report"));
  if (!variable_get('apachesolr_stats_enabled', 0)) {
    return t('Logging is disabled in the !link. Enable it to log Apache Solr queries.', array(
      '!link' => l('module configuration page', 'admin/settings/apachesolr/stats'),
    ));
  }
  $granularities = apachesolr_stats_get_granularities();

  // Decide what granularity to use: minute, hour or day
  // Check if given argument exists; if not, reset to "hour"
  if (!isset($granularities[$picked_granularity])) {
    $picked_granularity = "minute";
  }
  $granularity = $granularities[$picked_granularity];

  // Process latest log entries
  $report_elements = apachesolr_stats_generate_report_elements($granularity);

  // Create the output HTML:::::::::::::::::::::::::::::::::::::
  // Granularity picker:
  // Leave only those less than apachesolr_stats_flush_log_timer
  $timer_max = variable_get('apachesolr_stats_flush_log_timer', 259200);
  $output = "<div class='granularity'>" . t('Choose the report time span:');
  foreach ($granularities as $name => $granularity) {
    if ($name != "all" && $granularity['time_before'] > $timer_max) {
      continue;
    }
    $output .= " &nbsp; ";
    if ($name != $picked_granularity) {
      $output .= l($granularity["last_msg"], "admin/reports/apachesolr/stats/{$name}");
    }
    else {
      $output .= "<strong>" . $granularity["last_msg"] . "</strong>";
    }
  }
  $output .= "</div><hr>";
  if ($report_elements) {

    // Report description
    $output .= t('This is an overview of Apache Solr usage and performance.');
    $output .= ' ' . t('You can also visit the !settingslink.', array(
      '!settingslink' => l(t('settings page'), 'admin/settings/apachesolr/stats'),
    ));

    // Add Google Gadgets embedding link
    $key = variable_get("apachesolr_stats_gadget_key", "");
    if ($key) {
      $gadget_url = url("apachesolr_stats/gadget/{$key}", array(
        'absolute' => TRUE,
      ));
      $gadget_embed_html = '<a href="http://fusion.google.com/add?source=atgs&moduleurl=' . urlencode($gadget_url) . '"><img src="http://buttons.googlesyndication.com/fusion/add.gif" border="0" alt="' . t('Add to Google') . '"></a>';
      $output .= "<div style='text-align:right'>" . l(t('Embed as Google Gadget'), "http://www.google.com/ig/adde?moduleurl=" . urlencode($gadget_url)) . " {$gadget_embed_html}</div>";
    }

    // Render report elements
    foreach ($report_elements as $id => $data) {

      // Table data
      $rows[] = array(
        "data" => array(
          array(
            'data' => $data['name'],
            'header' => true,
            'style' => 'width:33%',
          ),
          array(
            'data' => $data['value'],
          ),
        ),
      );
    }
    $output .= theme('table', array(), $rows);
  }
  else {
    drupal_set_message(t('There is not enough stored data to build a report.'));
  }
  return $output;
}