You are here

function theme_spaces_casestats in Spaces 5.2

Same name and namespace in other branches
  1. 5 spaces_casetracker/spaces_casetracker.module \theme_spaces_casestats()
1 theme call to theme_spaces_casestats()
spaces_casetracker_block in spaces_casetracker/spaces_casetracker.module
Implementation of hook_block()

File

spaces_casetracker/spaces_casetracker.module, line 385

Code

function theme_spaces_casestats($stats, $username) {
  drupal_add_css(drupal_get_path('module', 'spaces') . '/spaces.css');
  $labels = array(
    array(
      'data' => t('Assigned to !user', array(
        '!user' => $username,
      )),
      'colspan' => 2,
      'class' => 'halfpoint',
    ),
    array(
      'data' => t('Created by !user', array(
        '!user' => $username,
      )),
      'colspan' => 2,
    ),
  );
  $rows[] = array(
    array(
      'data' => t('This Week'),
      'colspan' => 2,
      'class' => 'header halfpoint',
    ),
    array(
      'data' => t('This Week'),
      'colspan' => 2,
      'class' => 'header',
    ),
  );
  $rows[] = array(
    _spaces_casestats_count(t('Open'), $stats['assigned']['week_open']),
    array(
      'data' => _spaces_casestats_count(t('Closed'), $stats['assigned']['week_closed']),
      'class' => 'halfpoint',
    ),
    _spaces_casestats_count(t('Open'), $stats['created']['week_open']),
    _spaces_casestats_count(t('Closed'), $stats['created']['week_closed']),
  );
  $rows[] = array(
    array(
      'data' => t('Total'),
      'colspan' => 2,
      'class' => 'header halfpoint',
    ),
    array(
      'data' => t('Total'),
      'colspan' => 2,
      'class' => 'header',
    ),
  );
  $rows[] = array(
    _spaces_casestats_count(t('Open'), $stats['assigned']['total_open']),
    array(
      'data' => _spaces_casestats_count(t('Closed'), $stats['assigned']['total_closed']),
      'class' => 'halfpoint',
    ),
    _spaces_casestats_count(t('Open'), $stats['created']['total_open']),
    _spaces_casestats_count(t('Closed'), $stats['created']['total_closed']),
  );
  $o = theme('table', $labels, $rows, array(
    'class' => 'casestats',
  ));

  /*** Breakdown ***/
  if ($stats['created']['breakdown']) {
    $total = array_sum($stats['created']['breakdown']);
    foreach ($stats['created']['breakdown'] as $label => $count) {
      $pct = floor($count / $total * 1000) * 0.1;
      $breakdown[] = "<span class='pct'>{$pct}%</span> " . t('in') . " {$label}";
    }
    $breakdown = implode(', ', $breakdown) . ".";
    $breakdown = "<div class='case-breakdown'><span class='label'>" . t('Cases created:') . "</span>{$breakdown}</div>";
  }
  return $o . $breakdown;
}