You are here

function _charts_system_node_activity in Charts 6

Same name and namespace in other branches
  1. 7 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 = 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();
  while ($result = db_fetch_array($results)) {
    $day = ltrim(date('d', $result['created']), '0');
    $types[$result['type']] = $type++;
    $counts[$day][$result['type']]++;
  }

  // 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 '';
}