You are here

function theme_memcache_admin_stats_raw_table in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 modules/memcache/memcache_admin/memcache_admin.module \theme_memcache_admin_stats_raw_table()
1 theme call to theme_memcache_admin_stats_raw_table()
memcache_admin_stats_raw in modules/memcache/memcache_admin/memcache_admin.module

File

modules/memcache/memcache_admin/memcache_admin.module, line 439

Code

function theme_memcache_admin_stats_raw_table($variables) {
  $cluster = $variables['cluster'];
  $server = $variables['server'];
  $stats = $variables['stats'];
  $current_type = isset($variables['type']) ? $variables['type'] : 'default';
  $memcache_bins = variable_get('memcache_bins', array());
  $bin = isset($memcache_bins[$cluster]) ? $memcache_bins[$cluster] : 'default';

  // Provide navigation for the various memcache stats types
  if (count(memcache_admin_stats_types($bin)) > 1) {
    foreach (memcache_admin_stats_types($bin) as $type) {
      if ($current_type == $type) {
        $links[] = '<strong>' . l(t($type), "admin/reports/memcache/{$bin}/{$server}/" . ($type == 'default' ? '' : $type)) . '</strong>';
      }
      else {
        $links[] = l(t($type), "admin/reports/memcache/{$bin}/{$server}/" . ($type == 'default' ? '' : $type));
      }
    }
  }
  $output = !empty($links) ? implode($links, ' | ') : '';
  $headers = array(
    t('Property'),
    t('Value'),
  );
  $rows = array();

  // Items are returned as an array within an array within an array.  We step
  // in one level to properly display the contained statistics.
  if ($current_type == 'items' && isset($stats['items'])) {
    $stats = $stats['items'];
  }
  foreach ($stats as $key => $value) {

    // Add navigation for getting a cachedump of individual slabs
    if (($current_type == 'slabs' || $current_type == 'items') && is_int($key) && user_access('access slab cachedump')) {
      $key = l($key, "admin/reports/memcache/{$bin}/{$server}/slabs/cachedump/{$key}");
    }
    if (is_array($value)) {
      $rs = array();
      foreach ($value as $k => $v) {

        // Format timestamp when viewing cachedump of individual slabs.
        if ($current_type == 'slabs' && user_access('access slab cachedump') && arg(6) == 'cachedump' && $k == 0) {
          $k = t('Size');
          $v = format_size($v);
        }
        else {
          if ($current_type == 'slabs' && user_access('access slab cachedump') && arg(6) == 'cachedump' && $k == 1) {
            $k = t('Expire');
            $full_stats = dmemcache_stats($cluster, 'default');
            $infinite = $full_stats[$cluster][$server]['time'] - $full_stats[$cluster][$server]['uptime'];
            if ($v == $infinite) {
              $v = t('infinite');
            }
            else {
              $v = t('in @time', array(
                '@time' => format_interval($v - time()),
              ));
            }
          }
        }
        $rs[] = array(
          check_plain($k),
          check_plain($v),
        );
      }
      $rows[] = array(
        $key,
        theme('table', array(
          'rows' => $rs,
        )),
      );
    }
    else {
      $rows[] = array(
        check_plain($key),
        check_plain($value),
      );
    }
  }
  $output .= theme('table', array(
    'header' => $headers,
    'rows' => $rows,
  ));
  return $output;
}