1

Im looking for a way to store the TOTAL number of nodes published on my drupal 6 web site at a particular month of the year so I can generate some curve from it :

timestamp | total node nb type x
2013/01   | 96
2013/02   | 100 (I mean 96+4, cumulative)
2013/03   | 120
[...]

the need seems simple to me, but I cant find any statistics module that cares about this. also the need is really simple compared to the features these modules offer. I could write some piece of code about this using CRON and some requests to write such a table. maybe something with views count + cron.

but it certainly already exists somewhere as a module ?

thanks for any pointers/recipes.

jerome

3 Answers 3

2

Do you really need the publishing date? or just the created date?

If you need the former, well that date isn't tracked by core - http://drupal.org/node/1838918

You could try a contrib module to start tracking that for you... http://drupal.org/project/publication_date

If you're not worried about deleted nodes you can just do what you're after by running a query to count all the nodes that have a created date lower than month X. Or just get all nodes back, and then loop over them in php, successively incrementing counters for each month for your graph.

Otherwise, yeah you're going to have to do something with cron and get snapshots over time. I haven't heard of an existing offering for this in contrib.

0
1

You should give a try at the Count module :

The Count Nodes Module counts total number of nodes created (published and unpublished both) in each content type. It provide a total number of blocks equals to the total number of content types created such that administrator can use one block for each content type.

The Count Nodes module also provide a text box in each block to do a manual entry of total nodes. It helps administrator to show less or more count of actual nodes.

6
  • thanks I'll try it, but it seems it does exactly the same than a view that get a node type with > display as 'views calc table' style in count mode. I would need to store these values in some table.
    – jerome
    Jan 22, 2013 at 14:14
  • uuuh, doesn't this module just get the current number of nodes? OP is asking for snapshots over time to help with graphing. Jan 22, 2013 at 14:15
  • yep. (what is OP ? sry noob)
    – jerome
    Jan 22, 2013 at 14:17
  • Original Poster/Original Post Jan 22, 2013 at 14:20
  • I got the beginning of something with this : tylerfrankenstein.com/code/…
    – jerome
    Jan 22, 2013 at 14:38
1

for this purpose, unfortunately, I cant find my way yet using views or this module http://drupal.org/project/views_groupby (it doesnt work when using date published field even using field rewrite).

so here is a snippet I wrote that can be pasted in a block (you need php input).

this generates a table with 3 columns : year/month, node created / month, total (cumulative). change the nod type and drupal table preffix by yours.

<?php
  $header = array('month','compte','total');
  $rows = array();
  $total = 0;

  $query = "SELECT 
    DATE_FORMAT((FROM_UNIXTIME(node.created) + INTERVAL 3600 SECOND), '%Y/%m') AS node_created_month,
    COUNT(node.nid) AS node_count
    FROM <db>_node node 
    WHERE node.type in ('<nodetype>')
    GROUP BY node_created_month
    ORDER BY node_created_month ASC";

  $results = db_query($query);

  while ($fld = db_fetch_object($results)) {
    $total += $fld->node_count;
    $rows[] = array(
      $fld->node_created_month,
      $fld->node_count,
      $total
    );
  }

  return theme('table', $header, $rows);
?>

using the google chart api module http://drupal.org/project/chart one can also generate a chart using the same query.

    <?php
    // retrieve datas
      $query = "SELECT 
        DATE_FORMAT((FROM_UNIXTIME(node.created) + INTERVAL 3600 SECOND), '%Y/%m') AS node_created_month,
        COUNT(node.nid) AS node_count
        FROM <db>_node node 
        WHERE node.type in ('<nodetype>')
        GROUP BY node_created_month
        ORDER BY node_created_month ASC";

      $results = db_query($query);

      // prepare chart layout
      $chart = array(
          '#chart_id' => 'test_chart',
          '#title' => chart_title(t('blahblah'), 'cc0000', 15),
          '#type' => CHART_TYPE_LINE,
          '#size' => chart_size(545, 300),
          '#adjust_resolution' => TRUE,
          '#chart_fill' => chart_fill('c', 'eeeeee'),          
          '#grid_lines' => chart_grid_lines(20, 20, 1, 5),
      );

      $chart['#legends'][] = '<nodetype>';
      $chart['#data_colors'][] = '00ff00';

      $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][1][] = chart_mixed_axis_label(t('nombre lieux'), 50);

      $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][2][] = chart_mixed_axis_label(t('temps'), 50);

      // inject datas into chart arrays
      $total = 0;
      while ($fld = db_fetch_object($results)) {
        $total = $total + $fld->node_count;
        $chart['#data']['<nodetype>'][] = $total;  
        $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label( $fld->node_created_month );
      };

      $chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][0][] = chart_mixed_axis_range_label(0, $total);
      echo chart_render($chart);
    ?>

the generated graph png can be saved, and block is cachable so I wonder if its valuable to investigate about cron and add results to an existing sql table rather than to regenerate the whole thing, but well, that's a start.

1
  • one also needs to add the months where there was no node creations in the arrays. just ask if you need it I'll publish. pending : reseau-alpha.org/statistiques
    – jerome
    Jan 23, 2013 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.