You are here

function webform_chart_page in Webform Chart 7.2

Same name and namespace in other branches
  1. 7 webform_chart.charting.inc \webform_chart_page()

Provides graphical analysis of all submissions to a webform.

By adding checks for 'grid' and 'table_element' - type components that have either insufficent analysis formatting or no analysis callbacks at all, we can shoe-horn in our own analysis formatting functions by switching the callback from 'analysis' to 'chart_analysis'. Return handling needed to be modified for these elements as well since these functions return arrays of questions/answers, not single questions/answers.

This also differs from the webform core results formatter by sending forward the component along with the analysis data to the theme function in the main data array. This provides additional functionality down stream in the theme functions.

Parameters

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

array $sids: An array of submission IDs to which this analysis may be filtered. May be used to generate results that are per-user or other groups of submissions.

String $analysis_component : A webform component. If passed in, additional information may be returned relating specifically to that component's analysis, such as a list of "Other" values within a select list.

1 string reference to 'webform_chart_page'
webform_chart_menu in ./webform_chart.module
Implements hook_menu().

File

./webform_chart.charting.inc, line 35
Provides result page functions for the webform_chart module

Code

function webform_chart_page($node, $sids = array(), $analysis_component = NULL) {

  // Helps to sanityze the $sids when one was given manually in the URL
  // (it should not).
  if (!is_array($sids)) {
    $sids = array();
  }

  // Helps to sanityze the $analysis_component when one was given manually in
  // the URL (it should not).
  // If showing a component's details, we don't want to loose the menu tabs.
  if ($analysis_component) {
    $item = menu_get_item('node/' . $node->nid . '/webform-results/chart');
    menu_set_item(NULL, $item);
  }

  // Retrieve the components list: either the customer component to analyse
  // or the list of all components from the webform.
  $components = isset($analysis_component) ? array(
    $analysis_component['cid'] => $analysis_component,
  ) : $node->webform['components'];
  $data = array();
  foreach ($components as $cid => $component) {

    // Get the component type.
    $type = $component['type'];

    // Get the callback to use, depending on the component.
    $callback = _webform_chart_webform_callback($type);

    // Do component specific call.
    if ($type == 'table_element' || $callback == 'analysis_data') {
      $component['components'] = $components;
    }

    // Invoke the component analysis callback:
    // -   _webform_chart_analysis_grid, for grid component,
    // callback defined in this module.
    // -   _webform_chart_analysis_table_element, for table component,
    // callback in this module.
    // (from http://drupal.org/project/webform_table_element)
    // -   _webform_analysis_*type*, for all other components,
    // callback defined in webform.
    $row_data = webform_component_invoke($type, $callback, $component, $sids, isset($analysis_component));
    if ($row_data) {

      // Case of grid: build the result.
      if ($type == 'grid') {
        foreach ($row_data['question_set'] as $key => $qa_set) {
          $data[$key] = array(
            'row_data' => $row_data['answer_set'][$key],
            'component_data' => $qa_set,
          );
        }
      }
      elseif ($type == 'table_element') {
        foreach ($row_data['question_set'] as $key => $qa_set) {
          $data[$key] = array(
            'row_data' => $row_data['answer_set'][$key],
            'component_data' => $qa_set,
          );
        }
      }
      else {
        $data[$cid] = array(
          'row_data' => $row_data,
          'component_data' => $component,
        );
      }
    }
  }

  // Return the rendered chart page.
  return theme('webform_chart_page', array(
    'node' => $node,
    'data' => $data,
    'sids' => $sids,
    'component' => $analysis_component,
  ));
}