You are here

function webform_results_download_rows_process in Webform 7.4

Processes the submissions to be downloaded into exported rows.

This is an internal routine and not intended for use by other modules.

Parameters

$node: The webform node on which to generate the analysis.

array $options: A list of options that define the output format. These are generally passed through from the GUI interface.

$serial_start: The starting position for the Serial column in the output.

array $submissions: An associative array of loaded submissions, indexed by sid.

Return value

array An array of rows built according to the provided $serial_start and $pager_count variables. Note that the current page number is determined by the super-global $_GET['page'] variable.

2 calls to webform_results_download_rows_process()
webform_results_batch_rows in includes/webform.report.inc
Batch API callback; Write the rows of the export to the export file.
webform_results_download_rows in includes/webform.report.inc
Returns rows of downloadable webform data.

File

includes/webform.report.inc, line 1156
This file includes helper functions for creating reports for webform.module.

Code

function webform_results_download_rows_process($node, array $options, $serial_start, array $submissions) {
  module_load_include('inc', 'webform', 'includes/webform.components');
  $submission_information = webform_results_download_submission_information($node, $options);

  // Generate a row for each submission.
  $row_count = 0;
  $rows = array();
  foreach ($submissions as $sid => $submission) {
    $row_count++;
    $row = array();

    // Add submission information.
    foreach (array_keys($submission_information) as $token) {
      $cell = module_invoke_all('webform_results_download_submission_information_data', $token, $submission, $options, $serial_start, $row_count);
      $context = array(
        'token' => $token,
        'submission' => $submission,
        'options' => $options,
        'serial_start' => $serial_start,
        'row_count' => $row_count,
      );
      drupal_alter('webform_results_download_submission_information_data', $cell, $context);

      // implode() to ensure everything from a single value goes into one
      // column, even if more than one module responds to this item.
      $row[] = implode(', ', $cell);
    }
    foreach ($options['components'] as $cid) {
      if (isset($node->webform['components'][$cid])) {
        $component = $node->webform['components'][$cid];

        // Let each component add its data.
        $raw_data = isset($submission->data[$cid]) ? $submission->data[$cid] : NULL;
        if (webform_component_feature($component['type'], 'csv')) {
          $data = webform_component_invoke($component['type'], 'csv_data', $component, $options, $raw_data);

          // Allow modules to modify the CSV data.
          drupal_alter('webform_csv_data', $data, $component, $submission);
          if (is_array($data)) {
            $row = array_merge($row, array_values($data));
          }
          else {
            $row[] = isset($data) ? $data : '';
          }
        }
      }
    }
    $rows[$serial_start + $row_count] = $row;
  }
  return $rows;
}