Author: david
Date: Tue Jan 10 14:31:19 2012
New Revision: 10627
Log:
Set entity_type_id
Modified:
trunk/lib/task/csvIsaarImportTask.class.php
trunk/plugins/sfIsaarPlugin/lib/qtIsaarCsv.class.php
Modified: trunk/lib/task/csvIsaarImportTask.class.php
==============================================================================
--- trunk/lib/task/csvIsaarImportTask.class.php Tue Jan 10 14:07:25 2012
(r10626)
+++ trunk/lib/task/csvIsaarImportTask.class.php Tue Jan 10 14:31:19 2012
(r10627)
@@ -74,13 +74,6 @@
$databaseManager = new sfDatabaseManager($this->configuration);
$conn = $databaseManager->getDatabase('propel')->getConnection();
- // Load taxonomies into variables to avoid use of magic numbers
- $termData = $this->loadTaxonomyTerms(array(
- QubitTaxonomy::NOTE_TYPE_ID => 'noteTypes',
- QubitTaxonomy::RAD_TITLE_NOTE_ID => 'titleNoteTypes',
- QubitTaxonomy::MATERIAL_TYPE_ID => 'materialTypes'
- ));
-
// First row is header
$header = fgetcsv($fh);
@@ -90,7 +83,10 @@
$importColumns = array_intersect($header, qtIsaarCsv::$NAMES);
// Set source file
- qtIsaarCsv::$keymap_source = basename($arguments['filename']);
+ qtIsaarCsv::$keymapSource = basename($arguments['filename']);
+
+ // Load entity type taxonomy
+ qtIsaarCsv::$entityTypeLookup =
self::getTermsForLookup(QubitTaxonomy::ACTOR_ENTITY_TYPE_ID, $conn);
while ($row = fgetcsv($fh))
{
@@ -107,24 +103,38 @@
$isaarCsv->save();
$this->count++;
+
+//DEBUGGING: stop after two rows
+ if (1 < $this->count)
+ {
+ break;
+ }
}
fclose($fh);
}
- protected function loadTaxonomyTerms($taxonomies)
+ protected function getTermsForLookup($taxonomyId, $connection)
{
- $taxonomyTerms = array();
+ $query = "SELECT term.id, i18n.name
+ FROM ".QubitTerm::TABLE_NAME." term JOIN ".QubitTermI18n::TABLE_NAME."
i18n
+ ON term.id = i18n.id
+ WHERE term.taxonomy_id = ?
+ AND i18n.culture = 'en';";
+
+ $statement = $connection->prepare($query);
+ $statement->bindValue(1, $taxonomyId, PDO::PARAM_INT);
+ if (false === $statement->execute())
+ {
+ return;
+ }
- foreach($taxonomies as $taxonomyId => $varName)
+ while ($row = $statement->fetch(PDO::FETCH_NUM))
{
- $taxonomyTerms[$varName] = array();
- foreach(QubitFlatfileImport::getTaxonomyTerms($taxonomyId) as $termId =>
$term)
- {
- $taxonomyTerms[$varName][$termId] = $term->name;
- }
+ // key on lowercase term name
+ $terms[strtolower($row[1])] = $row[0];
}
- return $taxonomyTerms;
+ return $terms;
}
}
Modified: trunk/plugins/sfIsaarPlugin/lib/qtIsaarCsv.class.php
==============================================================================
--- trunk/plugins/sfIsaarPlugin/lib/qtIsaarCsv.class.php Tue Jan 10
14:07:25 2012 (r10626)
+++ trunk/plugins/sfIsaarPlugin/lib/qtIsaarCsv.class.php Tue Jan 10
14:31:19 2012 (r10627)
@@ -33,14 +33,15 @@
$sourceId;
public static
- $keymap_source,
- $keymap_target = 'actor',
+ $keymapSource,
+ $keymapTarget = 'actor',
+ $entityTypeLookup,
$NAMES = array(
'authorizedFormOfName',
'datesOfExistence',
'descriptionIdentifier',
- //'entityType',
+ 'entityType',
'functions',
'generalContext',
'history',
@@ -91,6 +92,14 @@
{
switch ($name)
{
+ case 'entityType':
+ $value = strtolower($value);
+ if (isset(self::$entityTypeLookup[$value]))
+ {
+ $this->resource->entityTypeId = self::$entityTypeLookup[$value];
+ }
+ break;
+
case 'maintenanceNotes':
$this->isaar->maintenanceNotes = $value;
break;
@@ -113,9 +122,9 @@
// Add to keymap table
$keymap = new QubitKeymap;
- $keymap->sourceName = self::$keymap_source;
+ $keymap->sourceName = self::$keymapSource;
$keymap->sourceId = $this->sourceId;
- $keymap->targetName = self::$keymap_target;
+ $keymap->targetName = self::$keymapTarget;
$keymap->targetId = $this->resource->id;
$keymap->save($connection);
--
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.