Author: peter
Date: 2008-11-25 09:55:42 -0800 (Tue, 25 Nov 2008)
New Revision: 1617
Modified:
trunk/qubit/apps/qubit/lib/import/ead.yml
trunk/qubit/apps/qubit/modules/object/actions/importAction.class.php
trunk/qubit/lib/model/QubitInformationObject.php
Log:
initial commit of very basic EAD import functionality, namely for demo
purposes, lots more to come and needs QA. Also, syntax cleanup of
importAction.class.php as enforced by the Qubit coding standard pre-commit hook.
Modified: trunk/qubit/apps/qubit/lib/import/ead.yml
===================================================================
(Binary files differ)
Modified: trunk/qubit/apps/qubit/modules/object/actions/importAction.class.php
===================================================================
--- trunk/qubit/apps/qubit/modules/object/actions/importAction.class.php
2008-11-22 00:48:07 UTC (rev 1616)
+++ trunk/qubit/apps/qubit/modules/object/actions/importAction.class.php
2008-11-25 17:55:42 UTC (rev 1617)
@@ -51,7 +51,6 @@
// FIXME: hardcoded until we decide how these will be developed
$validSchemas = array(
// document type declarations
- '+//ISBN 1-931666-00-8//DTD ead.dtd (Encoded Archival Description
(EAD) Version 2002)//EN' => 'ead',
'+//ISBN 1-931666-00-8//DTD ead.dtd Encoded Archival Description (EAD)
Version 2002//EN' => 'ead',
'-//Society of American Archivists//DTD ead.dtd (Encoded Archival
Description (EAD) Version 1.0)//EN' => 'ead1',
// namespaces
@@ -96,7 +95,7 @@
$this->schemaMap = sfYaml::load($importMap);
// create the base object(s) we're importing from the schema mapping
- $this->BaseObject = eval("return new
Qubit".$this->schemaMap['BaseObject'].";");
+ $this->BaseObject = eval('return new
Qubit'.$this->schemaMap['BaseObject'].';');
// if XSLs are specified in the mapping, process them
if (!empty($this->schemaMap['processXSLT']))
@@ -159,7 +158,7 @@
$parameters = array();
foreach ($mapping['Parameters'] as $parameter)
{
- eval("\$parameters[] = ".$parameter.";");
+ eval('\$parameters[] = '.$parameter.';');
}
}
@@ -171,13 +170,13 @@
}
// create a new object if we're trying to access one that doesn't exist
- if (!eval("return isset(\$this->".$mapping['Object'].");"))
+ if (!eval('return isset(\$this->'.$mapping['Object'].');'))
{
- eval("\$this->".$mapping['Object']." = new
Qubit".$mapping['Object'].";");
+ eval('\$this->'.$mapping['Object'].' = new
Qubit'.$mapping['Object'].';');
}
// ensure the method exists on the object/class
- if (!eval("return method_exists(\$this->".$mapping['Object'].",
'".$mapping['Method']."');"))
+ if (!eval('return method_exists(\$this->'.$mapping['Object'].",
'".$mapping['Method']."');"))
{
// warning condition, import mapping has called a non-existent method
continue;
@@ -186,11 +185,32 @@
// invoke the object and method defined in the schema map
$result = eval("return
call_user_func_array(array(&\$this->\$mapping['Object'], \$mapping['Method']),
\$parameters);");
+ // Insert InformationObject specific attributes
+ //HACKISH >> TODO: see if this is the right place and way to do this
+ if ($this->BaseObject->getClassName() == 'QubitInformationObject')
+ {
+ if ($importSchema == 'ead')
+ {
+
$this->BaseObject->setCollectionTypeId(QubitTerm::ARCHIVAL_MATERIAL_ID);
+ }
+
+ // insert informationObject into a the global nested set hierarchy
for informationObjects
+ if (!isset($parentId))
+ {
+ $criteria = new Criteria;
+ $criteria = QubitInformationObject::addRootsCriteria($criteria);
+ $parentId = QubitInformationObject::getOne($criteria)->getId();
+ }
+
+ $this->BaseObject->setParentId($parentId);
+ }
+
// save the context object after every modification to ensure
referential integrity
- eval("\$this->".$mapping['Object']."->save();");
+ eval('\$this->'.$mapping['Object'].'->save();');
}
}
- return sfView::SUCCESS;
+
+ return sfView::SUCCESS;
}
/*
@@ -239,41 +259,45 @@
foreach ($attr as $name => $value)
{
- if (substr($name,0,5) == "xmlns")
+ if (substr($name,0,5) == 'xmlns')
{
$uri = $value;
$pre = $doc->documentElement->lookupPrefix($uri);
- if ($uri == "http://www.w3.org/2001/XMLSchema-instance")
- $xsi = $pre;
+ if ($uri == 'http://www.w3.org/2001/XMLSchema-instance')
+ {
+ $xsi = $pre;
+ }
$doc->namespaces[$pre] = $uri;
- if ($pre == "")
- $pre = "noname";
+ if ($pre == '')
+ {
+ $pre = 'noname';
+ }
$doc->xpath->registerNamespace($pre, $uri);
}
}
- if (!isset($doc->namespaces[""]))
+ if (!isset($doc->namespaces['']))
{
- $doc->namespaces[""] = $doc->documentElement->namespaceURI;
+ $doc->namespaces[''] = $doc->documentElement->namespaceURI;
}
if ($xsi)
{
$doc->schemaLocations = array();
- $lst = $doc->xpath->query("//@$xsi:schemaLocation");
+ $lst = $doc->xpath->query('//@$xsi:schemaLocation');
foreach ($lst as $el)
{
- $re = "{[\\s\n\r]*([^\\s\n\r]+)[\\s\n\r]*([^\\s\n\r]+)}";
- preg_match_all($re, $el->nodeValue, $mat);
- for ($i=0; $i<count($mat[0]); $i++)
- {
- $value = $mat[2][$i];
- $doc->schemaLocations[ $mat[1][$i] ] = $value;
- }
+ $re = "{[\\s\n\r]*([^\\s\n\r]+)[\\s\n\r]*([^\\s\n\r]+)}";
+ preg_match_all($re, $el->nodeValue, $mat);
+ for ($i=0; $i<count($mat[0]); $i++)
+ {
+ $value = $mat[2][$i];
+ $doc->schemaLocations[$mat[1][$i]] = $value;
+ }
}
// validate document against default namespace schema
- $doc->schemaValidate($doc->schemaLocations[$doc->namespaces[""]]);
+ $doc->schemaValidate($doc->schemaLocations[$doc->namespaces['']]);
}
return $doc;
@@ -289,12 +313,12 @@
for ($i=0; $i<count($mat[0]); $i++)
{
$value = $mat[2][$i];
- if ($value[0] == "\'" || $value[0] == "\"")
+ if ($value[0] == "\'" || $value[0] == '\"')
{
$len = strlen($value);
$value = substr($value, 1, strlen($value)-2);
}
- $att[ $mat[1][$i] ] = $value;
+ $att[$mat[1][$i]] = $value;
}
return $att;
}
@@ -302,10 +326,8 @@
private function decodeNode($node)
{
$out = $node->ownerDocument->saveXML($node);
- $re =
"{^<((?:\\w*:)?\\w*)"."[\\s\n\r]*((?:[\\s\n\r]*"."(?:\\w*:)?\\w+[\\s\n\r]*=[\\s\n\r]*"."(?:\"[^\"]*\"|\'[^\']*\'))*)"."[\\s\n\r]*>[\r\n]*"."((?:.*[\r\n]*)*)"."[\r\n]*</\\1>$}";
+ $re =
'{^<((?:\\w*:)?\\w*)'.'[\\s\n\r]*((?:[\\s\n\r]*'.'(?:\\w*:)?\\w+[\\s\n\r]*=[\\s\n\r]*'.'(?:\"[^\"]*\"|\'[^\']*\'))*)'.'[\\s\n\r]*>[\r\n]*'.'((?:.*[\r\n]*)*)'.'[\r\n]*</\\1>$}';
preg_match($re, $out, $mat);
return $mat;
}
-}
-
-?>
+}
\ No newline at end of file
Modified: trunk/qubit/lib/model/QubitInformationObject.php
===================================================================
--- trunk/qubit/lib/model/QubitInformationObject.php 2008-11-22 00:48:07 UTC
(rev 1616)
+++ trunk/qubit/lib/model/QubitInformationObject.php 2008-11-25 17:55:42 UTC
(rev 1617)
@@ -304,12 +304,13 @@
}
//TODO: like getCreationEvents, use the getActorEvents method. Need to find
out how to pass
- //the additional '$criteria->add(QubitEvent::START_DATE, null,
Criteria::ISNOTNULL)' as an $option
+ //the additional '$criteria->add(QubitEvent::DATE_DISPLAY, null,
Criteria::ISNOTNULL)' as an $option
public function getDates(array $options = array())
{
$criteria = new Criteria;
$criteria->add(QubitEvent::INFORMATION_OBJECT_ID, $this->getId());
- $criteria->add(QubitEvent::START_DATE, null, Criteria::ISNOTNULL);
+ $criteria->addJoin(QubitEvent::ID, QubitEventI18n::ID);
+ $criteria->add(QubitEventI18n::DATE_DISPLAY, null, Criteria::ISNOTNULL);
if (isset($options['type_id']))
{
$criteria->add(QubitEvent::TYPE_ID, $options['type_id']);
@@ -779,4 +780,84 @@
return $this;
}
-}
+
+ /**************
+ Import methods
+ ***************/
+
+ public function setRepositoryByName($name)
+ {
+ // see if Repository record already exists, if so link to it
+ $criteria = new Criteria;
+ $criteria->addJoin(QubitActor::ID, QubitActorI18n::ID);
+ $criteria->add(QubitActorI18n::AUTHORIZED_FORM_OF_NAME, $name);
+ if ($actor = QubitActor::getOne($criteria))
+ {
+ if ($actor->getClassName() == 'QubitRepository')
+ {
+ $this->setRepositoryId($actor->getId());
+ }
+ //TODO: figure out how to create a Repository from an existing Actor
+ //e.g. if the Actor record exists but it is not yet been used as a
Repository
+ }
+ else
+ {
+ // if the repository does not already exist, create a new Repository and
link to it
+ $repository = new QubitRepository;
+ $repository->setAuthorizedFormOfName($name);
+ $repository->save();
+ $this->setRepositoryId($repository->getId());
+ }
+
+ $this->save();
+ }
+
+ public function setCreatorByName($name)
+ {
+ // see if the Actor record already exists, if not create it
+ $criteria = new Criteria;
+ $criteria->addJoin(QubitActor::ID, QubitActorI18n::ID);
+ $criteria->add(QubitActorI18n::AUTHORIZED_FORM_OF_NAME, $name);
+ if (null === $actor = QubitActor::getOne($criteria))
+ {
+ $actor = new QubitActor;
+ $actor->setAuthorizedFormOfName($name);
+ /*
+ if (isset($options['type']))
+ {
+ // set actor entityTypeId
+ }
+ */
+
+ $actor->save();
+ }
+
+ // create an event object to link the information object and actor
+ $event = new QubitEvent;
+ $event->setInformationObjectId($this->getId());
+ $event->setActorId($actor->getId());
+ $event->setTypeId(QubitTerm::CREATION_ID);
+
+ $event->save();
+ }
+
+ public function setLevelOfDescriptionByName()
+ {
+ }
+
+ public function setDates($date)
+ {
+ // create an event object to link the information object
+ // assume the event type is creation for now
+ // TODO: detect event type
+ // TODO: detect normalized dates and enter ISO dates
+ // TODO: link event to an actor where possible
+ $event = new QubitEvent;
+ $event->setInformationObjectId($this->getId());
+ $event->setTypeId(QubitTerm::CREATION_ID);
+ $event->setDateDisplay($date);
+
+ $event->save();
+ }
+
+}
\ No newline at end of file
--~--~---------~--~----~------------~-------~--~----~
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.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---