Author: mcantelon
Date: Tue Jan 3 14:44:53 2012
New Revision: 10543
Log:
Added support for radGeneralMaterialDesignation import column.
Modified:
trunk/lib/task/csvImportTask.class.php
Modified: trunk/lib/task/csvImportTask.class.php
==============================================================================
--- trunk/lib/task/csvImportTask.class.php Tue Jan 3 14:42:10 2012
(r10542)
+++ trunk/lib/task/csvImportTask.class.php Tue Jan 3 14:44:53 2012
(r10543)
@@ -67,12 +67,14 @@
);
$defaultStatusTypeId = QubitTerm::STATUS_TYPE_PUBLICATION_ID;
- // Get note type ID => name mapping for note types
- $noteTaxonomies = array(
+ // Load taxonomies into variables to avoid use of magic numbers
+ $taxonomies = array(
QubitTaxonomy::NOTE_TYPE_ID => 'noteTypes',
- QubitTaxonomy::RAD_TITLE_NOTE_ID => 'titleNoteTypes'
+ QubitTaxonomy::RAD_TITLE_NOTE_ID => 'titleNoteTypes',
+ QubitTaxonomy::MATERIAL_TYPE_ID => 'materialTypes'
);
- foreach($noteTaxonomies as $taxonomyId => $varName)
+
+ foreach($taxonomies as $taxonomyId => $varName)
{
$$varName = array();
foreach(QubitFlatfileImport::getTaxonomyTerms($taxonomyId) as $termId =>
$term)
@@ -81,6 +83,9 @@
}
}
+ // hack to make this accessible from closure
+ $GLOBALS['materialTypes'] = $materialTypes;
+
// Define import
$import = new QubitFlatfileImport(array(
'columns' => fgetcsv($fh, 60000), // 1st row supplies column names/order
@@ -196,9 +201,11 @@
}
}
- if (isset($self->rowStatusVars['nameAccessPoints'])) {
+ if (isset($self->rowStatusVars['nameAccessPoints']))
+ {
// add name access points
- foreach($self->rowStatusVars['nameAccessPoints'] as $name) {
+ foreach($self->rowStatusVars['nameAccessPoints'] as $name)
+ {
$actor = $self->createOrFetchActor($name);
$relation = new QubitRelation;
$relation->subjectId = $self->informationObject->id;
@@ -225,6 +232,15 @@
}
}
+ // add material-related term relation
+ if (isset($self->rowStatusVars['radGeneralMaterialDesignation']))
+ {
+ $self->createObjectTermRelation(
+ $self->informationObject->id,
+ $self->rowStatusVars['radGeneralMaterialDesignation']
+ );
+ }
+
if (isset($self->rowStatusVars['creators'])
&& count($self->rowStatusVars['creators']))
{
@@ -341,6 +357,32 @@
}
});
+ $import->addColumnHandler('radGeneralMaterialDesignation',
function(&$self, $data)
+ {
+ if ($data)
+ {
+ $cvaToQubit = array(
+ 'Text' => 'Textual record',
+ 'Photo' => 'Graphic material'
+ );
+
+ if (isset($cvaToQubit[$data]))
+ {
+ $materialTermName = $cvaToQubit[$data];
+ if (in_array($materialTermName, $GLOBALS['materialTypes']))
+ {
+ $termId = array_search($materialTermName,
$GLOBALS['materialTypes']);
+ // lookup material taxonomy ID from materialTypes
+ $self->rowStatusVars['radGeneralMaterialDesignation'] = $termId;
+ } else {
+ die('Could not find "'. $materialTermName .'" in materialTypes
array.');
+ }
+ } else {
+ die('Could not find a way to handle radGeneralMaterialDesignation
value "'. $data .'".');
+ }
+ }
+ });
+
$import->csv($fh);
}
}
--
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.