add validation and parsing of new types (user, group, etc.)

This commit is contained in:
Uwe Steinmann 2020-09-01 09:22:48 +02:00
parent a328984b3d
commit 051fac8281

View File

@ -800,12 +800,52 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
$sep = substr($value, 0, 1); $sep = substr($value, 0, 1);
$vsep = $this->getValueSetSeparator(); $vsep = $this->getValueSetSeparator();
if($sep == $vsep) if($sep == $vsep)
return(explode($sep, substr($value, 1))); $values = explode($sep, substr($value, 1));
else else
return(array($value)); $values = array($value);
} else { } 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($this->getMultipleValues()) {
if(is_string($attrvalue)) { if(is_string($attrvalue)) {
$sep = $attrvalue[0]; $sep = $attrvalue[0];
@ -1100,11 +1146,13 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
$values = array(); $values = array();
} }
/* Check if attribute value has at least the minimum number of values */
$this->_validation_error = 0; $this->_validation_error = 0;
if($this->getMinValues() > count($values)) { if($this->getMinValues() > count($values)) {
$this->_validation_error = 1; $this->_validation_error = 1;
return false; return false;
} }
/* Check if attribute value has not more than maximum number of values */
if($this->getMaxValues() && $this->getMaxValues() < count($values)) { if($this->getMaxValues() && $this->getMaxValues() < count($values)) {
$this->_validation_error = 2; $this->_validation_error = 2;
return false; return false;
@ -1163,6 +1211,42 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
if(!$success) if(!$success)
$this->_validation_error = 4; $this->_validation_error = 4;
break; 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) if(!$success)