From 444d3a8b01059878201035fdd0696f3f156dfaed Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 15 Apr 2015 14:11:21 +0200 Subject: [PATCH] add new method getAttribute() --- SeedDMS_Core/Core/inc.ClassObject.php | 63 +++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/SeedDMS_Core/Core/inc.ClassObject.php b/SeedDMS_Core/Core/inc.ClassObject.php index b7db8d084..36bede8a8 100644 --- a/SeedDMS_Core/Core/inc.ClassObject.php +++ b/SeedDMS_Core/Core/inc.ClassObject.php @@ -108,6 +108,25 @@ class SeedDMS_Core_Object { /* {{{ */ * @return array|string value of attritbute or false. The value is an array * 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) { /* {{{ */ if (!$this->_attributes) { $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 *