You are here

function webform_results_analysis in Webform 7.4

Same name and namespace in other branches
  1. 5.2 webform_report.inc \webform_results_analysis()
  2. 6.3 includes/webform.report.inc \webform_results_analysis()
  3. 6.2 webform_report.inc \webform_results_analysis()
  4. 7.3 includes/webform.report.inc \webform_results_analysis()

Provides a simple analysis of all submissions to a webform.

Parameters

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

$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.

$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.

Return value

array Renderable array: A simple analysis of all submissions to a webform.

1 string reference to 'webform_results_analysis'
webform_menu in ./webform.module
Implements hook_menu().

File

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

Code

function webform_results_analysis($node, $sids = array(), $analysis_component = NULL) {
  if (!is_array($sids)) {
    $sids = array();
  }

  // Build a renderable for the content of this page.
  $analysis = array(
    '#theme' => array(
      'webform_analysis__' . $node->nid,
      'webform_analysis',
    ),
    '#node' => $node,
    '#component' => $analysis_component,
  );

  // See if a query (possibly with exposed filter) needs to restrict the
  // submissions that are being analyzed.
  $query = NULL;
  if (empty($sids)) {
    $view = webform_get_view($node, 'webform_analysis');
    if ($view->type != t('Default') || $view->name != 'webform_analysis') {

      // The view has been customized from the no-op built-in view. Use it.
      $view
        ->set_display();
      $view
        ->init_handlers();
      $view->override_url = $_GET['q'];
      $view->preview = TRUE;
      $view
        ->pre_execute(array(
        $node->nid,
      ));
      $view
        ->build();

      // Let modules modify the view just prior to executing it.
      foreach (module_implements('views_pre_execute') as $module) {
        $function = $module . '_views_pre_execute';
        $function($view);
      }

      // If the view is already executed, there was an error in generating it.
      $query = $view->executed ? NULL : $view->query
        ->query();
      $view
        ->post_execute();
      if (isset($view->exposed_widgets)) {
        $analysis['exposed_filter']['#markup'] = $view->exposed_widgets;
      }
    }
  }

  // If showing all components, display selection form.
  if (!$analysis_component) {
    $analysis['form'] = drupal_get_form('webform_analysis_components_form', $node);
  }

  // Add all the components to the analysis renderable array.
  $components = isset($analysis_component) ? array(
    $analysis_component['cid'],
  ) : webform_analysis_enabled_components($node);
  foreach ($components as $cid) {

    // Do component specific call.
    $component = $node->webform['components'][$cid];
    if ($data = webform_component_invoke($component['type'], 'analysis', $component, $sids, isset($analysis_component), $query)) {
      drupal_alter('webform_analysis_component_data', $data, $node, $component);
      $analysis['data'][$cid] = array(
        '#theme' => array(
          'webform_analysis_component__' . $node->nid . '__' . $cid,
          'webform_analysis_component__' . $node->nid,
          'webform_analysis_component',
        ),
        '#node' => $node,
        '#component' => $component,
        '#data' => $data,
      );
      $analysis['data'][$cid]['basic'] = array(
        '#theme' => array(
          'webform_analysis_component_basic__' . $node->nid . '__' . $cid,
          'webform_analysis_component_basic__' . $node->nid,
          'webform_analysis_component_basic',
        ),
        '#component' => $component,
        '#data' => $data,
      );
    }
  }
  drupal_alter('webform_analysis', $analysis);
  return $analysis;
}