Passes down the list of input-to-output relations to the field callback.
authorVincent Zanotti <vincent.zanotti@m4x.org>
Mon, 20 Apr 2009 21:20:03 +0000 (23:20 +0200)
committerVincent Zanotti <vincent.zanotti@m4x.org>
Mon, 20 Apr 2009 21:20:03 +0000 (23:20 +0200)
It allows this callback to actually use the input in a proper way (the first
parameter of the cb is the user input, which is improperly keyed).

Also make the getValue method public and static to simplify the computation
of output keys by the callbacks.

Signed-off-by: Vincent Zanotti <vincent.zanotti@m4x.org>
classes/csvimporter.php

index 0f576a0..44a75a5 100644 (file)
@@ -64,12 +64,12 @@ class CSVImporter
         return true;
     }
 
-    private function getValue($line, $key, $action)
+    static public function getValue($line, $key, $action, $relation = null)
     {
         if (@array_key_exists($action, $line)) {
             $value = $line[$action];
         } elseif (is_callable($action, false)) {
-            $value = call_user_func($action, $line, $key);
+            $value = call_user_func($action, $line, $key, $relation);
         } else {
             $value = $action;
         }
@@ -83,7 +83,7 @@ class CSVImporter
     {
         $ops = array();
         foreach ($relation as $key=>$ref) {
-            $ops[$key] = $this->getValue($line, $key, $ref);
+            $ops[$key] = $this->getValue($line, $key, $ref, $relation);
         }
         return $ops;
     }
@@ -92,7 +92,7 @@ class CSVImporter
     {
         $ops = array();
         foreach ($relation as $key=>$ref) {
-            $value = $this->getValue($line, $key, $ref);
+            $value = $this->getValue($line, $key, $ref, $relation);
             if (!is_null($value) && $value != 'NULL') {
                 $value = "'" . addslashes($value) . "'";
             }