Hi Karen, I love this module, its starting to allow Drupal to act as a kind of spreadsheet application. One thing I'd like to see is some kind of way of storing the result of a Views Calc total in the database. An example of when this would be useful is for a parent child node relationship where the parent needs to be able to display the combined results of one of the child nodes' fields. For example a parent node called Project which can have multiple child nodes, called say Tasks. A Views Calc view displays a table of the child Task nodes with one column calculated, say Cost. This total is then stored in a field called Total Cost in the parent Project node so that it can be displayed in another view, Project Overview, listing all parent Project nodes and their Total Cost field.

Does this make sense? I'm not sure how to implement this, I've done it for a project by hacking the views calc module but it wasn't pretty. I ended up putting my code in the views_calc_calc_view function. It got the current parent node id being viewed from:

$nodeid = node_load(arg(1));
$mynode = $nodeid->nid;

I defined the computed cck field I wanted updating (computed field is stored in db):

$myfield = "field_current_cost_value";

I had to convert the calculated value into an integer or decimal and strip out any formatting (I think, it was a while ago now) using the following:

 $myval = str_replace(",","",$add[$calc_options[$calc]][$field]);
$myval = $myval + 0; 

Then I simply did the following sql:

 db_query("UPDATE content_type_project SET $myfield = $myval WHERE nid = $mynode");

This works fine in my application but I'm sure there is a much cleaner way of going about this. Do you have any thoughts or ideas on this?

Comments

pmford’s picture

I'm hoping to achieve something like this too... I'm using Drupal to put together a sort of pedometer competition site. People log in and post the number of steps walked in a given day. It would be great to be able to compute totals on an individual basis and then display ranked totals in a leader board.

Thanks for the great module!

karens’s picture

Status: Active » Closed (won't fix)

The D5 version is no longer supported.