From 530d75fdf0fa44de9deca93c7bae4fa31c912611 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 14 Nov 2016 11:04:57 +0100 Subject: [PATCH 1/4] getValueAsArray() checks if value starts with separator new funtion parseValue() --- SeedDMS_Core/Core/inc.ClassAttribute.php | 41 +++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/SeedDMS_Core/Core/inc.ClassAttribute.php b/SeedDMS_Core/Core/inc.ClassAttribute.php index b1bc22a2c..ed4828de0 100644 --- a/SeedDMS_Core/Core/inc.ClassAttribute.php +++ b/SeedDMS_Core/Core/inc.ClassAttribute.php @@ -117,7 +117,17 @@ class SeedDMS_Core_Attribute { /* {{{ */ */ function getValueAsArray() { /* {{{ */ if($this->_attrdef->getMultipleValues()) { - return explode($this->_value[0], substr($this->_value, 1)); + /* If the value doesn't start with the separator used in the value set, + * then assume that the value was not saved with a leading separator. + * This can happen, if the value was previously a single value from + * the value set and later turned into a multi value attribute. + */ + $sep = substr($this->_value, 0, 1); + $vsep = $this->_attrdef->getValueSetSeparator(); + if($sep == $vsep) + return(explode($sep, substr($this->_value, 1))); + else + return(array($this->_value)); } else { return array($this->_value); } @@ -684,6 +694,35 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ return true; } /* }}} */ + /** + * Parse a given value according to attribute definition + * + * The return value is always an array, even if the attribute is single + * value attribute. + * + * @return array list of single values + */ + function parseValue($value) { /* {{{ */ + $db = $this->_dms->getDB(); + + if($this->getMultipleValues()) { + /* If the value doesn't start with the separator used in the value set, + * then assume that the value was not saved with a leading separator. + * This can happen, if the value was previously a single value from + * the value set and later turned into a multi value attribute. + */ + $sep = substr($value, 0, 1); + $vsep = $this->getValueSetSeparator(); + if($sep == $vsep) + return(explode($sep, substr($value, 1))); + else + return(array($value)); + } else { + return array($value); + } + return true; + } /* }}} */ + /** * Return a list of documents, folders, document contents where this * attribute definition is used From a1f6bd9a7d98f42957681b963a67cbab02b3d76b Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 14 Nov 2016 11:05:57 +0100 Subject: [PATCH 2/4] getAttributeValue() checks if value starts with seperator --- SeedDMS_Core/Core/inc.ClassObject.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SeedDMS_Core/Core/inc.ClassObject.php b/SeedDMS_Core/Core/inc.ClassObject.php index 10fa89755..61455e791 100644 --- a/SeedDMS_Core/Core/inc.ClassObject.php +++ b/SeedDMS_Core/Core/inc.ClassObject.php @@ -117,7 +117,16 @@ class SeedDMS_Core_Object { /* {{{ */ $value = $this->_attributes[$attrdef->getId()]->getValue(); if($attrdef->getMultipleValues()) { $sep = substr($value, 0, 1); - return(explode($sep, substr($value, 1))); + $vsep = $attrdef->getValueSetSeparator(); + /* If the value doesn't start with the separator used in the value set, + * then assume that the value was not saved with a leading separator. + * This can happen, if the value was previously a single value from + * the value set and later turned into a multi value attribute. + */ + if($sep == $vsep) + return(explode($sep, substr($value, 1))); + else + return(array($value)); } else { return $value; } From 6a059c9a1bba8642a9dbe977c886777f751c656f Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 14 Nov 2016 11:06:38 +0100 Subject: [PATCH 3/4] propperly check for multiple values --- views/bootstrap/class.AttributeMgr.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/views/bootstrap/class.AttributeMgr.php b/views/bootstrap/class.AttributeMgr.php index 583f39066..bfb80af3a 100644 --- a/views/bootstrap/class.AttributeMgr.php +++ b/views/bootstrap/class.AttributeMgr.php @@ -92,14 +92,17 @@ $(document).ready( function() { print "\n"; print "\n\n"; foreach($res['frequencies'][$type] as $entry) { + $value = $selattrdef->parseValue($entry['value']); echo ""; - echo "".$entry['value']."".$entry['c'].""; + echo "".implode(';', $value)."".$entry['c'].""; /* various checks, if the value is valid */ echo ""; /* Check if value is in value set */ if($selattrdef->getValueSet()) { - if(in_array($entry['value'], $selattrdef->getValueSetAsArray())) - printMLText("attribute_value_not_in_valueset"); + foreach($values as $v) { + if(!in_array($value, $selattrdef->getValueSetAsArray())) + printMLText("attribute_value_not_in_valueset"); + } } echo ""; echo ""; From 38cdbe04d2c74d0889b1e4a93fc70a1c0f1be296 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 14 Nov 2016 11:07:03 +0100 Subject: [PATCH 4/4] add notes --- SeedDMS_Core/package.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/SeedDMS_Core/package.xml b/SeedDMS_Core/package.xml index f1e70b47a..a116e5880 100644 --- a/SeedDMS_Core/package.xml +++ b/SeedDMS_Core/package.xml @@ -26,6 +26,7 @@ - new method SeedDMЅ_Core_WorkflowAction::getTransitions() - new method SeedDMЅ_Core_WorkflowState::getTransitions() +- new method SeedDMЅ_Core_AttributeDefinition::parseValue()