N°962: TagSet - add label support

SVN:b931[6031]
This commit is contained in:
Eric Espié
2018-08-29 10:26:36 +00:00
committed by Pierre Goiffon
parent a03c553000
commit 1953c05b33
2 changed files with 70 additions and 16 deletions

View File

@@ -6023,10 +6023,16 @@ class AttributeTagSet extends AttributeDBField
*/ */
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true) public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
{ {
// TODO $bLocalize = true
if (is_object($value) && ($value instanceof ormTagSet)) if (is_object($value) && ($value instanceof ormTagSet))
{ {
$aValues = $value->GetValue(); if ($bLocalize)
{
$aValues = $value->GetLabel();
}
else
{
$aValues = $value->GetValue();
}
return implode(' ', $aValues); return implode(' ', $aValues);
} }
return null; return null;
@@ -6042,12 +6048,17 @@ class AttributeTagSet extends AttributeDBField
*/ */
public function GetAsXML($value, $oHostObject = null, $bLocalize = true) public function GetAsXML($value, $oHostObject = null, $bLocalize = true)
{ {
// TODO $bLocalize = true
if (is_object($value) && ($value instanceof ormTagSet)) if (is_object($value) && ($value instanceof ormTagSet))
{ {
$sRes = "<Set>\n"; $sRes = "<Set>\n";
$aValues = $value->GetValue(); if ($bLocalize)
if (!empty($aValuess)) {
$aValues = $value->GetLabel();
}
else
{
$aValues = $value->GetValue();
} if (!empty($aValuess))
{ {
$sRes .= '<Tag>'.implode('</Tag><Tag>', $aValues).'</Tag>'; $sRes .= '<Tag>'.implode('</Tag><Tag>', $aValues).'</Tag>';
} }
@@ -6073,10 +6084,16 @@ class AttributeTagSet extends AttributeDBField
*/ */
public function GetAsCSV($value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true, $bConvertToPlainText = false) public function GetAsCSV($value, $sSeparator = ',', $sTextQualifier = '"', $oHostObject = null, $bLocalize = true, $bConvertToPlainText = false)
{ {
// TODO $bLocalize = true
if (is_object($value) && ($value instanceof ormTagSet)) if (is_object($value) && ($value instanceof ormTagSet))
{ {
$aValues = $value->GetValue(); if ($bLocalize)
{
$aValues = $value->GetLabel();
}
else
{
$aValues = $value->GetValue();
}
$sRes = implode(' ', $aValues); $sRes = implode(' ', $aValues);
} }
else else
@@ -6110,10 +6127,16 @@ class AttributeTagSet extends AttributeDBField
*/ */
public function GetForTemplate($value, $sVerb, $oHostObject = null, $bLocalize = true) public function GetForTemplate($value, $sVerb, $oHostObject = null, $bLocalize = true)
{ {
// TODO $bLocalize = true
if (is_object($value) && ($value instanceof ormTagSet)) if (is_object($value) && ($value instanceof ormTagSet))
{ {
$aValues = $value->GetValue(); if ($bLocalize)
{
$aValues = $value->GetLabel();
}
else
{
$aValues = $value->GetValue();
}
switch ($sVerb) switch ($sVerb)
{ {

View File

@@ -28,8 +28,8 @@
final class ormTagSet final class ormTagSet
{ {
private $sClass; // class of the tag private $sClass; // class of the tag field
private $sAttCode; // attcode of the tag private $sAttCode; // attcode of the tag field
private $aAllowedTags; private $aAllowedTags;
private $oOriginalSet; private $oOriginalSet;
@@ -119,12 +119,12 @@ final class ormTagSet
*/ */
public function GetValue() public function GetValue()
{ {
$aValue = array(); $aValues = array();
foreach ($this->aPreserved as $oTag) foreach ($this->aPreserved as $oTag)
{ {
try try
{ {
$aValue[] = $oTag->Get('tag_code'); $aValues[] = $oTag->Get('tag_code');
} catch (CoreException $e) } catch (CoreException $e)
{ {
IssueLog::Error($e->getMessage()); IssueLog::Error($e->getMessage());
@@ -134,16 +134,47 @@ final class ormTagSet
{ {
try try
{ {
$aValue[] = $oTag->Get('tag_code'); $aValues[] = $oTag->Get('tag_code');
} catch (CoreException $e) } catch (CoreException $e)
{ {
IssueLog::Error($e->getMessage()); IssueLog::Error($e->getMessage());
} }
} }
sort($aValue); sort($aValues);
return $aValue; return $aValues;
}
public function GetLabel()
{
$aLabels = array();
foreach ($this->aPreserved as $oTag)
{
try
{
$aValues[$oTag->Get('tag_code')] = $oTag->Get('tag_label');
} catch (CoreException $e)
{
IssueLog::Error($e->getMessage());
}
}
foreach ($this->aAdded as $oTag)
{
try
{
$aValues[$oTag->Get('tag_code')] = $oTag->Get('tag_label');
} catch (CoreException $e)
{
IssueLog::Error($e->getMessage());
}
}
ksort($aValues);
foreach($aValues as $sLabel)
{
$aLabels[] = $sLabel;
}
return $aLabels;
} }
/** /**