From 857506f65bb11d0f21a5b6577a4df2299b5a9919 Mon Sep 17 00:00:00 2001
From: Bruno Massa <brmassa@67164.no-reply.drupal.org>
Date: Mon, 17 Mar 2008 23:33:19 +0000
Subject: [PATCH] New features: * _charts_system_node_activity() shows which
 kind of node type was created in the current month

---
 charts_system/charts_system.inc | 56 +++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/charts_system/charts_system.inc b/charts_system/charts_system.inc
index 2cfe523..15e6693 100644
--- a/charts_system/charts_system.inc
+++ b/charts_system/charts_system.inc
@@ -7,9 +7,9 @@
  */
 
 /**
- * Page callback.
+ * Chart reports page
  */
-function _charts_system_charts($ctype = 'nodes') {
+function _charts_system_charts($ctype) {
   $output = '';
 
   switch ($ctype) {
@@ -37,6 +37,7 @@ function _charts_system_charts($ctype = 'nodes') {
         GROUP BY type
         ORDER BY type"
       );
+      $output .= _charts_system_node_activity();
       break;
 
     case 'users':
@@ -83,7 +84,7 @@ function _charts_system_charts($ctype = 'nodes') {
 }
 
 /**
- * Translate the user status label code to a string
+ * Generate some charts using a pre defined method.
  *
  * @param $title
  *   String. The chart title
@@ -123,6 +124,55 @@ function _charts_system_generate($title, $sql, $callback = NULL) {
   return '';
 }
 
+/**
+ * Show which kind of node type was created in the current month.
+ *
+ * @return
+ *   String. The HTML chart when all data is fine or a blank string
+ */
+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'];
+    $counts[$day][$result['type']]++;
+  }
+
+  // Generate data and labels
+  if (!empty($counts)) {
+    for ($i = 1; $i <= date('d', $now); $i++) {
+      foreach ($types as $index => $type) {
+        $chart[$index]['#legend'] = $type;
+        $chart[$index][] = array(
+          '#value'  => empty($counts[$i][$type]) ? 0 : $counts[$i][$type],
+          '#label'  => empty($index) ? $i : NULL
+        );
+      }
+    }
+  }
+
+  if (!empty($chart)) {
+    $chart['#title']    = t('Activity for !date', array('!date' => date('F Y', $now)));
+    $chart['#type']     = 'line2D';
+
+    return charts_chart($chart);
+  }
+
+  return '';
+}
+
 /**
  * Translate the user status label code to a string
  *
-- 
GitLab