예제 #1
0
 /**
  * Initialize form data from the associated citation.
  * @param $citation Citation
  */
 function initData()
 {
     $citation =& $this->getCitation();
     // The unparsed citation text
     $this->setData('editedCitation', $citation->getEditedCitation());
     // Citation meta-data
     foreach ($citation->getSupportedMetadataAdapters() as $metadataAdapter) {
         // Retrieve the meta-data schema
         $metadataSchema =& $metadataAdapter->getMetadataSchema();
         $metadataSchemaNamespace = $metadataSchema->getNamespace();
         // Loop over the properties in the schema and add string
         // values for all form fields.
         $citationVars = array();
         $properties = $metadataSchema->getProperties();
         $metadataDescription =& $citation->extractMetadata($metadataSchema);
         foreach ($properties as $propertyName => $property) {
             if ($metadataDescription->hasStatement($propertyName)) {
                 $value = $metadataDescription->getStatement($propertyName);
                 if ($property->getType() == METADATA_PROPERTY_TYPE_COMPOSITE) {
                     // We currently only support composite name arrays
                     assert(in_array($property->getCompositeType(), array(ASSOC_TYPE_AUTHOR, ASSOC_TYPE_EDITOR)));
                     import('metadata.nlm.NlmNameSchemaPersonStringFilter');
                     $personStringFilter = new NlmNameSchemaPersonStringFilter(PERSON_STRING_FILTER_MULTIPLE);
                     assert($personStringFilter->supportsAsInput($value));
                     $fieldValue = $personStringFilter->execute($value);
                 } else {
                     // We currently don't support repeated values
                     if ($property->getCardinality() == METADATA_PROPERTY_CARDINALITY_MANY && !empty($value)) {
                         assert(is_array($value) && count($value) <= 1);
                         $value = $value[0];
                     }
                     $fieldValue = (string) $value;
                 }
             } else {
                 $fieldValue = '';
             }
             $fieldName = $metadataSchema->getNamespacedPropertyId($propertyName);
             $citationVars[$fieldName] = array('translationKey' => $property->getDisplayName(), 'value' => $fieldValue);
         }
     }
     $this->setData('citationVars', $citationVars);
 }
 /**
  * Take a structured meta-data statement and transform it into a
  * plain text value that can be displayed to the end-user.
  *
  * @param $property MetadataProperty
  * @param $value mixed
  * @return string
  */
 function _getStringValueFromMetadataStatement(&$property, &$value)
 {
     if ($property->getCardinality() == METADATA_PROPERTY_CARDINALITY_MANY && !empty($value)) {
         $allowedTypes = $property->getAllowedTypes();
         if (isset($allowedTypes[METADATA_PROPERTY_TYPE_COMPOSITE])) {
             // We currently only can transform composite
             // name arrays to strings.
             $allowedAssocTypes = $allowedTypes[METADATA_PROPERTY_TYPE_COMPOSITE];
             assert(in_array(ASSOC_TYPE_AUTHOR, $allowedAssocTypes) || in_array(ASSOC_TYPE_EDITOR, $allowedAssocTypes));
             import('lib.pkp.classes.metadata.nlm.NlmNameSchemaPersonStringFilter');
             $personStringFilter = new NlmNameSchemaPersonStringFilter(PERSON_STRING_FILTER_MULTIPLE);
             assert($personStringFilter->supportsAsInput($value));
             $stringValue = $personStringFilter->execute($value);
         } else {
             // We currently can't transform properties of
             // cardinality "many" to strings.
             assert(is_array($value) && count($value) <= 1);
             $stringValue = $value[0];
         }
     } else {
         $stringValue = (string) $value;
     }
     return $stringValue;
 }
예제 #3
0
 /**
  * Initialize form data from the associated citation.
  * @param $citation Citation
  */
 function initData()
 {
     $citation =& $this->getCitation();
     // The unparsed citation text and the citation state
     $this->setData('editedCitation', $citation->getEditedCitation());
     // Citation meta-data
     foreach ($citation->getSupportedMetadataAdapters() as $metadataAdapter) {
         // Retrieve the meta-data schema
         $metadataSchema =& $metadataAdapter->getMetadataSchema();
         $metadataSchemaNamespace = $metadataSchema->getNamespace();
         // Loop over the properties in the schema and add string
         // values for all form fields.
         $citationVars = array();
         $citationVarsEmpty = array();
         $properties = $metadataSchema->getProperties();
         $metadataDescription =& $citation->extractMetadata($metadataSchema);
         foreach ($properties as $propertyName => $property) {
             if ($metadataDescription->hasStatement($propertyName)) {
                 $value = $metadataDescription->getStatement($propertyName);
                 if ($property->getCardinality() == METADATA_PROPERTY_CARDINALITY_MANY && !empty($value)) {
                     // FIXME: The following is a work-around until we completely
                     // implement #5171 ("author: et.al"). Then we have to support
                     // true multi-type properties.
                     if (is_a($value[0], 'MetadataDescription')) {
                         // We currently only support composite name arrays
                         assert(in_array($value[0]->getAssocType(), array(ASSOC_TYPE_AUTHOR, ASSOC_TYPE_EDITOR)));
                         import('metadata.nlm.NlmNameSchemaPersonStringFilter');
                         $personStringFilter = new NlmNameSchemaPersonStringFilter(PERSON_STRING_FILTER_MULTIPLE);
                         assert($personStringFilter->supportsAsInput($value));
                         $fieldValue = $personStringFilter->execute($value);
                     } else {
                         // We currently don't support repeated values
                         assert(is_array($value) && count($value) <= 1);
                         $fieldValue = $value[0];
                     }
                 } else {
                     $fieldValue = (string) $value;
                 }
             } else {
                 $fieldValue = '';
             }
             $fieldName = $metadataSchema->getNamespacedPropertyId($propertyName);
             if ($fieldValue != '') {
                 $citationVars[$fieldName] = array('translationKey' => $property->getDisplayName(), 'value' => $fieldValue);
             } else {
                 $citationVarsEmpty[$fieldName] = array('translationKey' => $property->getDisplayName(), 'value' => $fieldValue);
             }
         }
     }
     // FIXME: at the moment, we just create two tabs -- one for filled elements, and one for empty ones.
     // any number of elements can be added, and they will appear as new tabs on the modal window.
     $citationVarArrays = array("Filled Elements" => $citationVars, "Empty Elements" => $citationVarsEmpty);
     $this->setData('citationVarArrays', $citationVarArrays);
     $this->setData('ts', time());
 }