From 86362c5284d921558e9136bf80da1de34739a5ab Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 28 Feb 2025 08:40:06 +0100 Subject: [PATCH 1/3] fix output of attributes --- views/bootstrap/class.DocumentVersionDetail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/bootstrap/class.DocumentVersionDetail.php b/views/bootstrap/class.DocumentVersionDetail.php index 91c2404c0..f77bd267b 100644 --- a/views/bootstrap/class.DocumentVersionDetail.php +++ b/views/bootstrap/class.DocumentVersionDetail.php @@ -352,7 +352,7 @@ class SeedDMS_View_DocumentVersionDetail extends SeedDMS_Theme_Style { print "
  • ".$arr[0].": ".$arr[1]."
  • \n"; } else { $attrdef = $attribute->getAttributeDefinition(); - print "
  • ".htmlspecialchars($attrdef->getName()).": ".htmlspecialchars(implode(', ', $attribute->getValueAsArray()))."
  • \n"; + print "
  • ".htmlspecialchars($attrdef->getName()).": ".htmlspecialchars($attribute->getValueAsString())."
  • \n"; } } } From 4ba50995699f5f5611a532b372771b456591d3c5 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 28 Feb 2025 17:53:54 +0100 Subject: [PATCH 2/3] getAttributeEditField() handels arrays of attr values propperly --- views/bootstrap/class.Bootstrap.php | 39 ++++++++++++++++++++---- views/bootstrap4/class.Bootstrap4.php | 43 ++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/views/bootstrap/class.Bootstrap.php b/views/bootstrap/class.Bootstrap.php index 7d7f4408d..017e213a1 100644 --- a/views/bootstrap/class.Bootstrap.php +++ b/views/bootstrap/class.Bootstrap.php @@ -1966,6 +1966,15 @@ $(document).ready(function() { echo self::getAttributeEditField($attrdef, $attribute, $fieldname, $norequire, $namepostfix, $alwaysmultiple); } /* }}} */ + /** + * Return html code for an input/select field of an attribute + * + * The passed attribute ($attribute) can either be an object of type + * SeedDMS_Core_Attribute, scalar or an array. A scalar or array is + * passed when the method is called to create the search form. In that + * case $attribute has the value from the post data after submitting the + * search form. + */ function getAttributeEditField($attrdef, $attribute, $fieldname='attributes', $norequire=false, $namepostfix='', $alwaysmultiple=false) { /* {{{ */ $dms = $this->params['dms']; $attr_id = $fieldname.'_'.$attrdef->getId().($namepostfix ? '_'.$namepostfix : ''); @@ -2002,10 +2011,19 @@ $(document).ready(function() { $content .= $this->getDocumentChooserHtml("attr".$attrdef->getId(), $target, $attr_name); break; case SeedDMS_Core_AttributeDefinition::type_user: - $target = $attribute ? $attribute->getValueAsArray() : []; $objvalue = []; - foreach($target as $t) - $objvalue[] = $t->getId(); + if($attribute) { + if(is_object($attribute)) { + $target = $attribute->getValueAsArray(); + foreach($target as $t) + $objvalue[] = $t->getId(); + } elseif(is_array($attribute)) { + foreach($attribute as $t) + $objvalue[] = $t; + } else { + $objvalue[] = $attribute; + } + } $users = $dms->getAllUsers(); if($users) { $allowempty = $attrdef->getMinValues() == 0; @@ -2025,10 +2043,19 @@ $(document).ready(function() { } break; case SeedDMS_Core_AttributeDefinition::type_group: - $target = $attribute ? $attribute->getValueAsArray() : []; $objvalue = []; - foreach($target as $t) - $objvalue[] = $t->getId(); + if($attribute) { + if(is_object($attribute)) { + $target = $attribute->getValueAsArray(); + foreach($target as $t) + $objvalue[] = $t->getId(); + } elseif(is_array($attribute)) { + foreach($attribute as $t) + $objvalue[] = $t; + } else { + $objvalue[] = $attribute; + } + } $groups = $dms->getAllGroups(); if($groups) { $allowempty = $attrdef->getMinValues() == 0; diff --git a/views/bootstrap4/class.Bootstrap4.php b/views/bootstrap4/class.Bootstrap4.php index 93ffc29f2..9e7c2fa64 100644 --- a/views/bootstrap4/class.Bootstrap4.php +++ b/views/bootstrap4/class.Bootstrap4.php @@ -1985,6 +1985,15 @@ $(document).ready(function() { echo self::getAttributeEditField($attrdef, $attribute, $fieldname, $norequire, $namepostfix, $alwaysmultiple); } /* }}} */ + /** + * Return html code for an input/select field of an attribute + * + * The passed attribute ($attribute) can either be an object of type + * SeedDMS_Core_Attribute, scalar or an array. A scalar or array is + * passed when the method is called to create the search form. In that + * case $attribute has the value from the post data after submitting the + * search form. + */ function getAttributeEditField($attrdef, $attribute, $fieldname='attributes', $norequire=false, $namepostfix='', $alwaysmultiple=false) { /* {{{ */ $dms = $this->params['dms']; $attr_id = $fieldname.'_'.$attrdef->getId().($namepostfix ? '_'.$namepostfix : ''); @@ -2018,18 +2027,27 @@ $(document).ready(function() { $content .= "getMinValues() > 0) ? ' required="required"' : '')." data-rule-number=\"true\"/>"; break; */ case SeedDMS_Core_AttributeDefinition::type_folder: - $target = $attribute ? $attribute->getValue() : null; + $target = $attribute ? (is_object($attribute) ? $attribute->getValue() : $attribute) : null; $content .= $this->getFolderChooserHtml("attr".$attrdef->getId(), M_READWRITE, -1, $target, $attr_name, false); break; case SeedDMS_Core_AttributeDefinition::type_document: - $target = $attribute ? $attribute->getValue() : null; + $target = $attribute ? (is_object($attribute) ? $attribute->getValue() : $attribute) : null; $content .= $this->getDocumentChooserHtml("attr".$attrdef->getId(), $target, $attr_name); break; case SeedDMS_Core_AttributeDefinition::type_user: - $target = $attribute ? $attribute->getValueAsArray() : []; $objvalue = []; - foreach($target as $t) - $objvalue[] = $t->getId(); + if($attribute) { + if(is_object($attribute)) { + $target = $attribute->getValueAsArray(); + foreach($target as $t) + $objvalue[] = $t->getId(); + } elseif(is_array($attribute)) { + foreach($attribute as $t) + $objvalue[] = $t; + } else { + $objvalue[] = $attribute; + } + } $users = $dms->getAllUsers(); if($users) { $allowempty = $attrdef->getMinValues() == 0; @@ -2049,10 +2067,19 @@ $(document).ready(function() { } break; case SeedDMS_Core_AttributeDefinition::type_group: - $target = $attribute ? $attribute->getValueAsArray() : []; $objvalue = []; - foreach($target as $t) - $objvalue[] = $t->getId(); + if($attribute) { + if(is_object($attribute)) { + $target = $attribute->getValueAsArray(); + foreach($target as $t) + $objvalue[] = $t->getId(); + } elseif(is_array($attribute)) { + foreach($attribute as $t) + $objvalue[] = $t; + } else { + $objvalue[] = $attribute; + } + } $groups = $dms->getAllGroups(); if($groups) { $allowempty = $attrdef->getMinValues() == 0; From d66f12ae213c8d21a909926228d131857db05bc9 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 28 Feb 2025 17:54:52 +0100 Subject: [PATCH 3/3] do not tread each field of search form as multivalued --- views/bootstrap/class.Search.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/views/bootstrap/class.Search.php b/views/bootstrap/class.Search.php index bb7e754b3..7df547f82 100644 --- a/views/bootstrap/class.Search.php +++ b/views/bootstrap/class.Search.php @@ -794,9 +794,9 @@ $(document).ready(function() { } elseif(in_array($attrdef->getType(), [SeedDMS_Core_AttributeDefinition::type_int, SeedDMS_Core_AttributeDefinition::type_float]) && !$attrdef->getValueSet()) { $this->formField(htmlspecialchars($attrdef->getName().' ('.getMLText('from').')'), $this->getAttributeEditField($attrdef, !empty($attributes[$attrdef->getID()]['from']) ? $attributes[$attrdef->getID()]['from'] : '', 'attributes', true, 'from')); $this->formField(htmlspecialchars($attrdef->getName().' ('.getMLText('to').')'), $this->getAttributeEditField($attrdef, !empty($attributes[$attrdef->getID()]['to']) ? $attributes[$attrdef->getID()]['to'] : '', 'attributes', true, 'to')); - - } else - $this->formField(htmlspecialchars($attrdef->getName()), $this->getAttributeEditField($attrdef, isset($attributes[$attrdef->getID()]) ? $attributes[$attrdef->getID()] : '', 'attributes', true, '', true)); + } else { + $this->formField(htmlspecialchars($attrdef->getName()), $this->getAttributeEditField($attrdef, isset($attributes[$attrdef->getID()]) ? $attributes[$attrdef->getID()] : '', 'attributes', true, '', false)); + } } } }