You are here

function _charts_system_node_activity in Charts 7

Same name and namespace in other branches
  1. 6 charts_system/charts_system.inc \_charts_system_node_activity()

Show which kind of node type was created in the current month.

Return value

String. The HTML chart when all data is fine or a blank string

1 call to _charts_system_node_activity()
_charts_system_charts in charts_system/charts_system.inc
Chart reports page

File

charts_system/charts_system.inc, line 133
@author Bruno Massa http://drupal.org/user/67164 @author TJ (based on his Chart module)

Code

function _charts_system_node_activity() {
  $now = REQUEST_TIME;
  $results = db_query('SELECT type, created
    FROM {node}
    WHERE created < %d AND created > %d
    ORDER BY created', $now, mktime(0, 0, 0, date('m', $now), 1, date('Y', $now)));
  $max = array();
  $counts = array();
  $types = array();
  $type = 0;
  foreach ($results as $result) {
    $day = ltrim(date('d', $result->created), '0');
    $types[$result->type] = $type++;
    if (isset($counts[$day][$result->type])) {
      $counts[$day][$result->type]++;
    }
    else {
      $counts[$day][$result->type] = 1;
    }
  }

  // Generate data and labels
  if (!empty($counts)) {
    foreach ($types as $type => $index) {
      $chart[$type]['#legend'] = $type;
      for ($i = 1; $i <= date('d', $now); $i++) {
        $chart[$type][] = array(
          '#value' => empty($counts[$i][$type]) ? 0 : $counts[$i][$type],
          '#label' => $i,
        );
      }
    }
    $chart['#title'] = t('Activity for !date', array(
      '!date' => date('F Y', $now),
    ));
    $chart['#type'] = 'line2D';
    return charts_chart($chart);
  }
  return '';
}