Author: mcantelon
Date: Wed Jan 18 17:45:45 2012
New Revision: 10720
Log:
Refactoring.
Modified:
trunk/lib/task/import/csvAccessionImportTask.class.php
Modified: trunk/lib/task/import/csvAccessionImportTask.class.php
==============================================================================
--- trunk/lib/task/import/csvAccessionImportTask.class.php Wed Jan 18
17:40:47 2012 (r10719)
+++ trunk/lib/task/import/csvAccessionImportTask.class.php Wed Jan 18
17:45:45 2012 (r10720)
@@ -141,9 +141,9 @@
{
if ($self->object)
{
- if (isset($self->rowStatusVars['extents']))
+ if (isset($self->rowStatusVars['receivedExtentUnits']))
{
- $self->object->receivedExtentUnits =
$self->rowStatusVars['extents'];
+ $self->object->receivedExtentUnits =
$self->rowStatusVars['receivedExtentUnits'];
}
if (isset($self->rowStatusVars['processingNotes']))
@@ -214,6 +214,32 @@
$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
@@ -237,36 +263,31 @@
'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)
{
- if ($data)
- {
- $self->rowStatusVars['extents'] =
(isset($self->rowStatusVars['extents']))
- ? $self->rowStatusVars['extents']
- : '';
-
- $extentColumnsAndPrefixes =
$self->getStatus('extentColumnsAndPrefixes');
- $self->rowStatusVars['extents'] = $self->appendWithLineBreakIfNeeded(
- $self->rowStatusVars['extents'],
- $extentColumnsAndPrefixes[($self->status['currentColumn'])] . $data
- );
- }
+ csvAccessionImportTask::appendColumnDataToRowVarWithColumnSpecificPrefix(
+ $self,
+ $self->status['currentColumn'],
+ $data,
+ 'receivedExtentUnits',
+ $self->getStatus('extentColumnsAndPrefixes')
+ );
};
// add handler for each extent-related column
- foreach($extentColumnsAndPrefixes as $column => $junk)
- {
- $import->addColumnHandler($column, $extentColumnHandler);
- }
-
+ $import->addColumnHandlers(
+ array_keys($extentColumnsAndPrefixes),
+ $extentColumnHandler
+ );
}
protected function setUpProcessingNoteColumnHandling(&$import)
{
- // map of extent-related column names to their corresponding prefixes
+ // map of processing-note-related column names to their corresponding
prefixes
$processingNoteColumnsAndPrefixes = array(
'ACCESSION NOTE' => "",
'ACKNOWLEDGMENT' => "Acknowledge Donor in Description? (Y/N): ",
@@ -280,35 +301,25 @@
'VanRims Number' => "Classification #: "
);
+ // 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)
{
- if ($data)
- {
- $self->rowStatusVars['processingNotes'] =
(isset($self->rowStatusVars['processingNotes']))
- ? $self->rowStatusVars['processingNotes']
- : '';
-
- $processingNoteColumnsAndPrefixes =
$self->getStatus('processingNoteColumnsAndPrefixes');
- $prefix =
$processingNoteColumnsAndPrefixes[($self->status['currentColumn'])];
- $appendValue = ($prefix) ? $prefix . $data : $data;
- if ($prefix)
- {
- $self->rowStatusVars['processingNotes'] =
$self->appendWithLineBreakIfNeeded(
- $self->rowStatusVars['processingNotes'],
- $appendValue
- );
- }
- }
+ csvAccessionImportTask::appendColumnDataToRowVarWithColumnSpecificPrefix(
+ $self,
+ $self->status['currentColumn'],
+ $data,
+ 'processingNotes',
+ $self->getStatus('processingNoteColumnsAndPrefixes')
+ );
};
// add handler for each extent-related column
- foreach($processingNoteColumnsAndPrefixes as $column => $junk)
- {
- $import->addColumnHandler($column, $processingNoteColumnHandler);
- }
-
+ $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.