23 import(
'lib.pkp.classes.filter.PersistableFilter');
24 import(
'lib.pkp.classes.metadata.MetadataDescription');
26 define(
'METADATA_DOA_INJECTION_MODE', 0x01);
27 define(
'METADATA_DOA_EXTRACTION_MODE', 0x02);
57 parent::__construct($filterGroup);
63 $metadataTypeDescription =
null;
64 $dataObjectTypeDescription =
null;
68 if (is_a($inputType,
'MetadataTypeDescription')) {
69 $mode = METADATA_DOA_INJECTION_MODE;
71 $mode = METADATA_DOA_EXTRACTION_MODE;
76 if ($mode == METADATA_DOA_INJECTION_MODE) {
78 $metadataTypeDescription =& $inputType;
79 assert(is_a($outputType,
'ClassTypeDescription'));
80 $dataObjectTypeDescription =& $outputType;
83 assert(is_a($outputType,
'MetadataTypeDescription'));
84 $metadataTypeDescription =& $outputType;
85 assert(is_a($inputType,
'ClassTypeDescription'));
86 $dataObjectTypeDescription =& $inputType;
90 $this->_metadataSchemaName = $metadataTypeDescription->getMetadataSchemaClass();
91 $this->_assocType = $metadataTypeDescription->getAssocType();
92 $this->_dataObjectName = $dataObjectTypeDescription->getTypeName();
95 if ($mode == METADATA_DOA_INJECTION_MODE) {
129 if (is_null($this->_metadataSchema)) {
131 assert(!is_null($metadataSchemaName));
132 $this->_metadataSchema =&
instantiate($metadataSchemaName,
'MetadataSchema');
133 assert(is_object($this->_metadataSchema));
145 return $metadataSchema->getNamespace();
163 if (is_null($this->_dataObjectClass)) {
165 assert(!is_null($dataObjectName));
166 $dataObjectNameParts = explode(
'.', $dataObjectName);
167 $this->_dataObjectClass = array_pop($dataObjectNameParts);
186 $this->_targetDataObject =& $targetDataObject;
194 return $this->_targetDataObject;
252 case METADATA_DOA_INJECTION_MODE:
256 if (is_null($targetDataObject)) {
265 case METADATA_DOA_EXTRACTION_MODE:
293 assert(!is_null($dataObjectName));
305 return $metadataDescription;
317 if (is_null($this->_metadataFieldNames)) {
319 $this->_metadataFieldNames = array();
324 $metadataSchemaNamespace = $metadataSchema->getNamespace();
325 $properties =& $metadataSchema->getProperties();
326 foreach($properties as $property) {
327 $propertyAssocTypes = $property->getAssocTypes();
328 if (in_array($this->_assocType, $propertyAssocTypes)) {
332 $this->_metadataFieldNames[$property->getTranslated()][] = $metadataSchemaNamespace.
':'.$property->getName();
338 return $this->_metadataFieldNames[$translated];
348 if (is_array($localizedValues)) {
349 foreach ($localizedValues as $locale => $values) {
351 if (is_scalar($values)) $values = array($values);
352 foreach($values as $value) {
353 $metadataDescription->addStatement($propertyName, $value, $locale);
369 foreach(array(
true,
false) as $translated) {
373 list($namespace, $propertyName) = explode(
':', $unmappedProperty);
376 if ($metadataDescription->hasStatement($propertyName)) {
380 $dataObject->setData($unmappedProperty, $metadataDescription->getStatementTranslations($propertyName));
382 $dataObject->setData($unmappedProperty, $metadataDescription->getStatement($propertyName));
397 $handledNamespace = $metadataSchema->getNamespace();
400 foreach(array(
true,
false) as $translated) {
404 if ($dataObject->hasData($unmappedProperty)) {
406 list($namespace, $propertyName) = explode(
':', $unmappedProperty);
411 if ($namespace == $handledNamespace && $metadataSchema->hasProperty($propertyName)) {
414 $this->
addLocalizedStatements($metadataDescription, $propertyName, $dataObject->getData($unmappedProperty));
416 $metadataDescription->addStatement($propertyName, $dataObject->getData($unmappedProperty));