fix handling of multivalue attributes

This commit is contained in:
Uwe Steinmann 2014-02-20 21:03:03 +01:00
parent 41469a4570
commit 5c07f7545b

View File

@ -105,16 +105,23 @@ class SeedDMS_Core_Object { /* {{{ */
/** /**
* Returns an attribute of the object for the given attribute definition * Returns an attribute of the object for the given attribute definition
* *
* @return object object of class SeedDMS_Core_Attribute or false * @return array|string value of attritbute or false. The value is an array
* if the attribute is defined as multi value
*/ */
function getAttributeValue($attrdef) { /* {{{ */ function getAttributeValue($attrdef) { /* {{{ */
if (!$this->_attributes) { if (!$this->_attributes) {
$this->getAttributes(); $this->getAttributes();
} }
if (isset($this->_attributes[$attrdef->getId()])) if (isset($this->_attributes[$attrdef->getId()])) {
return $this->_attributes[$attrdef->getId()]->getValue(); $value = $this->_attributes[$attrdef->getId()]->getValue();
else if($attrdef->getMultipleValues()) {
$sep = substr($value, 0, 1);
return(explode($sep, substr($value, 1)));
} else {
return $value;
}
} else
return false; return false;
} /* }}} */ } /* }}} */
@ -122,6 +129,9 @@ class SeedDMS_Core_Object { /* {{{ */
/** /**
* Set an attribute of the object for the given attribute definition * Set an attribute of the object for the given attribute definition
* *
* @param object $attrdef definition of attribute
* @param array|sting $value value of attribute, for multiple values this
* must be an array
* @return boolean true if operation was successful, otherwise false * @return boolean true if operation was successful, otherwise false
*/ */
function setAttributeValue($attrdef, $value) { /* {{{ */ function setAttributeValue($attrdef, $value) { /* {{{ */
@ -129,6 +139,10 @@ class SeedDMS_Core_Object { /* {{{ */
if (!$this->_attributes) { if (!$this->_attributes) {
$this->getAttributes(); $this->getAttributes();
} }
if($attrdef->getMultipleValues() && is_array($value)) {
$sep = substr($attrdef->getValueSet(), 0, 1);
$value = $sep.implode($sep, $value);
}
if(!isset($this->_attributes[$attrdef->getId()])) { if(!isset($this->_attributes[$attrdef->getId()])) {
switch(get_class($this)) { switch(get_class($this)) {
case "SeedDMS_Core_Document": case "SeedDMS_Core_Document":