Author: mcantelon
Date: Thu Feb 23 14:39:06 2012
New Revision: 10961

Log:
Added ad-hoc event creation logic for imports.

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

Modified: trunk/lib/task/import/csvImportTask.class.php
==============================================================================
--- trunk/lib/task/import/csvImportTask.class.php       Thu Feb 23 14:30:15 
2012        (r10960)
+++ trunk/lib/task/import/csvImportTask.class.php       Thu Feb 23 14:39:06 
2012        (r10961)
@@ -515,20 +515,27 @@
           {
             foreach($self->rowStatusVars['eventActors'] as $index => $actor)
             {
+              // initialize data that'll be used to create the event
               $eventData = array(
-                'actor' => $actor
+                'actorName' => $actor
               );
 
+              // define whether each event-related column's values go directly
+              // into an event property or put into a varibale for further
+              // processing
               $eventColumns = array(
                 'eventTypes' => array(
-                  'property' => 'typeId',
+                  'variable'      => 'eventType',
                   'requiredError' => 'You have populated the eventActors 
column but not the eventTypes column.'
                 ),
-                'eventPlaces'        => array('property' => 'place'),
+                'eventPlaces'        => array('variable' => 'place'),
                 'eventDates'         => array('property' => 'date'),
                 'eventDescriptions'  => array('property' => 'description')
               );
 
+              // handle each of the event-related columns
+              $eventType = FALSE;
+              $place     = FALSE;
               foreach($eventColumns as $column => $definition)
               {
                 if (isset($self->rowStatusVars[$column]))
@@ -537,13 +544,43 @@
                     = (count($self->rowStatusVars['eventActors']) == 
count($self->rowStatusVars[$column]))
                       ? $self->rowStatusVars[$column][$index]
                       : $self->rowStatusVars[$column][0];
-                  $eventData[($definition['property'])] = $value;
+
+                  // allow column value(s) to set event property
+                  if (isset($definition['property']))
+                  {
+                    $eventData[($definition['property'])] = $value;
+                  }
+
+                  // allow column values(s) to set variable
+                  if (isset($definition['variable']))
+                  {
+                    $$definition['variable'] = $value;
+                  }
                 } else if (isset($definition['requiredError'])) {
                   throw new sfException('You have populated the eventActors 
column but not the eventTypes column.');
                 }
               }
 
-              // add event/place creation here
+              // if an event type has been specified, attempt to create the 
event
+              if ($eventType)
+              {
+                // do lookup of type ID
+                $typeTerm = 
$self->createOrFetchTerm(QubitTaxonomy::EVENT_TYPE_ID, $eventType);
+                $eventTypeId = $typeTerm->id;
+
+                // create event
+                $event = $self->createEvent($eventTypeId, $eventData);
+
+                // create a place term if specified
+                if ($place)
+                {
+                  // create place
+                  $placeTerm = $self->createTerm(QubitTaxonomy::PLACE_ID, 
$place);
+                  $self->createObjectTermRelation($event->id, $placeTerm->id);
+                }
+              } else {
+                throw new sfException('eventTypes column need to be 
populated.');
+              }
             }
           }
 

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