You are here

function theme_webform_display_grid in Webform 7.3

Same name and namespace in other branches
  1. 6.3 components/grid.inc \theme_webform_display_grid()
  2. 7.4 components/grid.inc \theme_webform_display_grid()

Format the text output for this component.

1 theme call to theme_webform_display_grid()
_webform_display_grid in components/grid.inc
Implements _webform_display_component().

File

components/grid.inc, line 252
Webform module grid component.

Code

function theme_webform_display_grid($variables) {
  $element = $variables['element'];
  $component = $element['#webform_component'];
  $format = $element['#format'];
  if ($format == 'html') {
    $rows = array();
    $header = array(
      array(
        'data' => '',
        'class' => array(
          'webform-grid-question',
        ),
      ),
    );
    foreach ($element['#grid_options'] as $option) {
      $header[] = array(
        'data' => _webform_filter_xss($option),
        'class' => array(
          'checkbox',
          'webform-grid-option',
        ),
      );
    }
    foreach ($element['#grid_questions'] as $question_key => $question) {
      $row = array();
      $row[] = array(
        'data' => _webform_filter_xss($question),
        'class' => array(
          'webform-grid-question',
        ),
      );
      foreach ($element['#grid_options'] as $option_value => $option_label) {
        if (strcmp($element[$question_key]['#value'], $option_value) == 0) {
          $row[] = array(
            'data' => '<strong>X</strong>',
            'class' => array(
              'checkbox',
              'webform-grid-option',
            ),
          );
        }
        else {
          $row[] = array(
            'data' => '&nbsp;',
            'class' => array(
              'checkbox',
              'webform-grid-option',
            ),
          );
        }
      }
      $rows[] = $row;
    }
    $option_count = count($header) - 1;
    $output = theme('table', array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'class' => array(
          'webform-grid',
          'webform-grid-' . $option_count,
        ),
      ),
    ));
  }
  else {
    $items = array();
    foreach (element_children($element) as $key) {
      $items[] = ' - ' . $element[$key]['#title'] . ': ' . (isset($element['#grid_options'][$element[$key]['#value']]) ? $element['#grid_options'][$element[$key]['#value']] : '');
    }
    $output = implode("\n", $items);
  }
  return $output;
}