I have a View that I'm formatting as a Views Calc table. I am trying to do calculations on six fields. On one field I am trying to do a count, on another an average, & on the other four both a sum & an average. Of these, two of the 'sum & average' fields work; all other fields have blank totals.

There is one exposed filter, filtering by published status of the nodes of the content type being viewed.

The query being generated by Views is (according to the Views preview):

SELECT node.nid AS nid, node.status AS node_status, node.created AS node_created, node.uid AS node_uid, 'node' AS field_data_field_inventory_ticket_serial_node_entity_type, 'node' AS field_data_field_inventory_quality_overall_node_entity_type, 'node' AS field_data_field_total_weight_textiles_node_entity_type, 'node' AS field_data_field_total_weight_paired_shoes_node_entity_type, 'node' AS field_data_field_processed_weight_elec_node_entity_type, 'node' AS field_data_field_inventory_total_weight_node_entity_type
FROM
{node} node
WHERE (( (node.type IN  ('inventory_stocking_ticket')) ))
ORDER BY node_created DESC
LIMIT 50 OFFSET 0

I get the following error messages:

Notice: Undefined property: stdClass::$count__field_data_field_inventory_ticket_serial_node_entity_type in views_calc_table_total() (line 281 of /hosting/somesite/com/htdocs/cms_sandbox/sites/all/modules/views_calc/theme.inc).
Notice: Undefined property: stdClass::$avg__field_data_field_inventory_quality_overall_node_entity_type in views_calc_table_total() (line 281 of /hosting/somesite/com/htdocs/cms_sandbox/sites/all/modules/views_calc/theme.inc).
Notice: Undefined property: stdClass::$avg__field_data_field_total_weight_paired_shoes_node_entity_type in views_calc_table_total() (line 281 of /hosting/somesite/com/htdocs/cms_sandbox/sites/all/modules/views_calc/theme.inc).
Notice: Undefined property: stdClass::$avg__field_data_field_inventory_total_weight_node_entity_type in views_calc_table_total() (line 281 of /hosting/somesite/com/htdocs/cms_sandbox/sites/all/modules/views_calc/theme.inc).
Notice: Undefined property: stdClass::$sum__field_data_field_total_weight_paired_shoes_node_entity_type in views_calc_table_total() (line 281 of /hosting/somesite/com/htdocs/cms_sandbox/sites/all/modules/views_calc/theme.inc).
Notice: Undefined property: stdClass::$sum__field_data_field_inventory_total_weight_node_entity_type in views_calc_table_total() (line 281 of /hosting/somesite/com/htdocs/cms_sandbox/sites/all/modules/views_calc/theme.inc).

Any ideas why this is happening?

Comments

Priority:Major» Normal
Status:Needs review» Active

It seems that Views automatically truncates field alias names to 60 characters. See function views_plugin_query_default::add_field:

<?php
$alias
= strtolower(substr($alias, 0, 60));
?>

So to make Views Calc work with long field names, I had to change $ext_alias = strtolower($calc) . '__' . $query_alias; in theme.inc to the following:

<?php
      $ext_alias
= strtolower($calc) . '__' . $query_alias;
     
$ext_alias = substr($ext_alias, 0, 60);
?>

Works for me, all calculation are now working, no errors in the log.

Priority:Normal» Major
Status:Active» Needs review

I don't know if the change I made is the definitive solution, but maybe someone can take a look at it. Marking as 'needs review'.

rhclato, truncating $alias to 60 chars worked for me too. Rather than add an extra line I just rewrote

<?php
$ext_alias
= strtolower($calc) . '__' . $query_alias;
?>

to

<?php
$ext_alias
= substr(strtolower($calc) . '__' . $query_alias, 0, 60);
?>

...to keep it on one line. It obviously doesn't make a difference. But your solution does work and makes sense to me.

Priority:Normal» Major
Status:Active» Closed (duplicate)

This is a duplicate of https://drupal.org/node/1163514

Issue summary:View changes

typo