diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index d09cae003..9955bc4c3 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -4221,6 +4221,7 @@ EOF $oDummyObj->Set($sAttCode, $currValue); /** @var ormTagSet $oTagSet */ $oTagSet = $oDummyObj->Get($sAttCode); + $oTagSet->SetDisplayPartial(true); foreach($aKeys as $iIndex => $sValues) { if ($iIndex == 0) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 93ffacaaa..287215967 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -9655,14 +9655,27 @@ class AttributeTagSet extends AttributeSet { $aJson['partial_values'] = array(); $aJson['orig_value'] = array(); + $aJson['added'] = array(); + $aJson['removed'] = array(); } else { - $aJson['partial_values'] = $oValue->GetModified(); $aJson['orig_value'] = array_merge($oValue->GetValues(), $oValue->GetModified()); + $aJson['added'] = $oValue->GetAdded(); + $aJson['removed'] = $oValue->GetRemoved(); + + if ($oValue->DisplayPartial()) + { + // For bulk updates + $aJson['partial_values'] = $oValue->GetModified(); + } + else + { + // For simple updates + $aJson['partial_values'] = array(); + } } - $aJson['added'] = array(); - $aJson['removed'] = array(); + $iMaxTags = $this->GetMaxItems(); $aJson['max_items_allowed'] = $iMaxTags; diff --git a/core/ormtagset.class.inc.php b/core/ormtagset.class.inc.php index 46dc7e04f..b8f9a1481 100644 --- a/core/ormtagset.class.inc.php +++ b/core/ormtagset.class.inc.php @@ -26,6 +26,9 @@ */ final class ormTagSet extends ormSet { + private $m_bDisplayPartial = false; + + /** * ormTagSet constructor. * @@ -299,6 +302,82 @@ final class ormTagSet extends ormSet return $aModifiedTagCodes; } + /** + * @return string[] list of codes for added entries + */ + public function GetAdded() + { + $aAddedTagCodes = array_keys($this->aAdded); + sort($aAddedTagCodes); + + return $aAddedTagCodes; + } + + /** + * @return string[] list of codes for removed entries + */ + public function GetRemoved() + { + $aRemovedTagCodes = array_keys($this->aRemoved); + sort($aRemovedTagCodes); + + return $aRemovedTagCodes; + } + + /** + * Apply a delta to the current ItemSet + * $aDelta['added] = array of added items + * $aDelta['removed'] = array of removed items + * + * @param $aDelta + * + * @throws \CoreException + */ + public function ApplyDelta($aDelta) + { + if (isset($aDelta['removed'])) + { + foreach($aDelta['removed'] as $oItem) + { + $this->Remove($oItem); + } + } + if (isset($aDelta['added'])) + { + foreach($aDelta['added'] as $oItem) + { + $this->Add($oItem); + } + } + } + + /** + * Populates the added and removed arrays for bulk edit + * + * @param string[] $aItems + * + * @throws \CoreException + */ + public function GenerateDiffFromArray($aItems) + { + foreach($this->GetValues() as $oCurrentItem) + { + if (!in_array($oCurrentItem, $aItems)) + { + $this->Remove($oCurrentItem); + } + } + + foreach($aItems as $oNewItem) + { + $this->Add($oNewItem); + } + + // Keep only the aModified list + $this->aRemoved = array(); + $this->aAdded = array(); + } + /** * Check whether a tag code is valid or not for this TagSet * @@ -479,4 +558,21 @@ final class ormTagSet extends ormSet return TagSetFieldData::GetTagDataClassName($this->sClass, $this->sAttCode); } + + /** + * @return bool + */ + public function DisplayPartial() + { + return $this->m_bDisplayPartial; + } + + /** + * @param bool $m_bDisplayPartial + */ + public function SetDisplayPartial($m_bDisplayPartial) + { + $this->m_bDisplayPartial = $m_bDisplayPartial; + } + } \ No newline at end of file