diff --git a/SeedDMS_Core/Core/inc.ClassAttribute.php b/SeedDMS_Core/Core/inc.ClassAttribute.php index 857b15ab4..2e9e6d11c 100644 --- a/SeedDMS_Core/Core/inc.ClassAttribute.php +++ b/SeedDMS_Core/Core/inc.ClassAttribute.php @@ -800,12 +800,52 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ $sep = substr($value, 0, 1); $vsep = $this->getValueSetSeparator(); if($sep == $vsep) - return(explode($sep, substr($value, 1))); + $values = explode($sep, substr($value, 1)); else - return(array($value)); + $values = array($value); } else { - return array($value); + $values = array($value); } + + switch((string) $this->getType()) { + case self::type_document: + foreach($values as $value) { + if($u = $this->_dms->getDocument((int) $value)) + $tmp[] = $u->getName(); + else + $tmp[] = '???'; + } + $values = $tmp; + break; + case self::type_folder: + foreach($values as $value) { + if($u = $this->_dms->getFolder((int) $value)) + $tmp[] = $u->getName(); + else + $tmp[] = '???'; + } + $values = $tmp; + break; + case self::type_user: + foreach($values as $value) { + if($u = $this->_dms->getUser((int) $value)) + $tmp[] = $u->getLogin(); + else + $tmp[] = '???'; + } + $values = $tmp; + break; + case self::type_group: + foreach($values as $value) { + if($u = $this->_dms->getGroup((int) $value)) + $tmp[] = $u->getName(); + else + $tmp[] = '???'; + } + $values = $tmp; + break; + } + return $values; } /* }}} */ /** @@ -1084,6 +1124,12 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ } } + /* Turn $attrvalue into an array of values. Checks if $attrvalue starts + * with a separator char as set in the value set and uses it to explode + * the $attrvalue. If the separator doesn't match or this attribute + * definition doesn't have a value set, then just create a one element + * array. if $attrvalue is empty, then create an empty array. + */ if($this->getMultipleValues()) { if(is_string($attrvalue)) { $sep = $attrvalue[0]; @@ -1100,11 +1146,13 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ $values = array(); } + /* Check if attribute value has at least the minimum number of values */ $this->_validation_error = 0; if($this->getMinValues() > count($values)) { $this->_validation_error = 1; return false; } + /* Check if attribute value has not more than maximum number of values */ if($this->getMaxValues() && $this->getMaxValues() < count($values)) { $this->_validation_error = 2; return false; @@ -1163,6 +1211,42 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ if(!$success) $this->_validation_error = 4; break; + case self::type_document: + foreach($values as $value) { + $success = true; + if(!$this->_dms->getDocument((int) $value)) + $success = false; + } + if(!$success) + $this->_validation_error = 10; + break; + case self::type_folder: + foreach($values as $value) { + $success = true; + if(!$this->_dms->getFolder((int) $value)) + $success = false; + } + if(!$success) + $this->_validation_error = 11; + break; + case self::type_user: + foreach($values as $value) { + $success = true; + if(!$this->_dms->getUser((int) $value)) + $success = false; + } + if(!$success) + $this->_validation_error = 12; + break; + case self::type_group: + foreach($values as $value) { + $success = true; + if(!$this->_dms->getGroup((int) $value)) + $success = false; + } + if(!$success) + $this->_validation_error = 13; + break; } if(!$success)