You are here

function _webform_csv_headers_select in Webform 5

Same name and namespace in other branches
  1. 5.2 components/select.inc \_webform_csv_headers_select()
  2. 6.3 components/select.inc \_webform_csv_headers_select()
  3. 6.2 components/select.inc \_webform_csv_headers_select()
  4. 7.4 components/select.inc \_webform_csv_headers_select()
  5. 7.3 components/select.inc \_webform_csv_headers_select()

Return the header information for this component to be displayed in a comma seperated value file. The output of this function will be displayed under the "results" tab then "download".

Parameters

$component: An array of information describing the component, directly correlating to the webform_component database schema.

Return value

An array of data to be displayed in the first three rows of a CSV file, not including either prefixed or trailing commas.

File

components/select.inc, line 388

Code

function _webform_csv_headers_select($component) {
  $header = array();
  $header[0] = '';
  if ($component['extra']['multiple']) {
    $header[1] = $component['name'];
    $items = split("\n", $component['extra']['items']);
    foreach ($items as $item) {
      $item = trim($item);
      if (preg_match('/^([^"|]+)\\|(.*)$/', $item, $matches)) {
        $item = $matches[1];
      }
      $header[2] .= "\\," . $item;

      // empty column per sub-field in main header.
      $header[1] .= "\\,";
    }

    // Remove the preceding extra comma.
    $header[2] = substr($header[2], 2);

    // Remove the trailing column.
    $header[1] = substr($header[1], 0, -2);
  }
  else {
    $header[2] = $component['name'];
  }
  return $header;
}