N°9525 - TagSet Errors

This commit is contained in:
Eric Espie
2026-04-20 17:42:35 +02:00
parent 848d869954
commit 900bd6956a
4 changed files with 17 additions and 14 deletions

View File

@@ -43,24 +43,24 @@ final class ormTagSet extends ormSet
/**
*
* @param array $aTagCodes
* @param array|null $aItems
*
* @throws \CoreException
* @throws \CoreUnexpectedValue when a code is invalid
*/
public function SetValues($aTagCodes)
public function SetValues($aItems)
{
if (is_null($aTagCodes)) {
$aTagCodes = [];
if (is_null($aItems)) {
$aItems = [];
}
if (!is_array($aTagCodes)) {
throw new CoreUnexpectedValue("Wrong value {$aTagCodes} for {$this->sClass}:{$this->sAttCode}");
if (!is_array($aItems)) {
throw new CoreUnexpectedValue("Wrong value {$aItems} for {$this->sClass}:{$this->sAttCode}");
}
$oTags = [];
$iCount = 0;
$bError = false;
foreach ($aTagCodes as $sTagCode) {
foreach ($aItems as $sTagCode) {
$iCount++;
if (($this->iLimit != 0) && ($iCount > $this->iLimit)) {
$bError = true;

View File

@@ -21,6 +21,7 @@ SetupWebPage::AddModule(
// Components
//
'datamodel' => [
'model.itop-faq-light.php',
],
'data.struct' => [
//'data.struct.itop-knownerror-mgmt.xml',

View File

@@ -213,7 +213,7 @@ abstract class AttributeSet extends AttributeDBFieldVoid
* force an allowed value (type conversion and possibly forces a value as mySQL would do upon writing!
*
* @param $proposedValue
* @param DBObject $oHostObj
* @param DBObject|null $oHostObj
*
* @param bool $bIgnoreErrors
*

View File

@@ -7,6 +7,8 @@
namespace Combodo\iTop\Core\AttributeDefinition;
use ApplicationContext;
use cmdbAbstractObject;
use CoreException;
use CoreUnexpectedValue;
use CoreWarning;
@@ -534,21 +536,21 @@ HTML;
}
/**
* @param $value
* @param $sValue
* @param DBObject $oHostObject
* @param bool $bLocalize
*
* @return string
*
*/
public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
public function GetAsXML($sValue, $oHostObject = null, $bLocalize = true)
{
if (is_object($value) && ($value instanceof ormTagSet)) {
if (is_object($sValue) && ($sValue instanceof ormTagSet)) {
$sRes = "<Set>\n";
if ($bLocalize) {
$aValues = $value->GetLabels();
$aValues = $sValue->GetLabels();
} else {
$aValues = $value->GetValues();
$aValues = $sValue->GetValues();
}
if (!empty($aValues)) {
$sRes .= '<Tag>'.implode('</Tag><Tag>', $aValues).'</Tag>';
@@ -636,7 +638,7 @@ HTML;
public function FromJSONToValue($json)
{
$oSet = new ormTagSet($this->GetHostClass(), $this->GetCode(), $this->GetMaxItems());
$oSet->SetValues($json);
$oSet->SetValues(json_decode($json, true));
return $oSet;
}