Views Calc support in export

repolainen - May 21, 2009 - 22:41
Project:Views Calc
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi,

I tried to export some Views Calc -tables with no good results. The subtotals & totals are not included in the exports.

I took a look at the views_calc_table.inc -file in the module and found the following piece of code:

      // Add sub_total rows to the results.
      foreach ($calc_fields as $calc => $field) {
        if ($summary_view = views_get_view($this->view->name)) {
          $summary_view->set_display($this->view->current_display);
          $summary_view->set_arguments($this->view->args);
          $summary_view->views_calc_calculation = $calc;
          $summary_view->views_calc_nids = $nids;
          $summary_view->views_calc_sub_total = TRUE;
          $summary_view->is_cacheable = FALSE;
          $summary_view->execute();
          $this->view->sub_totals[] = array_shift($summary_view->result);
        }
      }
    }
   
    // Add grand totals to the results.
    foreach ($calc_fields as $calc => $field) {
      if ($summary_view = views_get_view($this->view->name)) {
        $summary_view->set_display($this->view->current_display);
        $summary_view->set_arguments($this->view->args);
        $summary_view->pager['items_per_page'] = 0;
        $summary_view->views_calc_calculation = $calc;
        $summary_view->views_calc_nids = array();
        $summary_view->views_calc_sub_total = FALSE;
        $summary_view->is_cacheable = FALSE;
        $summary_view->execute();
        $this->view->totals[] = array_shift($summary_view->result);
      }
    }
  }

As I understand the code, this indicates that the subtotal-rows are located in the view->subtotals array and totals in view->totals.

Taking a look at the views_bonus_export.module code:

function _views_bonus_export_shared_preprocess(&$vars) {
  $view     = $vars['view'];
  $fields   = &$view->field;

which would indicate that we're using just the fields, but not going through the whole view-object. Should there be something like $subtotals = &$view->subtotals and $totals = &$view->totals ?

I believe this is quite simple to do, if you know what you're doing. Am I on the right track here on how to implement this views calc integration? How should we proceed?

#1

Rosamunda - May 23, 2009 - 12:14

subscribing.

#2

neclimdul - July 23, 2009 - 00:31
Category:bug report» feature request

Not really familiar with views calc to say...

Views bonus export styles uses the fields that views provides to provide simple rows for building feeds. If Views Calc isn't using fields(I'm not sure how it would) then it probably won't be very feasible to directly support it. However, you can write your own preprocess hook to add in this information, just make sure you module has a weight that makes it run after views_bonus_export.

That said, patches are welcome if you've got an idea.

#3

Rosamunda - July 24, 2009 - 14:54
Project:Views Bonus Pack» Views Calc
Version:6.x-1.x-dev» 6.x-1.x-dev
Component:Views Export» Code

Maybe this could be asked in the views calc issue queue...

 
 

Drupal is a registered trademark of Dries Buytaert.