Author: mcantelon
Date: Fri Jan 13 19:17:41 2012
New Revision: 10672

Log:
Added support for 3 accession import columns.

Modified:
   trunk/lib/task/csvAccessionImportTask.class.php

Modified: trunk/lib/task/csvAccessionImportTask.class.php
==============================================================================
--- trunk/lib/task/csvAccessionImportTask.class.php     Fri Jan 13 18:23:18 
2012        (r10671)
+++ trunk/lib/task/csvAccessionImportTask.class.php     Fri Jan 13 19:17:41 
2012        (r10672)
@@ -102,18 +102,10 @@
     $databaseManager = new sfDatabaseManager($this->configuration);
     $conn = $databaseManager->getDatabase('propel')->getConnection();
 
-    // set default publishing status
-    $defaultStatusId = sfConfig::get(
-      'app_defaultPubStatus',
-      QubitTerm::PUBLICATION_STATUS_PUBLISHED_ID
-    );
-    $defaultStatusTypeId = QubitTerm::STATUS_TYPE_PUBLICATION_ID;
-
-    // create note term if it doesn't yet exist
-    QubitFlatfileImport::createOrFetchTerm(
-      QubitTaxonomy::NOTE_TYPE_ID,
-      'Language note'
-    );
+    // Load taxonomies into variables to avoid use of magic numbers
+    $termData = QubitFlatfileImport::loadTermsFromTaxonomies(array(
+      QubitTaxonomy::ACCESSION_RESOURCE_TYPE_ID => 'resourceTypes',
+    ));
 
     // Define import
     $import = new QubitFlatfileImport(array(
@@ -126,7 +118,8 @@
       /* the status array is a place to put data that should be accessible
          from closure logic using the getStatus method */
       'status' => array(
-        'sourceName'           => $sourceName
+        'sourceName'    => $sourceName,
+        'resourceTypes' => $termData['resourceTypes']
       ),
       'columnNames' => fgetcsv($fh, 60000), // 1st row supplies column 
names/order
 //      'defaultStatusId' => $defaultStatusId,
@@ -157,11 +150,14 @@
          ),
       */
       'columnMap' => array(
+        'TITLE'          => 'title',
+        'ACCESSION NOTE' => 'processingNotes'
       ),
 
       /* these values get stored to the rowStatusVars array */
       'variableColumns' => array(
-        'ACCESSION NUMBER'
+        'ACCESSION NUMBER',
+        'TYPE'
       ),
 
       /* import logic to load accession */
@@ -201,9 +197,41 @@
       /* import logic to save accession */
       'saveLogic' => function(&$self)
       {
+        if($self->object)
+        {
+          $self->object->save();
+//print 'Saved ID '. $self->object->id ."\n"; exit();
+        }
       }
     ));
 
+    $import->addColumnHandler('TYPE', function(&$self, $data)
+    {
+      if ($data)
+      {
+        $cvaToQubit = array(
+          'Private records' => 'Private transfer',
+          'Public records'  => 'Public transfer'
+        );
+
+        if (isset($cvaToQubit[$data]))
+        {
+          $resourceTypeTermName = $cvaToQubit[$data];
+          if (in_array($resourceTypeTermName, 
$self->getStatus('resourceTypes')))
+          {
+            $termId = array_search($resourceTypeTermName, 
$self->getStatus('resourceTypes'));
+            // lookup material taxonomy ID from materialTypes
+            //$self->rowStatusVars['resourceType'] = $termId;
+            $self->object->resourceTypeId = $termId;
+          } else {
+            die('Could not find "'. $resourceTypeTermName .'" in resourceTypes 
array.');
+          }
+        } else {
+          die('Could not find a way to handle TYPE value "'. $data .'".');
+        }
+      }
+    });
+
     $import->csv($fh, $skipRows);
   }
 }

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