I've managed to create a CCK computed field to calculate a 'current depreciated value' for an asset node. (see http://drupal.org/node/126530) This works fine in the node view by using the current time() function when the page is loaded, but the only way to pass this value to a (asset summary) view would be to save the value in the database. If saved in the database, however, the value will only update each time the node is resubmitted and not when the view is loaded :(
So what I'm thinking is to create a views_calc 'column' field that will use the node data fields, but perform the up-to-date calculation when the view is loaded. In other words, to build a custom coded views calc field :)
Does that sound feasible ?
It would be very useful and encourage timid drupaleers to write mini PHP scripts ;)
Comments
Comment #1
JohnG-1 commentedI'm a non-programmer, but the custom code widget I'm thinking of is in the CCK computed field module. Perhaps someone clever could rip some code from there ... ?
This would be a very useful feature, wouldn't it?
Comment #2
karens commentedI agree that this could be useful if someone wants to dig into it. I'm doing some work on Views Calc now and I'll investigate this, but it might not be easy to do, so no promises :)
Comment #3
karens commentedThere are two issues here, really. One is that the computed field module does not store its data in the database so we cannot pick it up in Views Calc. The other is that it would be nice to have a way to create a custom field to combine various Views fields in different ways.
The first is going to be a problem because Views Calc does it's work in the database using SQL. The computed field module does its work in PHP and requires that we do a node_load() on each node to get it to populate the value, a process that is going to slow things down quite a bit. Once that value is calculated, we would then have to re-compute the entire page to use those new values. So basically, making it possible for that kind of field to work will make all other kinds of fields and computations much less efficient than they could be. So that's going to have to be postponed for now.
The second is similar to the request at http://drupal.org/node/104639, to have a way to create custom fields to do various computations that will work in Views Calc. I just committed some changes to the code to make that one possible and put the changes in the development version. The stable version of this module still has the original code.
Changing the name to match the remaining issue.
Comment #4
karens commentedThe custom field should be working.