N°931: TagSet Fix CSV import

This commit is contained in:
Eric
2018-09-14 12:07:15 +02:00
parent 6f1dc44932
commit d981fd35ef
2 changed files with 38 additions and 1 deletions

View File

@@ -5995,6 +5995,10 @@ class AttributeTagSet extends AttributeDBFieldVoid
$aGoodTags = array();
foreach($aTagCodes as $sTagCode)
{
if ($sTagCode === '')
{
continue;
}
if ($oTagSet->IsValidTag($sTagCode))
{
$aGoodTags[] = $sTagCode;
@@ -6048,7 +6052,20 @@ class AttributeTagSet extends AttributeDBFieldVoid
*/
public function MakeValueFromString($sProposedValue, $bLocalizedValue = false, $sSepItem = null, $sSepAttribute = null, $sSepValue = null, $sAttributeQualifier = null)
{
// TODO $bLocalizedValue
if ($bLocalizedValue && !empty($sProposedValue))
{
$oTagSet = new ormTagSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode());
$aLabels = explode('|', $sProposedValue);
$aCodes = array();
foreach($aLabels as $sTagLabel)
{
if (!empty($sTagLabel))
{
$aCodes[] = $oTagSet->GetTagFromLabel($sTagLabel);
}
}
$sProposedValue = implode(' ', $aCodes);
}
return $this->MakeRealValue($sProposedValue, null);
}

View File

@@ -429,6 +429,26 @@ final class ormTagSet
throw new CoreUnexpectedValue("{$sTagCode} is not defined as a valid tag for {$this->sClass}:{$this->sAttCode}");
}
/**
* @param $sTagCode
*
* @return DBObject tag
* @throws \CoreUnexpectedValue
* @throws \CoreException
*/
public function GetTagFromLabel($sTagLabel)
{
$aAllowedTags = $this->GetAllowedTags();
foreach($aAllowedTags as $oAllowedTag)
{
if ($oAllowedTag->Get('tag_label') === $sTagLabel)
{
return $oAllowedTag->Get('tag_code');
}
}
throw new CoreUnexpectedValue("{$sTagLabel} is not defined as a valid tag for {$this->sClass}:{$this->sAttCode}");
}
/**
* @return \TagSetFieldData[]
* @throws \CoreException