You are here

function _webform_display_matrix in Webform Matrix Component 7

Same name and namespace in other branches
  1. 6 components/matrix.inc \_webform_display_matrix()
  2. 7.4 components/matrix.inc \_webform_display_matrix()
  3. 7.2 components/matrix.inc \_webform_display_matrix()
  4. 7.3 components/matrix.inc \_webform_display_matrix()

Implements _webform_display_component().

File

components/matrix.inc, line 553
Webform module matrix component.

Code

function _webform_display_matrix($component, $value, $format = 'html') {
  $headers = array();
  $value_array = isset($value[0]) ? unserialize($value[0]) : '';
  $sub_elements = $component['extra']['element'];
  $col = 1;
  foreach ($sub_elements as $sub_element) {
    $headers[] = $sub_element['title'];
    if ($sub_element['type'] == 'select') {
      $option_array = matrix_select_option_from_text($sub_element['option']);
      foreach ($value_array as $key => $value_row) {
        $value_array[$key][$col] = array_key_exists($value_row[$col], $option_array) ? $option_array[$value_row[$col]] : $value_row[$col];
      }
    }
    elseif ($sub_element['type'] == 'date') {
      foreach ($value_array as $key => $value_row) {
        if ($value_array[$key][$col]['year'] && $value_array[$key][$col]['month'] && $value_array[$key][$col]['day']) {
          $timestamp = webform_strtotime($value_array[$key][$col]['month'] . '/' . $value_array[$key][$col]['day'] . '/' . $value_array[$key][$col]['year']);
          $format = webform_date_format('medium');
          $value_array[$key][$col] = format_date($timestamp, 'custom', $format, 'UTC');
        }
        else {
          $value_array[$key][$col] = "";
        }
      }
    }
    $col++;
  }
  $matrix_value = array(
    'headers' => $headers,
    'rows' => $value_array,
  );
  return array(
    '#title' => $component['name'],
    '#weight' => $component['weight'],
    '#theme' => 'webform_display_matrix',
    '#theme_wrappers' => $format == 'html' ? array(
      'webform_element',
    ) : array(
      'webform_element_text',
    ),
    '#format' => $format,
    '#value' => $matrix_value,
    '#translatable' => array(
      'title',
    ),
  );
}