Author: mcantelon
Date: Fri Jan  6 12:41:31 2012
New Revision: 10587

Log:
Got creation of ad-hoc actor/events, based on column names matching a certain 
pattern, working.

Modified:
   trunk/lib/QubitFlatfileImport.class.php
   trunk/lib/task/csvImportTask.class.php

Modified: trunk/lib/QubitFlatfileImport.class.php
==============================================================================
--- trunk/lib/QubitFlatfileImport.class.php     Fri Jan  6 11:49:37 2012        
(r10586)
+++ trunk/lib/QubitFlatfileImport.class.php     Fri Jan  6 12:41:31 2012        
(r10587)
@@ -338,7 +338,10 @@
       $event->description = $options['description'];
     }
 
-    $event->startDate = $options['startDate'];
+    if (isset($options['startDate']))
+    {
+      $event->startDate = $options['startDate'];
+    }
 
     if (isset($options['endDate']))
     {

Modified: trunk/lib/task/csvImportTask.class.php
==============================================================================
--- trunk/lib/task/csvImportTask.class.php      Fri Jan  6 11:49:37 2012        
(r10586)
+++ trunk/lib/task/csvImportTask.class.php      Fri Jan  6 12:41:31 2012        
(r10587)
@@ -381,6 +381,21 @@
           }
         }
 
+        // if a role is found, create term and actor if need be
+        if (isset($self->rowStatusVars['actorRoles']))
+        {
+          foreach($self->rowStatusVars['actorRoles'] as $actorRole)
+          {
+            // create/fetch term
+            $term = $self->createOrFetchTerm(40, $actorRole['role']);
+
+            // create/fetch actor
+            $self->createOrFetchActor($actorRole['actor']);
+
+            $self->createEvent($term->id, array('actorName' => 
$actorRole['actor']));
+          }
+        }
+
         // output progress information
         if ($options = $self->getStatus('options'))
         {
@@ -407,7 +422,24 @@
 
     $relatedActorHandler = function(&$self, $data)
     {
-      print 'Working with '. $self->status['currentColumn'] ."\n";
+      if ($data)
+      {
+        // parse out actor role from column name
+        $pattern = '/^relatedActor(.*)By$|^relatedActor(.*)$/';
+        preg_match($pattern, $self->status['currentColumn'], $matches);
+        $termName = (isset($matches[1]) && $matches[1] != '') ? $matches[1] : 
'';
+        $termName = (isset($matches[2]) && $matches[2] != '') ? $matches[2] : 
$termName;
+
+        // note that role and actor should be created after saving info object
+        $self->rowStatusVars['actorRoles'] = 
(isset($self->rowStatusVars['actorRoles']))
+          ? $self->rowStatusVars['actorRoles']
+          : array();
+
+        array_push(
+          $self->rowStatusVars['actorRoles'],
+          array('role' => $termName, 'actor' => $data)
+        );
+      }
     };
 
     $import->addColumnHandler('relatedActorCommissionedBy', 
$relatedActorHandler);

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