You are here

function uif_clean_and_key_row in User Import Framework 7

Same name and namespace in other branches
  1. 6 uif.admin.inc \uif_clean_and_key_row()

Trim all elements of $row, and pad $row out to the number of columns in the $header. Then replace keys in $row with $header values.

1 call to uif_clean_and_key_row()
uif_validate_user_file in ./uif.admin.inc
Read the user import file and validate on the way.

File

./uif.admin.inc, line 245
Simple, extensible user import from a CSV file.

Code

function uif_clean_and_key_row($header, $row, $line) {
  $row = array_map('trim', $row);
  $raw_row = $row;
  $row = array_map('uif_clean_value', $row);
  for ($i = 0; $i < count($row); $i++) {
    if ($raw_row[$i] !== $row[$i]) {
      $vars = array(
        '@line' => $line,
        '@column' => $header[$i],
      );
      drupal_set_message(t('Warning on row @line: Non UTF-8 characters were removed from @column column.', $vars), 'warning');
    }
  }
  if (count($row) < count($header)) {
    $row = array_merge($row, array_fill(count($row), count($header) - count($row), ''));
    drupal_set_message(t('Warning on row @line: Empty values added for missing data.', array(
      '@line' => $line,
    )), 'warning');
  }
  elseif (count($row) > count($header)) {
    array_splice($row, count($header));
    drupal_set_message(t('Warning on row @line: Data values beyond header were truncated.', array(
      '@line' => $line,
    )), 'warning');
  }
  $row = array_combine($header, $row);
  return $row;
}