101 import(
'lib.pkp.classes.core.DataObject');
 
  103 define(
'METADATA_DESCRIPTION_REPLACE_ALL', 0x01);
 
  104 define(
'METADATA_DESCRIPTION_REPLACE_PROPERTIES', 0x02);
 
  105 define(
'METADATA_DESCRIPTION_REPLACE_NOTHING', 0x03);
 
  107 define(
'METADATA_DESCRIPTION_UNKNOWN_LOCALE', 
'unknown');
 
  137    function __construct($metadataSchemaName, $assocType) {
 
  138       assert(is_string($metadataSchemaName) && is_integer($assocType));
 
  139       parent::__construct();
 
  140       $this->_metadataSchemaName = $metadataSchemaName;
 
  141       $this->_assocType = $assocType;
 
  162       if (is_null($this->_metadataSchema)) {
 
  164          assert(is_object($this->_metadataSchema));
 
  190       $this->_assocId = $assocId;
 
  202       assert(isset($assocType) && isset($assocId));
 
  203       return $assocType.
':'.$assocId;
 
  211       $this->_displayName = $displayName;
 
  249    function addStatement($propertyName, $value, $locale = 
null, $replace = 
false) {
 
  252       if (is_null($property)) 
return false;
 
  253       assert(is_a($property, 
'MetadataProperty'));
 
  256       if (!in_array($this->_assocType, $property->getAssocTypes())) 
return false;
 
  259       $translated = $property->getTranslated();
 
  260       if (isset($locale) && !$translated) 
return false;
 
  261       if (!isset($locale) && $translated) {
 
  267       if ($property->isValid($value, $locale) === 
false) 
return false;
 
  270       $existingValue =& $this->
getStatement($propertyName, $locale);
 
  271       switch ($property->getCardinality()) {
 
  272          case METADATA_PROPERTY_CARDINALITY_ONE:
 
  273             if (isset($existingValue) && !$replace) 
return false;
 
  277          case METADATA_PROPERTY_CARDINALITY_MANY:
 
  278             if (isset($existingValue) && !$replace) {
 
  279                assert(is_array($existingValue));
 
  280                $newValue = $existingValue;
 
  281                array_push($newValue, $value);
 
  283                $newValue = array($value);
 
  292       $this->
setData($propertyName, $newValue, $locale);
 
  307       if (isset($propertyName) && $this->
hasData($propertyName, $locale)) {
 
  308          $this->
setData($propertyName, 
null, $locale);
 
  326       unset($allData[
'id']);
 
  340       assert(isset($property) && is_a($property, 
'MetadataProperty'));
 
  343       $translated = $property->getTranslated();
 
  344       if (!$translated) assert(is_null($locale));
 
  345       if ($translated && !isset($locale)) {
 
  351       return $this->
getData($propertyName, $locale);
 
  364       return $this->
getData($propertyName);
 
  381    function setStatements(&$statements, $replace = METADATA_DESCRIPTION_REPLACE_PROPERTIES) {
 
  387       if ($replace == METADATA_DESCRIPTION_REPLACE_ALL) {
 
  389          $emptyArray = array();
 
  394       foreach($statements as $propertyName => $content) {
 
  395          assert(!empty($content));
 
  400          if (is_scalar($content) || is_string(key($content))) {
 
  401             $values = array(&$content);
 
  406          if ($replace == METADATA_DESCRIPTION_REPLACE_PROPERTIES) {
 
  407             $replaceProperty = 
true;
 
  409             $replaceProperty = 
false;
 
  413          foreach($values as $value) {
 
  414             $firstValue = ($valueIndex == 0) ? 
true : 
false;
 
  416             if (is_array($value)) {
 
  417                foreach($value as $locale => $translation) {
 
  419                   if (is_scalar($translation)) {
 
  420                      $translationValues = array(&$translation);
 
  422                      $translationValues =& $translation;
 
  424                   $translationIndex = 0;
 
  425                   foreach($translationValues as $translationValue) {
 
  426                      $firstTranslation = ($translationIndex == 0) ? 
true : 
false;
 
  428                      if (!($this->
addStatement($propertyName, $translationValue, $locale, $firstTranslation && $replaceProperty))) {
 
  432                      unset($translationValue);
 
  435                   unset($translationValues);
 
  440                if (!($this->
addStatement($propertyName, $value, 
null, $firstValue && $replaceProperty))) {
 
  460       return $metadataSchema->getProperties();
 
  471       return $metadataSchema->getProperty($propertyName);
 
  482       return $metadataSchema->getNamespacedPropertyId($propertyName);
 
  492       return $metadataSchema->getPropertyNames();
 
  503       return $metadataSchema->getPropertyNamesByType($propertyType);
 
  523       return $metadataSchema->hasProperty($propertyName);
 
  533       return (isset($statements[$propertyName]));
 
  544       assert(is_a($property, 
'MetadataProperty'));
 
  545       return $property->getTranslated();
 
  557       static $allowedReplaceLevels = array(
 
  558          METADATA_DESCRIPTION_REPLACE_ALL,
 
  559          METADATA_DESCRIPTION_REPLACE_PROPERTIES,
 
  560          METADATA_DESCRIPTION_REPLACE_NOTHING
 
  562       return $allowedReplaceLevels;