You are here

function _webform_csv_data_select in Webform 6.3

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

Implements _webform_csv_data_component().

File

components/select.inc, line 762
Webform module multiple select component.

Code

function _webform_csv_data_select($component, $export_options, $value) {
  $options = _webform_select_options($component, TRUE, FALSE);
  $return = array();
  if ($component['extra']['multiple']) {
    foreach ($options as $key => $item) {
      $index = array_search($key, (array) $value);
      if ($index !== FALSE) {
        if ($export_options['select_format'] == 'separate') {
          $return[] = 'X';
        }
        else {
          $return[] = $export_options['select_keys'] ? $key : $item;
        }
        unset($value[$index]);
      }
      elseif ($export_options['select_format'] == 'separate') {
        $return[] = '';
      }
    }

    // Any remaining items in the $value array will be user-added options.
    if ($component['extra']['other_option']) {
      $return[] = count($value) ? implode(',', $value) : '';
    }
  }
  else {
    $key = $value[0];
    if ($export_options['select_keys']) {
      $return = $key;
    }
    else {
      $return = isset($options[$key]) ? $options[$key] : $key;
    }
  }
  if ($component['extra']['multiple'] && $export_options['select_format'] == 'compact') {
    $return = implode(',', (array) $return);
  }
  return $return;
}