add new method getAttribute()

This commit is contained in:
Uwe Steinmann 2015-04-15 14:11:21 +02:00
parent 49afb6cfd6
commit 444d3a8b01

View File

@ -108,6 +108,25 @@ class SeedDMS_Core_Object { /* {{{ */
* @return array|string value of attritbute or false. The value is an array * @return array|string value of attritbute or false. The value is an array
* if the attribute is defined as multi value * if the attribute is defined as multi value
*/ */
function getAttribute($attrdef) { /* {{{ */
if (!$this->_attributes) {
$this->getAttributes();
}
if (isset($this->_attributes[$attrdef->getId()])) {
return $this->_attributes[$attrdef->getId()];
} else {
return false;
}
} /* }}} */
/**
* Returns an attribute value of the object for the given attribute definition
*
* @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();
@ -126,6 +145,50 @@ class SeedDMS_Core_Object { /* {{{ */
} /* }}} */ } /* }}} */
/**
* Returns an attribute value of the object for the given attribute definition
*
* This is a short cut for getAttribute($attrdef)->getValueAsArray() but
* first checks if the object has an attribute for the given attribute
* definition.
*
* @return array value of attritbute or false. The value is always an array
* even if the attribute is not defined as multi value
*/
function getAttributeValueAsArray($attrdef) { /* {{{ */
if (!$this->_attributes) {
$this->getAttributes();
}
if (isset($this->_attributes[$attrdef->getId()])) {
return $this->_attributes[$attrdef->getId()]->getValueAsArray();
} else
return false;
} /* }}} */
/**
* Returns an attribute value of the object for the given attribute definition
*
* This is a short cut for getAttribute($attrdef)->getValueAsString() but
* first checks if the object has an attribute for the given attribute
* definition.
*
* @return string value of attritbute or false. The value is always a string
* even if the attribute is defined as multi value
*/
function getAttributeValueAsString($attrdef) { /* {{{ */
if (!$this->_attributes) {
$this->getAttributes();
}
if (isset($this->_attributes[$attrdef->getId()])) {
return $this->_attributes[$attrdef->getId()]->getValue();
} else
return false;
} /* }}} */
/** /**
* Set an attribute of the object for the given attribute definition * Set an attribute of the object for the given attribute definition
* *