Author: mcantelon
Date: Thu Feb  2 20:28:44 2012
New Revision: 10799

Log:
Added ability to rename CSV header columns before importing.

Modified:
   trunk/lib/QubitFlatfileImport.class.php

Modified: trunk/lib/QubitFlatfileImport.class.php
==============================================================================
--- trunk/lib/QubitFlatfileImport.class.php     Thu Feb  2 15:50:15 2012        
(r10798)
+++ trunk/lib/QubitFlatfileImport.class.php     Thu Feb  2 20:28:44 2012        
(r10799)
@@ -36,6 +36,7 @@
 
   public $columnNames     = array(); // column names from first row of 
imported CSV
   public $ignoreColumns   = array(); // columns in CSV to ignore
+  public $renameColumns   = array(); // CSV header column substitutions
 
   public $standardColumns = array(); // columns in CSV are object properties
   public $columnMap       = array(); // columns in CSV that map to object 
properties
@@ -308,6 +309,20 @@
    *  ----------------------
    */
 
+  protected function handleColumnRenaming()
+  {
+    if (isset($this->renameColumns))
+    {
+      foreach($this->renameColumns as $sourceColumn => $newName)
+      {
+        if (is_numeric($position = array_search($sourceColumn, 
$this->columnNames)))
+        {
+          $this->columnNames[$position] = $newName;
+        }
+      }
+    }
+  }
+
   /**
    * Pull data from a csv file and process each row
    *
@@ -320,6 +335,7 @@
   {
     $this->status['skippedRows'] = $skipRows;
     $this->columnNames = fgetcsv($fh, 60000);
+    $this->handleColumnRenaming();
 
     // inform user of any columns not included in import
     print $this->renderUnhandledColumns();

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to