You are here

summary.inc in Webform Bonus Pack 6.3

Same filename and directory in other branches
  1. 7.3 components/summary.inc

Webform module summary component.

File

components/summary.inc
View source
<?php

/**
 * @file
 * Webform module summary component.
 */

/**
 * Create a default summary component.
 */
function _webform_defaults_summary() {
  return array(
    'name' => '',
    'form_key' => NULL,
    'pid' => 0,
    'weight' => 0,
    'value' => '',
    'extra' => array(
      'components' => '',
    ),
  );
}

/**
 * Implementation of _webform_edit_component().
 */
function _webform_edit_summary($component) {
  $form = array();
  $node = node_load($component['nid']);
  $options = array();
  foreach ($node->webform['components'] as $id => $c) {
    $options[$id] = $c['name'];
  }
  $form['extra']['components'] = array(
    '#type' => 'select',
    '#title' => t('Select components to show in summary'),
    '#default_value' => $component['extra']['components'],
    '#options' => $options,
    '#multiple' => TRUE,
    '#description' => t('Select component to which current component should be mapped'),
  );
  return $form;
}

/**
 * Implementation of _webform_render_component().
 */
function _webform_render_summary($component) {
  $element = array(
    '#type' => 'item',
    '#weight' => $component['weight'],
    '#title' => $component['extra']['title_display'] == 'none' ? '' : $component['name'],
    '#value' => '',
    '#nid' => $component['nid'],
    // Pass nid
    '#cid' => $component['cid'],
    // Pass cid
    '#after_build' => array(
      '_set_summary',
    ),
  );
  return $element;
}

/**
 * Form after_build callback function. Set the value property of the form item according to the submitted values.
 */
function _set_summary($form_element, &$form_state) {
  global $user;
  module_load_include('inc', 'webform', 'includes/webform.submissions');
  $submitted = $form_state['storage']['submitted'];
  $node = node_load($form_element['#nid']);
  $allowed_components = $node->webform['components'][$form_element['#cid']]['extra']['components'];

  // Show only selected components
  foreach ($submitted as $key => $component) {
    if (!in_array($key, $allowed_components)) {
      unset($submitted[$key]);
    }
  }
  foreach ($node->webform['components'] as $key => $component) {
    if (!in_array($key, $allowed_components)) {
      unset($node->webform['components'][$key]);
    }
  }
  $submission = (object) array(
    'nid' => $node->nid,
    'uid' => $user->uid,
    'submitted' => REQUEST_TIME,
    'remote_addr' => ip_address(),
    'is_draft' => TRUE,
    'data' => webform_submission_data($node, $submitted),
  );
  $form_element['#value'] = webform_submission_render($node, $submission, NULL, 'html');
  return $form_element;
}

/**
 * Module specific instance of hook_help().
 */
function _webform_help_summary($section) {
  switch ($section) {
    case 'admin/settings/webform#summary_description':
      return t('Displays previously submitted values in the form; does not render a field. Only values of fields contained in a fieldgroup on the first level are displayed, the name of the fieldgroup is used as caption.');
  }
}

Functions

Namesort descending Description
_set_summary Form after_build callback function. Set the value property of the form item according to the submitted values.
_webform_defaults_summary Create a default summary component.
_webform_edit_summary Implementation of _webform_edit_component().
_webform_help_summary Module specific instance of hook_help().
_webform_render_summary Implementation of _webform_render_component().