You are here

function _webform_csv_data_matrix in Webform Matrix Component 7

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

Implements _webform_csv_data_component().

File

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

Code

function _webform_csv_data_matrix($component, $export_options, $value) {
  if ($value[0]) {
    $value_array = webform_matrix_array($value[0]);
    $sub_elements = $component['extra']['element'];
    $col = 1;
    foreach ($sub_elements as $sub_element) {
      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++;
    }
    $reverse_array = matrix_array_reverse($value_array);
    $csv_array = array();
    foreach ($reverse_array as $value) {
      $csv_array[] = implode(" - ", $value);
    }
    return $csv_array;
  }
  else {
    return '';
  }
}