Author: mcantelon
Date: Thu Aug 30 17:58:44 2012
New Revision: 12233

Log:
Cleaning up accessions import.

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

Modified: trunk/lib/task/import/csvAccessionImportTask.class.php
==============================================================================
--- trunk/lib/task/import/csvAccessionImportTask.class.php      Thu Aug 30 
00:03:03 2012        (r12232)
+++ trunk/lib/task/import/csvAccessionImportTask.class.php      Thu Aug 30 
17:58:44 2012        (r12233)
@@ -27,9 +27,9 @@
  */
 class csvAccessionImportTask extends csvImportBaseTask
 {
-  protected $namespace        = 'csv';
-  protected $name             = 'accession-import';
-  protected $briefDescription = 'Import csv acession data';
+  protected $namespace           = 'csv';
+  protected $name                = 'accession-import';
+  protected $briefDescription    = 'Import csv acession data';
   protected $detailedDescription = <<<EOF
 Import CSV data
 EOF;
@@ -42,7 +42,11 @@
     parent::configure();
 
     $this->addOptions(array(
-      new sfCommandOption('source-name', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'Source name to use when inserting keymap 
entries.')
+      new sfCommandOption(
+        'source-name',
+        null,
+        sfCommandOption::PARAMETER_OPTIONAL, 'Source name to use when 
inserting keymap entries.'
+      )
     ));
   }
 
@@ -91,6 +95,18 @@
         'processingStatus' => $termData['processingStatus']
       ),
 
+      'standardColumns' => array(
+        'appraisal',
+        'archivalHistory',
+        'acquisitionDate',
+        'locationInformation',
+        'processingNotes',
+        'receivedExtentUnits',
+        'scopeAndContent',
+        'sourceOfAcquisition',
+        'title'
+      ),
+
       /* import columns that should be redirected to QubitInformationObject
          properties (and optionally transformed)
       
@@ -110,21 +126,14 @@
          ),
       */
       'columnMap' => array(
-        'TITLE'             => 'title',
-        'LOCATION'          => 'locationInformation',
-        'SCOPE AND CONTENT' => 'scopeAndContent',
-        'scopeAndContent'   => 'scopeAndContent',
-        'physicalCondition' => 'physicalCharacteristics',
-        'CONSERVATION NOTE' => 'physicalCharacteristics',
-        'extent'            => 'receivedExtentUnits',
-        'primaryNotes'      => 'notes',
-        'notes'             => 'notes'
+        'physicalCondition' => 'physicalCharacteristics'
       ),
 
       /* these values get stored to the rowStatusVars array */
       'variableColumns' => array(
         'accessionNumber',
-        'TYPE',
+        'acquisitionType',
+        'resourceType',
         'DONOR',
         'EMAIL',
         'POSTAL CODE',
@@ -135,8 +144,7 @@
         'APPRAISAL NOTES',
         'DISPOSITION NOTE',
         'DATE OF CREATION',
-        'DEPARTMENT',
-        'CREATOR or COLLECTOR'
+        'creators'
       ),
 
       /* import logic to load accession */
@@ -156,16 +164,11 @@
           print 'Found '. $result->id ."\n";
           $self->object = QubitAccession::getById($result->id);
         } else {
-          if (!$accessionNumber)
-          {
-            throw new sfException('Import aborted: stopped on blank accession 
number.');
-          } else {
-            $self->object = false;
-            $error = "Couldn't find accession # ". $accessionNumber .'... 
creating.';
-            print $error ."\n";
-            $self->object = new QubitAccession();
-            $self->object->identifier = $accessionNumber;
-          }
+          $self->object = false;
+          $error = "Couldn't find accession # ". $accessionNumber .'... 
creating.';
+          print $error ."\n";
+          $self->object = new QubitAccession();
+          $self->object->identifier = $accessionNumber;
         }
       },
 
@@ -175,67 +178,14 @@
         if ($self->object)
         {
           if (
-            isset($self->rowStatusVars['DATE OF CREATION'])
-            && $self->rowStatusVars['DATE OF CREATION'])
-          {
-            $self->object->scopeAndContent = 
$self->appendWithLineBreakIfNeeded(
-              $self->object->scopeAndContent,
-              'Dates of Creation: '. $self->rowStatusVars['DATE OF CREATION']
-            );
-          }
-
-          if (
-            isset($self->rowStatusVars['CREATOR or COLLECTOR'])
-            && $self->rowStatusVars['CREATOR or COLLECTOR']
+            isset($self->rowStatusVars['creators'])
+            && $self->rowStatusVars['creators']
           )
           {
-            $creators = explode('|', $self->rowStatusVars['CREATOR or 
COLLECTOR']);
+            $creators = explode('|', $self->rowStatusVars['creators']);
             foreach($creators as $creator)
             {
-              $self->object->scopeAndContent = 
$self->appendWithLineBreakIfNeeded(
-                $self->object->scopeAndContent,
-                'Creator: '. trim($creator)
-              );
-            }
-          }
-
-          if (
-            isset($self->rowStatusVars['DEPARTMENT'])
-            && trim($self->rowStatusVars['DEPARTMENT'])
-          )
-          {
-            $self->object->scopeAndContent = 
$self->appendWithLineBreakIfNeeded(
-              $self->object->scopeAndContent,
-              'Creator: '. trim($self->rowStatusVars['DEPARTMENT'])
-            );
-          }
-
-          if (isset($self->rowStatusVars['receivedExtentUnits']))
-          {
-            $self->object->receivedExtentUnits = 
$self->rowStatusVars['receivedExtentUnits'];
-          }
-
-          if (isset($self->rowStatusVars['processingNotes']))
-          {
-            $self->object->processingNotes = 
$self->rowStatusVars['processingNotes'];
-          }
-
-          // amalgamate appraisal-related fields
-          $appraisalVarPrefixMap = array(
-            'DISPOSITION NOTE' => '',
-            'APPRAISAL NOTES'  => 'Appraisal Notes: '
-          );
-
-          // if either of the appraisal-related fields contain content,
-          // add content to appraisal field, prefixing if necessary
-          foreach($appraisalVarPrefixMap as $var => $prefix)
-          {
-            if (isset($self->rowStatusVars[$var]) && 
$self->rowStatusVars[$var])
-            {
-              $self->object->appraisal = $self->appendWithLineBreakIfNeeded(
-                $self->object->appraisal,
-                $prefix . $self->rowStatusVars[$var]
-              );
+              // put some stuff here
             }
           }
         }
@@ -256,17 +206,6 @@
         if(isset($self->object) && is_object($self->object))
         {
           if (
-            isset($self->rowStatusVars['DATE OF CREATION'])
-            && $self->rowStatusVars['DATE OF CREATION']
-          )
-          {
-            $self->object->scopeAndContent = 
$self->appendWithLineBreakIfNeeded(
-              $self->object->scopeAndContent,
-              'Dates of Creation: '. $self->rowStatusVars['DATE OF CREATION']
-            );
-          }
-
-          if (
             isset($self->rowStatusVars['DONOR'])
             && $self->rowStatusVars['DONOR']
           )
@@ -304,10 +243,7 @@
       }
     ));
 
-    $this->setUpExtentColumnHandling($import);
-    $this->setUpProcessingNoteColumnHandling($import);
-
-    $import->addColumnHandler('DATE OF ACQUISITION', function(&$self, $data)
+    $import->addColumnHandler('acquisitionDate', function(&$self, $data)
     {
       if ($data)
       {
@@ -321,7 +257,7 @@
       }
     });
 
-    $import->addColumnHandler('TYPE', function(&$self, $data)
+    $import->addColumnHandler('resourceType', function(&$self, $data)
     {
       if ($data)
       {
@@ -333,7 +269,7 @@
         if (isset($self->object) && is_object($self->object))
         {
           $self->object->resourceTypeId = $self->translateNameToTermId(
-            'transfer type',
+            'resource type',
             $data,
             $cvaToQubit,
             $self->getStatus('resourceTypes')
@@ -342,140 +278,24 @@
       }
     });
 
-    $import->addColumnHandler('ACQUISITION METHOD', function(&$self, $data)
+    $import->addColumnHandler('acquisitionType', function(&$self, $data)
     {
       if ($data)
       {
-        $cvaToQubit = array(
-          'Copy Loan'          => 'Deposit', // is this correct?
-          'Donation'           => 'Gift',
-          'Direct Transfer'    => 'Transfer',
-          'Scheduled Transfer' => 'Transfer'
-        );
-
         if (isset($self->object) && is_object($self->object))
         {
-          $self->object->acquisitionTypeId = $self->translateNameToTermId(
-            'acquisition type',
-            $data,
-            $cvaToQubit,
-            $self->getStatus('acquisitionTypes')
-          );
+          $term_id = array_search($data, $self->getStatus('acquisitionTypes'));
+
+          if (!$term_id)
+          {
+            throw new sfException('Could not find a way to handle acquisition 
type value "Transfer".');
+          } else {
+            $self->object->acquisitionTypeId = $term_id;
+          }
         }
       }
     });
 
     $import->csv($fh, $skipRows);
   }
-
-  public function appendColumnDataToRowVarWithColumnSpecificPrefix(
-    &$import,
-    $column,
-    $data, 
-    $rowStatusVarName, 
-    $columnsAndPrefixes
-  )
-  {
-    if ($data)
-    {
-      // initialize column value storage
-      $import->rowStatusVars[$rowStatusVarName] = 
(isset($import->rowStatusVars[$rowStatusVarName]))
-        ? $import->rowStatusVars[$rowStatusVarName]
-        : '';
-
-      // determine appropriate column prefix (can be blank)
-      $prefix = $columnsAndPrefixes[$column];
-
-      // append prefixed value to column value
-      $import->rowStatusVars[$rowStatusVarName] = 
$import->appendWithLineBreakIfNeeded(
-        $import->rowStatusVars[$rowStatusVarName],
-        $prefix . $data
-      );
-    }
-  }
-
-  protected function setUpExtentColumnHandling(&$import)
-  {
-    // map of extent-related column names to their corresponding prefixes
-    $extentColumnsAndPrefixes = array(
-      'INARCHITECTURALPLAN' => "Plans (count): ",
-      'INAUDIOCASSETTE'     => "Audio Cassettes (count): ",
-      'INAUDIOREEL'         => "Audio Reels (count): ",
-      'INCOMPACTDISC'       => "CDs (count): ",
-      'INDIGITALPHOTO'      => "Digital Photos (count): ",
-      'INDOCUMENTARYART'    => "Doc Art (count): ",
-      'INDVD'               => "DVDs (count): ",
-      'INFILMREEL'          => "Film Reels (count): ",
-      'INMAP'               => "Maps (count): ",
-      'INMICROFICHE'        => "Microfiche (count): ",
-      'INMICROFILM'         => "Microfilm Reels (count): ",
-      'INNEGATIVE'          => "Photo Negs (count): ",
-      'INOTHER MATERIALS'   => "Other Materials (count): ",
-      'INPHOTOGRAPHICPRINT' => "Photo Prints (count): ",
-      'INSLIDE'             => "Slides (count): ",
-      'INTEXTUALRECORDS'    => "Textual (m): ",
-      'INVIDEOCASSETTE'     => "Video Cassettes (count): "
-    );
-
-    // store column/prefix data as we need to access it from inside a handler
-    $import->setStatus('extentColumnsAndPrefixes', $extentColumnsAndPrefixes);
-
-    // handling logic for extent columns
-    $extentColumnHandler = function(&$self, $data)
-    {
-      csvAccessionImportTask::appendColumnDataToRowVarWithColumnSpecificPrefix(
-        $self,
-        $self->status['currentColumn'],
-        $data,
-        'receivedExtentUnits',
-        $self->getStatus('extentColumnsAndPrefixes')
-      );
-    };
-
-    // add handler for each extent-related column
-    $import->addColumnHandlers(
-      array_keys($extentColumnsAndPrefixes), 
-      $extentColumnHandler
-    );
-  }
-
-  protected function setUpProcessingNoteColumnHandling(&$import)
-  {
-    // map of processing-note-related column names to their corresponding 
prefixes
-    $processingNoteColumnsAndPrefixes = array(
-      'ACCESSION NOTE'     => "",
-      'ACKNOWLEDGMENT'     => "Acknowledge Donor in Description? (Y/N): ",
-      'ARCHIVIST'          => "Registered by: ",
-      'CVA NUMBER'         => "CVA #: ",
-      'ItemNumberTracking' => "Last Item #: ",
-      'PR SERIES NUMBER'   => "PR Series #: ",
-      'PRI REC NO'         => "Private Rec. #: ",
-      'RECORD ID'          => "CS Record ID: ",
-      'TRANSFER NUMBER'    => "RM Transfer #: ",
-      'VanRims Number'     => "Classification #: ",
-      'COPYRIGHT STATUS'   => "Copyright Note: ",
-      'RESTRICTIONS'       => "Restrictions Note: "
-    );
-
-    // store column/prefix data as we need to access it from inside a handler
-    $import->setStatus('processingNoteColumnsAndPrefixes', 
$processingNoteColumnsAndPrefixes);
-
-    // handling logic for extent columns
-    $processingNoteColumnHandler = function(&$self, $data)
-    {
-      csvAccessionImportTask::appendColumnDataToRowVarWithColumnSpecificPrefix(
-        $self,
-        $self->status['currentColumn'],
-        $data,
-        'processingNotes',
-        $self->getStatus('processingNoteColumnsAndPrefixes')
-      );
-    };
-
-    // add handler for each extent-related column
-    $import->addColumnHandlers(
-      array_keys($processingNoteColumnsAndPrefixes),
-      $processingNoteColumnHandler
-    );
-  }
 }

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