mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°917: Fix Bulk modify for AttCodeSet
This commit is contained in:
@@ -2057,11 +2057,11 @@ EOF
|
|||||||
|
|
||||||
$oPage->add_dict_entry('Core:AttributeTagSet:placeholder');
|
$oPage->add_dict_entry('Core:AttributeTagSet:placeholder');
|
||||||
|
|
||||||
/** @var \ormSet $value */
|
|
||||||
if (isset($aArgs['this']))
|
if (isset($aArgs['this']))
|
||||||
{
|
{
|
||||||
$oAttDef->SetTargetClass($aArgs['this']);
|
$oAttDef->SetTargetClass($aArgs['this']);
|
||||||
}
|
}
|
||||||
|
/** @var \ormSet $value */
|
||||||
$sJson = $oAttDef->GetJsonForWidget($value);
|
$sJson = $oAttDef->GetJsonForWidget($value);
|
||||||
$sInputId = "attr_{$sFormPrefix}{$sAttCode}";
|
$sInputId = "attr_{$sFormPrefix}{$sAttCode}";
|
||||||
$sHTMLValue = "<div class=\"field_input_zone field_input_tagset\"><input id='$sInputId' name='$sInputId' type='hidden' value='$sJson'></div>{$sValidationSpan}{$sReloadSpan}";
|
$sHTMLValue = "<div class=\"field_input_zone field_input_tagset\"><input id='$sInputId' name='$sInputId' type='hidden' value='$sJson'></div>{$sValidationSpan}{$sReloadSpan}";
|
||||||
@@ -3975,9 +3975,9 @@ EOF
|
|||||||
{
|
{
|
||||||
$currValue = ' '; // Don't put an empty string, in case the field would be considered as mandatory...
|
$currValue = ' '; // Don't put an empty string, in case the field would be considered as mandatory...
|
||||||
}
|
}
|
||||||
elseif ($currValue instanceof ormTagSet)
|
elseif ($currValue instanceof ormSet)
|
||||||
{
|
{
|
||||||
$currValue = implode(' ', $currValue->GetValue());
|
$currValue = $oAttDef->GetEditValue($currValue, $oObj);
|
||||||
}
|
}
|
||||||
if (is_object($currValue))
|
if (is_object($currValue))
|
||||||
{
|
{
|
||||||
@@ -4107,12 +4107,8 @@ EOF
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$aTagCodes = array();
|
$aTagCodes = $oAttDef->FromStringToArray($sValues);
|
||||||
if (!empty($sValues))
|
$oTagSet->GenerateDiffFromArray($aTagCodes);
|
||||||
{
|
|
||||||
$aTagCodes = explode(' ', $sValues);
|
|
||||||
}
|
|
||||||
$oTagSet->GenerateDiffFromTags($aTagCodes);
|
|
||||||
}
|
}
|
||||||
$oDummyObj->Set($sAttCode, $oTagSet);
|
$oDummyObj->Set($sAttCode, $oTagSet);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6744,8 +6744,8 @@ class AttributeTagSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aJson['partial_values'] = $oValue->GetModifiedTags();
|
$aJson['partial_values'] = $oValue->GetModified();
|
||||||
$aJson['orig_value'] = array_merge($oValue->GetValue(), $oValue->GetModifiedTags());
|
$aJson['orig_value'] = array_merge($oValue->GetValues(), $oValue->GetModified());
|
||||||
}
|
}
|
||||||
$aJson['added'] = array();
|
$aJson['added'] = array();
|
||||||
$aJson['removed'] = array();
|
$aJson['removed'] = array();
|
||||||
@@ -6756,6 +6756,20 @@ class AttributeTagSet extends AttributeSet
|
|||||||
return json_encode($aJson);
|
return json_encode($aJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function FromStringToArray($proposedValue)
|
||||||
|
{
|
||||||
|
$aValues = array();
|
||||||
|
if (!empty($proposedValue))
|
||||||
|
{
|
||||||
|
foreach(explode(' ', $proposedValue) as $sCode)
|
||||||
|
{
|
||||||
|
$sValue = trim($sCode);
|
||||||
|
$aValues[] = $sValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $aValues;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract all existing tags from a string and ignore bad tags
|
* Extract all existing tags from a string and ignore bad tags
|
||||||
*
|
*
|
||||||
@@ -6768,7 +6782,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
*/
|
*/
|
||||||
public function GetExistingTagsFromString($sValue, $bNoLimit = false)
|
public function GetExistingTagsFromString($sValue, $bNoLimit = false)
|
||||||
{
|
{
|
||||||
$aTagCodes = explode(' ', "$sValue");
|
$aTagCodes = $this->FromStringToArray("$sValue");
|
||||||
$sAttCode = $this->GetCode();
|
$sAttCode = $this->GetCode();
|
||||||
$sClass = MetaModel::GetAttributeOrigin($this->GetHostClass(), $sAttCode);
|
$sClass = MetaModel::GetAttributeOrigin($this->GetHostClass(), $sAttCode);
|
||||||
if ($bNoLimit)
|
if ($bNoLimit)
|
||||||
@@ -6796,7 +6810,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$oTagSet->SetValue($aGoodTags);
|
$oTagSet->SetValues($aGoodTags);
|
||||||
|
|
||||||
return $oTagSet;
|
return $oTagSet;
|
||||||
}
|
}
|
||||||
@@ -6819,7 +6833,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
if ($value instanceof ormTagSet)
|
if ($value instanceof ormTagSet)
|
||||||
{
|
{
|
||||||
$aValues = $value->GetValue();
|
$aValues = $value->GetValues();
|
||||||
|
|
||||||
return implode(' ', $aValues);
|
return implode(' ', $aValues);
|
||||||
}
|
}
|
||||||
@@ -6887,17 +6901,20 @@ class AttributeTagSet extends AttributeSet
|
|||||||
* @param $proposedValue
|
* @param $proposedValue
|
||||||
* @param $oHostObj
|
* @param $oHostObj
|
||||||
*
|
*
|
||||||
|
* @param bool $bIgnoreErrors
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws \Exception
|
* @throws \CoreException
|
||||||
|
* @throws \CoreUnexpectedValue
|
||||||
*/
|
*/
|
||||||
public function MakeRealValue($proposedValue, $oHostObj)
|
public function MakeRealValue($proposedValue, $oHostObj, $bIgnoreErrors = false)
|
||||||
{
|
{
|
||||||
$oTagSet = new ormTagSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
$oTagSet = new ormTagSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||||
if (is_string($proposedValue) && !empty($proposedValue))
|
if (is_string($proposedValue) && !empty($proposedValue))
|
||||||
{
|
{
|
||||||
$proposedValue = trim("$proposedValue");
|
$proposedValue = trim("$proposedValue");
|
||||||
$aTagCodes = explode(' ', $proposedValue);
|
$aTagCodes = $this->FromStringToArray($proposedValue);
|
||||||
$oTagSet->SetValue($aTagCodes);
|
$oTagSet->SetValues($aTagCodes);
|
||||||
}
|
}
|
||||||
elseif ($proposedValue instanceof ormTagSet)
|
elseif ($proposedValue instanceof ormTagSet)
|
||||||
{
|
{
|
||||||
@@ -6958,7 +6975,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @var \ormTagSet $proposedValue */
|
/** @var \ormTagSet $proposedValue */
|
||||||
return count($proposedValue->GetValue()) == 0;
|
return count($proposedValue->GetValues()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -7008,7 +7025,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
if ($value instanceof ormTagSet)
|
if ($value instanceof ormTagSet)
|
||||||
{
|
{
|
||||||
$aValues = $value->GetValue();
|
$aValues = $value->GetValues();
|
||||||
|
|
||||||
return implode(' ', $aValues);
|
return implode(' ', $aValues);
|
||||||
}
|
}
|
||||||
@@ -7040,7 +7057,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aValues = $value->GetValue();
|
$aValues = $value->GetValues();
|
||||||
}
|
}
|
||||||
if (empty($aValues))
|
if (empty($aValues))
|
||||||
{
|
{
|
||||||
@@ -7060,7 +7077,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
{
|
{
|
||||||
// unknown tags are present display the code instead
|
// unknown tags are present display the code instead
|
||||||
}
|
}
|
||||||
$aTagCodes = explode(' ', $value);
|
$aTagCodes = $this->FromStringToArray($value);
|
||||||
$aValues = array();
|
$aValues = array();
|
||||||
$oTagSet = new ormTagSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()),
|
$oTagSet = new ormTagSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()),
|
||||||
$this->GetCode(), $this->GetMaxItems());
|
$this->GetCode(), $this->GetMaxItems());
|
||||||
@@ -7068,7 +7085,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$oTagSet->AddTag($sTagCode);
|
$oTagSet->Add($sTagCode);
|
||||||
} catch (Exception $e)
|
} catch (Exception $e)
|
||||||
{
|
{
|
||||||
$aValues[] = $sTagCode;
|
$aValues[] = $sTagCode;
|
||||||
@@ -7096,8 +7113,8 @@ class AttributeTagSet extends AttributeSet
|
|||||||
{
|
{
|
||||||
$sResult = Dict::Format('Change:AttName_Changed', $this->GetLabel()).", ";
|
$sResult = Dict::Format('Change:AttName_Changed', $this->GetLabel()).", ";
|
||||||
|
|
||||||
$aNewValues = explode(' ', $sNewValue);
|
$aNewValues = $this->FromStringToArray($sNewValue);
|
||||||
$aOldValues = explode(' ', $sOldValue);
|
$aOldValues = $this->FromStringToArray($sOldValue);
|
||||||
|
|
||||||
$aDelta['removed'] = array_diff($aOldValues, $aNewValues);
|
$aDelta['removed'] = array_diff($aOldValues, $aNewValues);
|
||||||
$aDelta['added'] = array_diff($aNewValues, $aOldValues);
|
$aDelta['added'] = array_diff($aNewValues, $aOldValues);
|
||||||
@@ -7194,7 +7211,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sHtml .= '<span class="attribute-tag-undefined">'.$oTag.'</span>';
|
$sHtml .= '<span class="attribute-tag">'.$oTag.'</span>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sHtml .= '</span>';
|
$sHtml .= '</span>';
|
||||||
@@ -7221,7 +7238,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aValues = $value->GetValue();
|
$aValues = $value->GetValues();
|
||||||
}
|
}
|
||||||
if (!empty($aValuess))
|
if (!empty($aValuess))
|
||||||
{
|
{
|
||||||
@@ -7261,7 +7278,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aValues = $value->GetValue();
|
$aValues = $value->GetValues();
|
||||||
}
|
}
|
||||||
$sRes = implode($sSepItem, $aValues);
|
$sRes = implode($sSepItem, $aValues);
|
||||||
}
|
}
|
||||||
@@ -7306,7 +7323,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aValues = $value->GetValue();
|
$aValues = $value->GetValues();
|
||||||
$sSep = ' ';
|
$sSep = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7338,7 +7355,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
$aRet = array();
|
$aRet = array();
|
||||||
if (is_object($value) && ($value instanceof ormTagSet))
|
if (is_object($value) && ($value instanceof ormTagSet))
|
||||||
{
|
{
|
||||||
$aRet = $value->GetValue();
|
$aRet = $value->GetValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $aRet;
|
return $aRet;
|
||||||
@@ -7358,7 +7375,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
public function FromJSONToValue($json)
|
public function FromJSONToValue($json)
|
||||||
{
|
{
|
||||||
$oSet = new ormTagSet($this->GetHostClass(), $this->GetCode(), $this->GetMaxItems());
|
$oSet = new ormTagSet($this->GetHostClass(), $this->GetCode(), $this->GetMaxItems());
|
||||||
$oSet->SetValue($json);
|
$oSet->SetValues($json);
|
||||||
|
|
||||||
return $oSet;
|
return $oSet;
|
||||||
}
|
}
|
||||||
@@ -7415,7 +7432,7 @@ class AttributeTagSet extends AttributeSet
|
|||||||
{
|
{
|
||||||
if ($value instanceof ormTagSet)
|
if ($value instanceof ormTagSet)
|
||||||
{
|
{
|
||||||
$aValues = $value->GetValue();
|
$aValues = $value->GetValues();
|
||||||
|
|
||||||
return implode(' ', $aValues);
|
return implode(' ', $aValues);
|
||||||
}
|
}
|
||||||
@@ -8750,7 +8767,7 @@ class AttributeSubItem extends AttributeDefinition
|
|||||||
static public function LoadInObject()
|
static public function LoadInObject()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
} // if this verb returns false, then GetValue must be implemented
|
} // if this verb returns false, then GetValues must be implemented
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by DBOBject::Get()
|
* Used by DBOBject::Get()
|
||||||
@@ -9367,9 +9384,9 @@ class AttributeSet extends AttributeDBFieldVoid
|
|||||||
$aJson = array();
|
$aJson = array();
|
||||||
|
|
||||||
// possible_values
|
// possible_values
|
||||||
$aSetObjectData = $this->GetAllowedValues();
|
$aAllowedValues = $this->GetAllowedValues();
|
||||||
$aSetKeyValData = array();
|
$aSetKeyValData = array();
|
||||||
foreach($aSetObjectData as $sCode => $sLabel)
|
foreach($aAllowedValues as $sCode => $sLabel)
|
||||||
{
|
{
|
||||||
$aSetKeyValData[] = [
|
$aSetKeyValData[] = [
|
||||||
'code' => $sCode,
|
'code' => $sCode,
|
||||||
@@ -9385,8 +9402,24 @@ class AttributeSet extends AttributeDBFieldVoid
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aJson['partial_values'] = $oValue->GetModified();
|
$aPartialValues = $oValue->GetModified();
|
||||||
$aJson['orig_value'] = array_merge($oValue->GetValues(), $oValue->GetModified());
|
foreach ($aPartialValues as $key => $value)
|
||||||
|
{
|
||||||
|
if (!isset($aAllowedValues[$value]))
|
||||||
|
{
|
||||||
|
unset($aPartialValues[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$aJson['partial_values'] = array_values($aPartialValues);
|
||||||
|
$aOrigValues = array_merge($oValue->GetValues(), $oValue->GetModified());
|
||||||
|
foreach ($aOrigValues as $key => $value)
|
||||||
|
{
|
||||||
|
if (!isset($aAllowedValues[$value]))
|
||||||
|
{
|
||||||
|
unset($aOrigValues[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$aJson['orig_value'] = array_values($aOrigValues);
|
||||||
}
|
}
|
||||||
$aJson['added'] = array();
|
$aJson['added'] = array();
|
||||||
$aJson['removed'] = array();
|
$aJson['removed'] = array();
|
||||||
@@ -9409,7 +9442,7 @@ class AttributeSet extends AttributeDBFieldVoid
|
|||||||
|
|
||||||
public function GetEditClass()
|
public function GetEditClass()
|
||||||
{
|
{
|
||||||
return "List";
|
return "Set";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetEditValue($value, $oHostObj = null)
|
public function GetEditValue($value, $oHostObj = null)
|
||||||
@@ -9442,6 +9475,20 @@ class AttributeSet extends AttributeDBFieldVoid
|
|||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function FromStringToArray($proposedValue)
|
||||||
|
{
|
||||||
|
$aValues = array();
|
||||||
|
if (!empty($proposedValue))
|
||||||
|
{
|
||||||
|
foreach(explode(',', $proposedValue) as $sCode)
|
||||||
|
{
|
||||||
|
$sValue = trim($sCode);
|
||||||
|
$aValues[] = $sValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $aValues;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $aCols
|
* @param array $aCols
|
||||||
* @param string $sPrefix
|
* @param string $sPrefix
|
||||||
@@ -9453,7 +9500,7 @@ class AttributeSet extends AttributeDBFieldVoid
|
|||||||
{
|
{
|
||||||
$sValue = $aCols["$sPrefix"];
|
$sValue = $aCols["$sPrefix"];
|
||||||
|
|
||||||
return $this->MakeRealValue($sValue, null);
|
return $this->MakeRealValue($sValue, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9476,21 +9523,19 @@ class AttributeSet extends AttributeDBFieldVoid
|
|||||||
* @param $proposedValue
|
* @param $proposedValue
|
||||||
* @param \DBObject $oHostObj
|
* @param \DBObject $oHostObj
|
||||||
*
|
*
|
||||||
|
* @param bool $bIgnoreErrors
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws \Exception
|
* @throws \CoreException
|
||||||
|
* @throws \CoreUnexpectedValue
|
||||||
*/
|
*/
|
||||||
public function MakeRealValue($proposedValue, $oHostObj)
|
public function MakeRealValue($proposedValue, $oHostObj, $bIgnoreErrors = false)
|
||||||
{
|
{
|
||||||
$oSet = new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
$oSet = new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||||
if (is_string($proposedValue) && !empty($proposedValue))
|
if (is_string($proposedValue) && !empty($proposedValue))
|
||||||
{
|
{
|
||||||
$proposedValue = trim("$proposedValue");
|
$proposedValue = trim("$proposedValue");
|
||||||
$aValues = array();
|
$aValues = $this->FromStringToArray($proposedValue);
|
||||||
foreach (explode(',', $proposedValue) as $sCode)
|
|
||||||
{
|
|
||||||
$sValue = trim($sCode);
|
|
||||||
$aValues[] = $sValue;
|
|
||||||
}
|
|
||||||
$oSet->SetValues($aValues);
|
$oSet->SetValues($aValues);
|
||||||
}
|
}
|
||||||
elseif ($proposedValue instanceof ormSet)
|
elseif ($proposedValue instanceof ormSet)
|
||||||
@@ -9700,17 +9745,23 @@ class AttributeClassAttCodeSet extends AttributeSet
|
|||||||
* @param $proposedValue
|
* @param $proposedValue
|
||||||
* @param \DBObject $oHostObj
|
* @param \DBObject $oHostObj
|
||||||
*
|
*
|
||||||
|
* @param bool $bIgnoreErrors
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @throws \CoreException
|
||||||
|
* @throws \CoreUnexpectedValue
|
||||||
|
* @throws \OQLException
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function MakeRealValue($proposedValue, $oHostObj)
|
public function MakeRealValue($proposedValue, $oHostObj, $bIgnoreErrors = false)
|
||||||
{
|
{
|
||||||
$oSet = new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
$oSet = new ormSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode(), $this->GetMaxItems());
|
||||||
$this->SetTargetClass($oHostObj);
|
$this->SetTargetClass($oHostObj);
|
||||||
$aAllowedAttributes = $this->GetAllowedValues();
|
$aAllowedAttributes = $this->GetAllowedValues();
|
||||||
|
$aInvalidAttCodes = array();
|
||||||
if (is_string($proposedValue) && !empty($proposedValue))
|
if (is_string($proposedValue) && !empty($proposedValue))
|
||||||
{
|
{
|
||||||
$proposedValue = trim("$proposedValue");
|
$proposedValue = trim($proposedValue);
|
||||||
$aValues = array();
|
$aValues = array();
|
||||||
foreach(explode(',', $proposedValue) as $sValue)
|
foreach(explode(',', $proposedValue) as $sValue)
|
||||||
{
|
{
|
||||||
@@ -9721,7 +9772,7 @@ class AttributeClassAttCodeSet extends AttributeSet
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new CoreUnexpectedValue("The attribute {$sAttCode} does not exist in class {$this->sTargetClass}");
|
$aInvalidAttCodes[] = $sAttCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$oSet->SetValues($aValues);
|
$oSet->SetValues($aValues);
|
||||||
@@ -9730,6 +9781,10 @@ class AttributeClassAttCodeSet extends AttributeSet
|
|||||||
{
|
{
|
||||||
$oSet = $proposedValue;
|
$oSet = $proposedValue;
|
||||||
}
|
}
|
||||||
|
if (!empty($aInvalidAttCodes) && !$bIgnoreErrors)
|
||||||
|
{
|
||||||
|
throw new CoreUnexpectedValue("The attribute(s) ".implode(', ', $aInvalidAttCodes)." are invalid for class {$this->sTargetClass}");
|
||||||
|
}
|
||||||
|
|
||||||
return $oSet;
|
return $oSet;
|
||||||
}
|
}
|
||||||
@@ -9757,7 +9812,13 @@ class AttributeClassAttCodeSet extends AttributeSet
|
|||||||
$aLocalizedValues = array();
|
$aLocalizedValues = array();
|
||||||
foreach($value as $sAttCode)
|
foreach($value as $sAttCode)
|
||||||
{
|
{
|
||||||
$aLocalizedValues[] = MetaModel::GetLabel($this->sTargetClass, $sAttCode);
|
try
|
||||||
|
{
|
||||||
|
$aLocalizedValues[] = MetaModel::GetLabel($this->sTargetClass, $sAttCode);
|
||||||
|
} catch (Exception $e)
|
||||||
|
{
|
||||||
|
// Ignore bad values
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$value = $aLocalizedValues;
|
$value = $aLocalizedValues;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -417,8 +417,8 @@ abstract class CMDBObject extends DBObject
|
|||||||
$oMyChangeOp->Set("objclass", get_class($this));
|
$oMyChangeOp->Set("objclass", get_class($this));
|
||||||
$oMyChangeOp->Set("objkey", $this->GetKey());
|
$oMyChangeOp->Set("objkey", $this->GetKey());
|
||||||
$oMyChangeOp->Set("attcode", $sAttCode);
|
$oMyChangeOp->Set("attcode", $sAttCode);
|
||||||
$oMyChangeOp->Set("oldvalue", implode(' ', $original->GetValue()));
|
$oMyChangeOp->Set("oldvalue", implode(' ', $original->GetValues()));
|
||||||
$oMyChangeOp->Set("newvalue", implode(' ', $value->GetValue()));
|
$oMyChangeOp->Set("newvalue", implode(' ', $value->GetValues()));
|
||||||
$iId = $oMyChangeOp->DBInsertNoReload();
|
$iId = $oMyChangeOp->DBInsertNoReload();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1285,7 +1285,7 @@ abstract class DBObject implements iDisplay
|
|||||||
$oTag = new ormTagSet(get_class($this), $sAttCode);
|
$oTag = new ormTagSet(get_class($this), $sAttCode);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$oTag->SetValue(explode(' ', $toCheck));
|
$oTag->SetValues(explode(' ', $toCheck));
|
||||||
} catch (Exception $e)
|
} catch (Exception $e)
|
||||||
{
|
{
|
||||||
return "Tag value '$toCheck' is not a valid tag list";
|
return "Tag value '$toCheck' is not a valid tag list";
|
||||||
|
|||||||
@@ -24,36 +24,36 @@
|
|||||||
* Date: 24/08/2018
|
* Date: 24/08/2018
|
||||||
* Time: 14:35
|
* Time: 14:35
|
||||||
*/
|
*/
|
||||||
final class ormSet
|
class ormSet
|
||||||
{
|
{
|
||||||
private $sClass; // class of the field
|
protected $sClass; // class of the field
|
||||||
private $sAttCode; // attcode of the field
|
protected $sAttCode; // attcode of the field
|
||||||
private $aOriginalObjects = null;
|
protected $aOriginalObjects = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object from the original set, minus the removed objects
|
* Object from the original set, minus the removed objects
|
||||||
*/
|
*/
|
||||||
private $aPreserved = array();
|
protected $aPreserved = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New items
|
* New items
|
||||||
*/
|
*/
|
||||||
private $aAdded = array();
|
protected $aAdded = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removed items
|
* Removed items
|
||||||
*/
|
*/
|
||||||
private $aRemoved = array();
|
protected $aRemoved = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modified items (mass edit)
|
* Modified items (mass edit)
|
||||||
*/
|
*/
|
||||||
private $aModified = array();
|
protected $aModified = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int Max number of tags in collection
|
* @var int Max number of tags in collection
|
||||||
*/
|
*/
|
||||||
private $iLimit;
|
protected $iLimit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __toString magical function overload.
|
* __toString magical function overload.
|
||||||
@@ -231,8 +231,8 @@ final class ormSet
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a delta to the current ItemSet
|
* Apply a delta to the current ItemSet
|
||||||
* $aDelta['added] = array of tag code for only the added tags
|
* $aDelta['added] = array of added items
|
||||||
* $aDelta['removed'] = array of tag code for only the removed tags
|
* $aDelta['removed'] = array of removed items
|
||||||
*
|
*
|
||||||
* @param $aDelta
|
* @param $aDelta
|
||||||
*
|
*
|
||||||
@@ -254,6 +254,9 @@ final class ormSet
|
|||||||
$this->Add($oItem);
|
$this->Add($oItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the object
|
||||||
|
$this->SetValues($this->GetValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -347,7 +350,7 @@ final class ormSet
|
|||||||
*
|
*
|
||||||
* @throws \CoreException
|
* @throws \CoreException
|
||||||
*/
|
*/
|
||||||
public function GenerateDiffFromItems($aItems)
|
public function GenerateDiffFromArray($aItems)
|
||||||
{
|
{
|
||||||
foreach($this->GetValues() as $oCurrentItem)
|
foreach($this->GetValues() as $oCurrentItem)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,55 +24,8 @@
|
|||||||
* Date: 24/08/2018
|
* Date: 24/08/2018
|
||||||
* Time: 14:35
|
* Time: 14:35
|
||||||
*/
|
*/
|
||||||
final class ormTagSet
|
final class ormTagSet extends ormSet
|
||||||
{
|
{
|
||||||
private $sClass; // class of the tag field
|
|
||||||
private $sAttCode; // attcode of the tag field
|
|
||||||
private $aOriginalObjects = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Object from the original set, minus the removed objects
|
|
||||||
*
|
|
||||||
* @var DBObject[] array of iObjectId => DBObject
|
|
||||||
*/
|
|
||||||
private $aPreserved = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var DBObject[] New items
|
|
||||||
*/
|
|
||||||
private $aAdded = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var DBObject[] Removed items
|
|
||||||
*/
|
|
||||||
private $aRemoved = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var DBObject[] Modified items (mass edit)
|
|
||||||
*/
|
|
||||||
private $aModified = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int Max number of tags in collection
|
|
||||||
*/
|
|
||||||
private $iLimit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* __toString magical function overload.
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
$aValue = $this->GetValue();
|
|
||||||
if (!empty($aValue))
|
|
||||||
{
|
|
||||||
return implode(' ', $aValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ormTagSet constructor.
|
* ormTagSet constructor.
|
||||||
*
|
*
|
||||||
@@ -84,31 +37,7 @@ final class ormTagSet
|
|||||||
*/
|
*/
|
||||||
public function __construct($sClass, $sAttCode, $iLimit = 12)
|
public function __construct($sClass, $sAttCode, $iLimit = 12)
|
||||||
{
|
{
|
||||||
$this->sAttCode = $sAttCode;
|
parent::__construct($sClass, $sAttCode, $iLimit);
|
||||||
|
|
||||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
|
||||||
if (!$oAttDef instanceof AttributeTagSet)
|
|
||||||
{
|
|
||||||
throw new Exception("ormTagSet: field {$sClass}:{$sAttCode} is not a tag");
|
|
||||||
}
|
|
||||||
$this->sClass = $sClass;
|
|
||||||
$this->iLimit = $iLimit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function GetClass()
|
|
||||||
{
|
|
||||||
return $this->sClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function GetAttCode()
|
|
||||||
{
|
|
||||||
return $this->sAttCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,7 +47,7 @@ final class ormTagSet
|
|||||||
* @throws \CoreException
|
* @throws \CoreException
|
||||||
* @throws \CoreUnexpectedValue when a code is invalid
|
* @throws \CoreUnexpectedValue when a code is invalid
|
||||||
*/
|
*/
|
||||||
public function SetValue($aTagCodes)
|
public function SetValues($aTagCodes)
|
||||||
{
|
{
|
||||||
if (!is_array($aTagCodes))
|
if (!is_array($aTagCodes))
|
||||||
{
|
{
|
||||||
@@ -152,15 +81,10 @@ final class ormTagSet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetCount()
|
|
||||||
{
|
|
||||||
return count($this->aPreserved) + count($this->aAdded) - count($this->aRemoved);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array of tag codes
|
* @return array of tag codes
|
||||||
*/
|
*/
|
||||||
public function GetValue()
|
public function GetValues()
|
||||||
{
|
{
|
||||||
$aValues = array();
|
$aValues = array();
|
||||||
foreach($this->aPreserved as $sTagCode => $oTag)
|
foreach($this->aPreserved as $sTagCode => $oTag)
|
||||||
@@ -183,6 +107,7 @@ final class ormTagSet
|
|||||||
public function GetLabels()
|
public function GetLabels()
|
||||||
{
|
{
|
||||||
$aTags = array();
|
$aTags = array();
|
||||||
|
/** @var \TagSetFieldData $oTag */
|
||||||
foreach($this->aPreserved as $sTagCode => $oTag)
|
foreach($this->aPreserved as $sTagCode => $oTag)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -300,21 +225,21 @@ final class ormTagSet
|
|||||||
* @throws \CoreUnexpectedValue
|
* @throws \CoreUnexpectedValue
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function GetDelta(ormTagSet $oOtherTagSet)
|
public function GetDelta(ormSet $oOtherTagSet)
|
||||||
{
|
{
|
||||||
$oTag = new ormTagSet($this->sClass, $this->sAttCode);
|
$oTag = new ormTagSet($this->sClass, $this->sAttCode);
|
||||||
// Set the initial value
|
// Set the initial value
|
||||||
$aOrigTagCodes = $this->GetValue();
|
$aOrigTagCodes = $this->GetValues();
|
||||||
$oTag->SetValue($aOrigTagCodes);
|
$oTag->SetValues($aOrigTagCodes);
|
||||||
// now remove everything
|
// now remove everything
|
||||||
foreach($aOrigTagCodes as $sTagCode)
|
foreach($aOrigTagCodes as $sTagCode)
|
||||||
{
|
{
|
||||||
$oTag->RemoveTag($sTagCode);
|
$oTag->Remove($sTagCode);
|
||||||
}
|
}
|
||||||
// now add the tags of the other TagSet
|
// now add the tags of the other TagSet
|
||||||
foreach($oOtherTagSet->GetValue() as $sTagCode)
|
foreach($oOtherTagSet->GetValues() as $sTagCode)
|
||||||
{
|
{
|
||||||
$oTag->AddTag($sTagCode);
|
$oTag->Add($sTagCode);
|
||||||
}
|
}
|
||||||
$aDelta = array();
|
$aDelta = array();
|
||||||
$aDelta['added'] = $oTag->GetAddedCodes();
|
$aDelta['added'] = $oTag->GetAddedCodes();
|
||||||
@@ -340,17 +265,17 @@ final class ormTagSet
|
|||||||
{
|
{
|
||||||
$oTag = new ormTagSet($this->sClass, $this->sAttCode);
|
$oTag = new ormTagSet($this->sClass, $this->sAttCode);
|
||||||
// Set the initial value
|
// Set the initial value
|
||||||
$aOrigTagCodes = $this->GetValue();
|
$aOrigTagCodes = $this->GetValues();
|
||||||
$oTag->SetValue($aOrigTagCodes);
|
$oTag->SetValues($aOrigTagCodes);
|
||||||
// now remove everything
|
// now remove everything
|
||||||
foreach($aOrigTagCodes as $sTagCode)
|
foreach($aOrigTagCodes as $sTagCode)
|
||||||
{
|
{
|
||||||
$oTag->RemoveTag($sTagCode);
|
$oTag->Remove($sTagCode);
|
||||||
}
|
}
|
||||||
// now add the tags of the other TagSet
|
// now add the tags of the other TagSet
|
||||||
foreach($oOtherTagSet->GetValue() as $sTagCode)
|
foreach($oOtherTagSet->GetValues() as $sTagCode)
|
||||||
{
|
{
|
||||||
$oTag->AddTag($sTagCode);
|
$oTag->Add($sTagCode);
|
||||||
}
|
}
|
||||||
$aDelta = array();
|
$aDelta = array();
|
||||||
$aDelta['added'] = $oTag->GetAddedTags();
|
$aDelta['added'] = $oTag->GetAddedTags();
|
||||||
@@ -362,7 +287,7 @@ final class ormTagSet
|
|||||||
/**
|
/**
|
||||||
* @return string[] list of codes for partial entries
|
* @return string[] list of codes for partial entries
|
||||||
*/
|
*/
|
||||||
public function GetModifiedTags()
|
public function GetModified()
|
||||||
{
|
{
|
||||||
$aModifiedTagCodes = array_keys($this->aModified);
|
$aModifiedTagCodes = array_keys($this->aModified);
|
||||||
sort($aModifiedTagCodes);
|
sort($aModifiedTagCodes);
|
||||||
@@ -370,34 +295,6 @@ final class ormTagSet
|
|||||||
return $aModifiedTagCodes;
|
return $aModifiedTagCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply a delta to the current TagSet
|
|
||||||
* $aDelta['added] = array of tag code for only the added tags
|
|
||||||
* $aDelta['removed'] = array of tag code for only the removed tags
|
|
||||||
*
|
|
||||||
* @param $aDelta
|
|
||||||
*
|
|
||||||
* @throws \CoreException
|
|
||||||
* @throws \CoreUnexpectedValue
|
|
||||||
*/
|
|
||||||
public function ApplyDelta($aDelta)
|
|
||||||
{
|
|
||||||
if (isset($aDelta['removed']))
|
|
||||||
{
|
|
||||||
foreach($aDelta['removed'] as $sTagCode)
|
|
||||||
{
|
|
||||||
$this->RemoveTag($sTagCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($aDelta['added']))
|
|
||||||
{
|
|
||||||
foreach($aDelta['added'] as $sTagCode)
|
|
||||||
{
|
|
||||||
$this->AddTag($sTagCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a tag code is valid or not for this TagSet
|
* Check whether a tag code is valid or not for this TagSet
|
||||||
*
|
*
|
||||||
@@ -424,9 +321,9 @@ final class ormTagSet
|
|||||||
* @throws \CoreException
|
* @throws \CoreException
|
||||||
* @throws \CoreUnexpectedValue
|
* @throws \CoreUnexpectedValue
|
||||||
*/
|
*/
|
||||||
public function AddTag($sTagCode)
|
public function Add($sTagCode)
|
||||||
{
|
{
|
||||||
if ($this->GetCount() === $this->iLimit)
|
if ($this->Count() === $this->iLimit)
|
||||||
{
|
{
|
||||||
throw new CoreException("Maximum number of tags ({$this->iLimit}) reached for {$this->sClass}:{$this->sAttCode}");
|
throw new CoreException("Maximum number of tags ({$this->iLimit}) reached for {$this->sClass}:{$this->sAttCode}");
|
||||||
}
|
}
|
||||||
@@ -440,7 +337,7 @@ final class ormTagSet
|
|||||||
{
|
{
|
||||||
// put it back into preserved
|
// put it back into preserved
|
||||||
$this->aPreserved[$sTagCode] = $oTag;
|
$this->aPreserved[$sTagCode] = $oTag;
|
||||||
// no need to add it to aModified : was already done when calling RemoveTag method
|
// no need to add it to aModified : was already done when calling Remove method
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -453,7 +350,7 @@ final class ormTagSet
|
|||||||
/**
|
/**
|
||||||
* @param $sTagCode
|
* @param $sTagCode
|
||||||
*/
|
*/
|
||||||
public function RemoveTag($sTagCode)
|
public function Remove($sTagCode)
|
||||||
{
|
{
|
||||||
if ($this->IsTagInList($this->aRemoved, $sTagCode))
|
if ($this->IsTagInList($this->aRemoved, $sTagCode))
|
||||||
{
|
{
|
||||||
@@ -501,30 +398,6 @@ final class ormTagSet
|
|||||||
return $oTag;
|
return $oTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Populates the added and removed arrays for bulk edit
|
|
||||||
*
|
|
||||||
* @param string[] $aTagCodes
|
|
||||||
*
|
|
||||||
* @throws \CoreException
|
|
||||||
* @throws \CoreUnexpectedValue
|
|
||||||
*/
|
|
||||||
public function GenerateDiffFromTags($aTagCodes)
|
|
||||||
{
|
|
||||||
foreach($this->GetValue() as $sCurrentTagCode)
|
|
||||||
{
|
|
||||||
if (!in_array($sCurrentTagCode, $aTagCodes))
|
|
||||||
{
|
|
||||||
$this->RemoveTag($sCurrentTagCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($aTagCodes as $sNewTagCode)
|
|
||||||
{
|
|
||||||
$this->AddTag($sNewTagCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $sTagCode
|
* @param $sTagCode
|
||||||
*
|
*
|
||||||
@@ -583,14 +456,18 @@ final class ormTagSet
|
|||||||
*
|
*
|
||||||
* @return bool true if same tag set
|
* @return bool true if same tag set
|
||||||
*/
|
*/
|
||||||
public function Equals(ormTagSet $other)
|
public function Equals(ormSet $other)
|
||||||
{
|
{
|
||||||
|
if (!($other instanceof ormTagSet))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if ($this->GetTagDataClass() !== $other->GetTagDataClass())
|
if ($this->GetTagDataClass() !== $other->GetTagDataClass())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode(' ', $this->GetValue()) === implode(' ', $other->GetValue());
|
return implode(' ', $this->GetValues()) === implode(' ', $other->GetValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetTagDataClass()
|
public function GetTagDataClass()
|
||||||
|
|||||||
@@ -66,30 +66,30 @@ class ormTagSetTest extends ItopDataTestCase
|
|||||||
public function testGetValue()
|
public function testGetValue()
|
||||||
{
|
{
|
||||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
static::assertEquals($oTagSet->GetValue(), array());
|
static::assertEquals($oTagSet->GetValues(), array());
|
||||||
|
|
||||||
$oTagSet->AddTag('tag1');
|
$oTagSet->Add('tag1');
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag1'));
|
static::assertEquals($oTagSet->GetValues(), array('tag1'));
|
||||||
|
|
||||||
$oTagSet->AddTag('tag2');
|
$oTagSet->Add('tag2');
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag1', 'tag2'));
|
static::assertEquals($oTagSet->GetValues(), array('tag1', 'tag2'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddTag()
|
public function testAddTag()
|
||||||
{
|
{
|
||||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
|
|
||||||
$oTagSet->AddTag('tag1');
|
$oTagSet->Add('tag1');
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag1'));
|
static::assertEquals($oTagSet->GetValues(), array('tag1'));
|
||||||
|
|
||||||
$oTagSet->SetValue(array('tag1', 'tag2'));
|
$oTagSet->SetValues(array('tag1', 'tag2'));
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag1', 'tag2'));
|
static::assertEquals($oTagSet->GetValues(), array('tag1', 'tag2'));
|
||||||
|
|
||||||
$oTagSet->RemoveTag('tag1');
|
$oTagSet->Remove('tag1');
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag2'));
|
static::assertEquals($oTagSet->GetValues(), array('tag2'));
|
||||||
|
|
||||||
$oTagSet->AddTag('tag1');
|
$oTagSet->Add('tag1');
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag1', 'tag2'));
|
static::assertEquals($oTagSet->GetValues(), array('tag1', 'tag2'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -102,13 +102,13 @@ class ormTagSetTest extends ItopDataTestCase
|
|||||||
{
|
{
|
||||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, 3);
|
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, 3);
|
||||||
|
|
||||||
$oTagSet->SetValue(array('tag1', 'tag2', 'tag3'));
|
$oTagSet->SetValues(array('tag1', 'tag2', 'tag3'));
|
||||||
|
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag1', 'tag2', 'tag3'));
|
static::assertEquals($oTagSet->GetValues(), array('tag1', 'tag2', 'tag3'));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$oTagSet->SetValue(array('tag1', 'tag2', 'tag3', 'tag4'));
|
$oTagSet->SetValues(array('tag1', 'tag2', 'tag3', 'tag4'));
|
||||||
}
|
}
|
||||||
catch (\CoreException $e)
|
catch (\CoreException $e)
|
||||||
{
|
{
|
||||||
@@ -120,15 +120,15 @@ class ormTagSetTest extends ItopDataTestCase
|
|||||||
public function testEquals()
|
public function testEquals()
|
||||||
{
|
{
|
||||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
$oTagSet1->AddTag('tag1');
|
$oTagSet1->Add('tag1');
|
||||||
static::assertTrue($oTagSet1->Equals($oTagSet1));
|
static::assertTrue($oTagSet1->Equals($oTagSet1));
|
||||||
|
|
||||||
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
$oTagSet2->SetValue(array('tag1'));
|
$oTagSet2->SetValues(array('tag1'));
|
||||||
|
|
||||||
static::assertTrue($oTagSet1->Equals($oTagSet2));
|
static::assertTrue($oTagSet1->Equals($oTagSet2));
|
||||||
|
|
||||||
$oTagSet1->AddTag('tag2');
|
$oTagSet1->Add('tag2');
|
||||||
static::assertFalse($oTagSet1->Equals($oTagSet2));
|
static::assertFalse($oTagSet1->Equals($oTagSet2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,48 +136,48 @@ class ormTagSetTest extends ItopDataTestCase
|
|||||||
{
|
{
|
||||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
|
|
||||||
$oTagSet->SetValue(array('tag1'));
|
$oTagSet->SetValues(array('tag1'));
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag1'));
|
static::assertEquals($oTagSet->GetValues(), array('tag1'));
|
||||||
|
|
||||||
$oTagSet->SetValue(array('tag1', 'tag2'));
|
$oTagSet->SetValues(array('tag1', 'tag2'));
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag1', 'tag2'));
|
static::assertEquals($oTagSet->GetValues(), array('tag1', 'tag2'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveTag()
|
public function testRemoveTag()
|
||||||
{
|
{
|
||||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
$oTagSet->RemoveTag('tag_unknown');
|
$oTagSet->Remove('tag_unknown');
|
||||||
static::assertEquals($oTagSet->GetValue(), array());
|
static::assertEquals($oTagSet->GetValues(), array());
|
||||||
|
|
||||||
$oTagSet->SetValue(array('tag1'));
|
$oTagSet->SetValues(array('tag1'));
|
||||||
$oTagSet->RemoveTag('tag_unknown');
|
$oTagSet->Remove('tag_unknown');
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag1'));
|
static::assertEquals($oTagSet->GetValues(), array('tag1'));
|
||||||
|
|
||||||
$oTagSet->SetValue(array('tag1', 'tag2'));
|
$oTagSet->SetValues(array('tag1', 'tag2'));
|
||||||
$oTagSet->RemoveTag('tag1');
|
$oTagSet->Remove('tag1');
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag2'));
|
static::assertEquals($oTagSet->GetValues(), array('tag2'));
|
||||||
|
|
||||||
$oTagSet->AddTag('tag1');
|
$oTagSet->Add('tag1');
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag1', 'tag2'));
|
static::assertEquals($oTagSet->GetValues(), array('tag1', 'tag2'));
|
||||||
|
|
||||||
$oTagSet->RemoveTag('tag1');
|
$oTagSet->Remove('tag1');
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag2'));
|
static::assertEquals($oTagSet->GetValues(), array('tag2'));
|
||||||
|
|
||||||
$oTagSet->RemoveTag('tag1');
|
$oTagSet->Remove('tag1');
|
||||||
static::assertEquals($oTagSet->GetValue(), array('tag2'));
|
static::assertEquals($oTagSet->GetValues(), array('tag2'));
|
||||||
|
|
||||||
$oTagSet->RemoveTag('tag2');
|
$oTagSet->Remove('tag2');
|
||||||
static::assertEquals($oTagSet->GetValue(), array());
|
static::assertEquals($oTagSet->GetValues(), array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetDelta()
|
public function testGetDelta()
|
||||||
{
|
{
|
||||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
$oTagSet1->SetValue(array('tag1', 'tag2'));
|
$oTagSet1->SetValues(array('tag1', 'tag2'));
|
||||||
|
|
||||||
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
$oTagSet2->SetValue(array('tag1', 'tag3', 'tag4'));
|
$oTagSet2->SetValues(array('tag1', 'tag3', 'tag4'));
|
||||||
|
|
||||||
$aDelta = $oTagSet1->GetDelta($oTagSet2);
|
$aDelta = $oTagSet1->GetDelta($oTagSet2);
|
||||||
static::assertCount(2, $aDelta);
|
static::assertCount(2, $aDelta);
|
||||||
@@ -188,10 +188,10 @@ class ormTagSetTest extends ItopDataTestCase
|
|||||||
public function testApplyDelta()
|
public function testApplyDelta()
|
||||||
{
|
{
|
||||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
$oTagSet1->SetValue(array('tag1', 'tag2'));
|
$oTagSet1->SetValues(array('tag1', 'tag2'));
|
||||||
|
|
||||||
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet2 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
$oTagSet2->SetValue(array('tag1', 'tag3', 'tag4'));
|
$oTagSet2->SetValues(array('tag1', 'tag3', 'tag4'));
|
||||||
|
|
||||||
$aDelta = $oTagSet1->GetDelta($oTagSet2);
|
$aDelta = $oTagSet1->GetDelta($oTagSet2);
|
||||||
|
|
||||||
@@ -212,12 +212,12 @@ class ormTagSetTest extends ItopDataTestCase
|
|||||||
public function testGetModified($aInitialTags, $aDiffAndExpectedTags)
|
public function testGetModified($aInitialTags, $aDiffAndExpectedTags)
|
||||||
{
|
{
|
||||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
$oTagSet1->SetValue($aInitialTags);
|
$oTagSet1->SetValues($aInitialTags);
|
||||||
|
|
||||||
foreach($aDiffAndExpectedTags as $aTestItem)
|
foreach($aDiffAndExpectedTags as $aTestItem)
|
||||||
{
|
{
|
||||||
$oTagSet1->GenerateDiffFromTags($aTestItem['diff']);
|
$oTagSet1->GenerateDiffFromArray($aTestItem['diff']);
|
||||||
static::assertEquals($aTestItem['modified'], $oTagSet1->GetModifiedTags());
|
static::assertEquals($aTestItem['modified'], $oTagSet1->GetModified());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,11 +264,11 @@ class ormTagSetTest extends ItopDataTestCase
|
|||||||
public function testBulkModify($aInitialTags, $aDelta, $aExpectedTags)
|
public function testBulkModify($aInitialTags, $aDelta, $aExpectedTags)
|
||||||
{
|
{
|
||||||
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
$oTagSet1 = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||||
$oTagSet1->SetValue($aInitialTags);
|
$oTagSet1->SetValues($aInitialTags);
|
||||||
|
|
||||||
$oTagSet1->ApplyDelta($aDelta);
|
$oTagSet1->ApplyDelta($aDelta);
|
||||||
|
|
||||||
static::assertEquals($aExpectedTags, $oTagSet1->GetValue());
|
static::assertEquals($aExpectedTags, $oTagSet1->GetValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function BulkModifyProvider()
|
public function BulkModifyProvider()
|
||||||
|
|||||||
Reference in New Issue
Block a user