Hello,
I'm trying to use your module with the CCK Computed module to create a timesheet application. However, when I run the code
$node_field[0]['value'] = $field->field_weekly[1][2]['value'] - $field->field_weekly[1][1]['value'];
in the CCK Computer field, it does not store a value in the database or display the value after the page is saved. The same code did work with a simple integer field type.

Comments

mh86’s picture

I've never tried this and I'm not familiar with the cck computed field module, but you have to address the values of the matrix field without the 'value' at the end, e.g. it's only $field->field_weekly[1][2]
Hope this helps you!

hsfdrupal’s picture

Hm, I can't get this to work either.

Shouldn't the code be $node->field_weekly[1][2]? What is $field?

mira2’s picture

I was just wondering if you could work out these 2 together? I need to create a timesheet type of field where hours entered for different tasks could be computed and outputed on the page for users' consultation. Any success yet?

reubenavery’s picture

I can confirm that Matrix Field does not work with with Computed Fields. I am not sure why, but I have confirmed that the $node object passed to the computation function for a field does not include the node's matrix field. I had to end up writing a sql query to get at the matrix field's values.

Rosamunda’s picture

Category: support » feature

Suscribing.

aaron1234nz’s picture

Status: Active » Closed (won't fix)

I would be very surprised if this module could be used with computed fields. The architecture doesn't lend itself that way. I'm marking this as a "won't fix" because I don't think its possible, at least not without masses of work.

ericatkins’s picture

How would one calculate the integers in the first column of a Matrix? Would that be done in the Content Type with some other kind of CCK object? Or would that be done in the body with some PHP code? And could that value be stored in the database and referenced later with Views?

I'm at a loss on how to do the questions I've asked above.

aaron1234nz’s picture

Title: Compatible with CCK Computed? » Computed values
Version: 5.x-1.0 » 6.x-1.x-dev
Status: Closed (won't fix) » Active

I would suggest using php code to do this.

I would start with this code. It will show you what you have to play with

print_r($node);

I think (off the top of my head) that you want to use $node->yourfieldname[0]['data'][$i][$j] where $i is the row number and $j is the column number. To sum a column you would write something like

  $column_of_interest = 1;
  $field_data = $node->yourfieldname[0]['data'];
  foreach($field_data as $row) {
    $sum += $row[$column_of_interest];
  } 
  echo $sum;

Note this is only psudo code and is not tested.

This data would not be available to views.

Note: I'm doing a bit of work on Matrix version 2 which will allow for select boxes, checkboxes, radio buttons, and textfields. Maybe I could calculations to this list too. I'll give it some thought

ericatkins’s picture

Thanks aaron1234nz.

If you add a 'calculated value' feature to the 'Matrix Field' CCK type, you'll have to rename your module to CCK Spreadsheet.

That's what it would nearly be, a Spreadsheet.

aaron1234nz’s picture

I'm not quite going to go as far as turning this module into a spreadsheet. That would take a LOT more work. Have you seen this module? http://drupal.org/project/sheetnode it might be of use to you.

aaron1234nz’s picture

Status: Active » Fixed

This functionality is implemented (in a fairly basic form only) in version 2. Please open a new issue if you wish to discuss an aspect of this functionality.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Stomper’s picture

Glad to hear that some level of computation is supported. I too am seeking simple summation computation. The Sheetnode module you suggested may be overkill for my application.

Does the Matrixfield demonstration (link on project page http://sandbox.webtolife.org/) include this computed field feature?

Thanks