Author: david
Date: Tue Nov 22 13:06:56 2011
New Revision: 10350

Log:
Add CSV import of admin/bio history.  Fixes issue 2185.

Modified:
   trunk/lib/QubitCsvImport.class.php

Modified: trunk/lib/QubitCsvImport.class.php
==============================================================================
--- trunk/lib/QubitCsvImport.class.php  Tue Nov 22 11:22:51 2011        (r10349)
+++ trunk/lib/QubitCsvImport.class.php  Tue Nov 22 13:06:56 2011        (r10350)
@@ -417,25 +417,12 @@
       }
     }
 
-    // Creators
-    $this->getActors();
-    foreach (explode('|', $parameters['creators']) as $creator)
+    // Link creators
+    foreach ($this->addCreatorsAndHistory($parameters) as $creator)
     {
-      if (0 < strlen($creator))
-      {
-        if (!isset($this->actors[$creator]))
-        {
-          $actor = new QubitActor;
-          $actor->authorizedFormOfName = $creator;
-          $actor->save();
-
-          $this->actors[$creator] = $actor;
-        }
-
-        $parameters['editEvents'][] = array(
-          'type' => $creationUrl,
-          'actor' => $this->context->routing->generate(null, 
array($this->actors[$creator], 'module' => 'actor')));
-      }
+      $parameters['editEvents'][] = array(
+        'type' => $creationUrl,
+        'actor' => $this->context->routing->generate(null, array($creator, 
'module' => 'actor')));
     }
 
     if (!isset($this->materialTypes))
@@ -517,25 +504,9 @@
 
     // name access points
     $n = 0;
-    $this->getActors();
-    foreach (explode('|', $parameters['creators']) as $creator)
+    foreach ($this->addCreatorsAndHistory($parameters) as $creator)
     {
-      if (0 == strlen(trim($creator)))
-      {
-        continue;
-      }
-
-      // if the name does not exist, create it
-      if (!isset($this->actors[$creator]))
-      {
-        $name = new QubitActor();
-        $name->authorizedFormOfName = $creator;
-        $name->save();
-
-        $this->actors[$name->__toString()] = $name;
-      }
-
-      $new_creators['new'.$n] = $this->context->routing->generate(null, 
array($this->actors[$creator], 'module' => 'actor'));
+      $new_creators['new'.$n] = $this->context->routing->generate(null, 
array($creator, 'module' => 'actor'));
       $n++;
     }
     $parameters['creators'] = $new_creators;
@@ -653,4 +624,57 @@
 
     return $this->actors;
   }
+
+  public function addCreatorsAndHistory($parameters)
+  {
+    $creators = $histories = array();
+    $i = 0;
+    $updated = false;
+
+    // Get array of existing actors
+    $this->getActors();
+
+    if (isset($parameters['creatorHistory']))
+    {
+      $histories = explode('|', $parameters['creatorHistory']);
+    }
+
+    foreach (explode('|', $parameters['creators']) as $creator)
+    {
+      if (0 == strlen(trim($creator)))
+      {
+        continue;
+      }
+
+      if (isset($this->actors[$creator]))
+      {
+        $actor = $this->actors[$creator];
+      }
+      else
+      {
+        $actor = new QubitActor;
+        $actor->authorizedFormOfName = $creator;
+        $updated = true;
+
+        // Add to array of existing actors
+        $this->actors[$creator] = $actor;
+      }
+
+      if (isset($histories[$i]))
+      {
+        $actor->history = $histories[$i];
+        $updated = true;
+      }
+
+      if ($updated)
+      {
+        $actor->save();
+      }
+
+      $creators[] = $actor;
+      $i++;
+    }
+
+    return $creators;
+  }
 }

-- 
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