You are here

function _webform_table_matrix in Webform Matrix Component 7

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

Implements _webform_table_component().

File

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

Code

function _webform_table_matrix($component, $value) {
  if ($value[0]) {
    $sub_elements = $component['extra']['element'];
    $value_array = unserialize($value[0]);
    $col = 1;
    $headers = array();
    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) {
          if (isset($value_row[$col])) {
            if (array_key_exists($value_row[$col], $option_array)) {
              $value_array[$key][$col] = $option_array[$value_row[$col]];
            }
            else {
              $value_array[$key][$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('short');
            $value_array[$key][$col] = format_date($timestamp, 'custom', $format, 'UTC');
          }
          else {
            $value_array[$key][$col] = "";
          }
        }
      }
      $col++;
    }
    $output = theme('table', array(
      'header' => $headers,
      'rows' => $value_array,
    ));
    return $output;
  }
  else {
    return '';
  }
}