mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Export for spreadsheets: transform keys (id of the queried object or external keys) into the corresponding friendly name (reintegrated from branch 1.2.1)
SVN:trunk[1816]
This commit is contained in:
@@ -1244,6 +1244,10 @@ EOF
|
||||
$oPage->add(self::GetSetAsHTMLSpreadsheet($oSet, $aParams));
|
||||
}
|
||||
|
||||
/**
|
||||
* Spreadsheet output: designed for end users doing some reporting
|
||||
* Then the ids are excluded and replaced by the corresponding friendlyname
|
||||
*/
|
||||
static function GetSetAsHTMLSpreadsheet(DBObjectSet $oSet, $aParams = array())
|
||||
{
|
||||
$aFields = null;
|
||||
@@ -1289,18 +1293,27 @@ EOF
|
||||
}
|
||||
}
|
||||
}
|
||||
$aHeader[] = 'id';
|
||||
// Replace external key by the corresponding friendly name (if not already in the list)
|
||||
foreach($aList[$sAlias] as $sAttCode => $oAttDef)
|
||||
{
|
||||
if ($oAttDef->IsExternalKey())
|
||||
{
|
||||
unset($aList[$sAlias][$sAttCode]);
|
||||
$sFriendlyNameAttCode = $sAttCode.'_friendlyname';
|
||||
if (!array_key_exists($sFriendlyNameAttCode, $aList[$sAlias]) && MetaModel::IsValidAttCode($sClassName, $sFriendlyNameAttCode))
|
||||
{
|
||||
$oFriendlyNameAtt = MetaModel::GetAttributeDef($sClassName, $sFriendlyNameAttCode);
|
||||
$aList[$sAlias][$sFriendlyNameAttCode] = $oFriendlyNameAtt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($aList[$sAlias] as $sAttCode => $oAttDef)
|
||||
{
|
||||
$sStar = '';
|
||||
if ($oAttDef->IsExternalField())
|
||||
{
|
||||
$sExtKeyLabel = MetaModel::GetLabel($sClassName, $oAttDef->GetKeyAttCode());
|
||||
$oExtKeyAttDef = MetaModel::GetAttributeDef($sClassName, $oAttDef->GetKeyAttCode());
|
||||
if (!$oExtKeyAttDef->IsNullAllowed() && isset($aParams['showMandatoryFields']))
|
||||
{
|
||||
$sStar = '*';
|
||||
}
|
||||
$sRemoteAttLabel = MetaModel::GetLabel($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
|
||||
$oTargetAttDef = MetaModel::GetAttributeDef($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
|
||||
$sSuffix = '';
|
||||
@@ -1308,15 +1321,11 @@ EOF
|
||||
{
|
||||
$sSuffix = '->id';
|
||||
}
|
||||
$sColLabel = $sExtKeyLabel.'->'.$sRemoteAttLabel.$sSuffix.$sStar;
|
||||
$sColLabel = $sExtKeyLabel.'->'.$sRemoteAttLabel.$sSuffix;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!$oAttDef->IsNullAllowed() && isset($aParams['showMandatoryFields']))
|
||||
{
|
||||
$sStar = '*';
|
||||
}
|
||||
$sColLabel = MetaModel::GetLabel($sClassName, $sAttCode).$sStar;
|
||||
$sColLabel = MetaModel::GetLabel($sClassName, $sAttCode);
|
||||
}
|
||||
$oFinalAttDef = $oAttDef->GetFinalAttDef();
|
||||
if (get_class($oFinalAttDef) == 'AttributeDateTime')
|
||||
@@ -1343,19 +1352,11 @@ EOF
|
||||
foreach($aAuthorizedClasses as $sAlias => $sClassName)
|
||||
{
|
||||
$oObj = $aObjects[$sAlias];
|
||||
if (is_null($oObj))
|
||||
{
|
||||
$aRow[] = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$aRow[] = '<td>'.$oObj->GetKey().'</td>';
|
||||
}
|
||||
foreach($aList[$sAlias] as $sAttCode => $oAttDef)
|
||||
{
|
||||
if (is_null($oObj))
|
||||
{
|
||||
$aRow[] = '';
|
||||
$aRow[] = '<td></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -3534,6 +3534,43 @@ class AttributeFriendlyName extends AttributeComputedFieldVoid
|
||||
|
||||
public function GetKeyAttCode() {return $this->Get("extkey_attcode");}
|
||||
|
||||
public function GetLabel($sDefault = null)
|
||||
{
|
||||
$sLabel = parent::GetLabel('');
|
||||
if (strlen($sLabel) == 0)
|
||||
{
|
||||
$sKeyAttCode = $this->Get("extkey_attcode");
|
||||
if ($sKeyAttCode == 'id')
|
||||
{
|
||||
return Dict::S('Core:FriendlyName-Label');
|
||||
}
|
||||
else
|
||||
{
|
||||
$oExtKeyAttDef = MetaModel::GetAttributeDef($this->GetHostClass(), $sKeyAttCode);
|
||||
$sLabel = $oExtKeyAttDef->GetLabel($this->m_sCode);
|
||||
}
|
||||
}
|
||||
return $sLabel;
|
||||
}
|
||||
public function GetDescription($sDefault = null)
|
||||
{
|
||||
$sLabel = parent::GetDescription('');
|
||||
if (strlen($sLabel) == 0)
|
||||
{
|
||||
$sKeyAttCode = $this->Get("extkey_attcode");
|
||||
if ($sKeyAttCode == 'id')
|
||||
{
|
||||
return Dict::S('Core:FriendlyName-Description');
|
||||
}
|
||||
else
|
||||
{
|
||||
$oExtKeyAttDef = MetaModel::GetAttributeDef($this->GetHostClass(), $sKeyAttCode);
|
||||
$sLabel = $oExtKeyAttDef->GetDescription('');
|
||||
}
|
||||
}
|
||||
return $sLabel;
|
||||
}
|
||||
|
||||
// n/a, the friendly name is made of a complex expression (see GetNameSpec)
|
||||
protected function GetSQLCol() {return "";}
|
||||
|
||||
|
||||
@@ -140,6 +140,12 @@ Operators:<br/>
|
||||
|
||||
'Core:AttributePropertySet' => 'Properties',
|
||||
'Core:AttributePropertySet+' => 'List of untyped properties (name and value)',
|
||||
|
||||
'Core:AttributeFriendlyName' => 'Friendly name',
|
||||
'Core:AttributeFriendlyName+' => 'Attribute created automatically ; the friendly name is computed after several attributes',
|
||||
|
||||
'Core:FriendlyName-Label' => 'Name',
|
||||
'Core:FriendlyName-Description' => 'Friendly name',
|
||||
));
|
||||
|
||||
|
||||
|
||||
@@ -485,6 +485,13 @@ Opérateurs :<br/>
|
||||
'Core:AttributeTable+' => 'Tableau à deux dimensions',
|
||||
'Core:AttributePropertySet' => 'Propriétés',
|
||||
'Core:AttributePropertySet+' => 'Liste de propriétés (nom et valeur) non typées',
|
||||
|
||||
'Core:AttributeFriendlyName' => 'Nom usuel (convivial)',
|
||||
'Core:AttributeFriendlyName+' => 'Attribut créé automatiquement ; sa valeur est calculée d\'après d\'autres attributs',
|
||||
|
||||
'Core:FriendlyName-Label' => 'Nom',
|
||||
'Core:FriendlyName-Description' => 'Nom usuel',
|
||||
|
||||
'Change:ObjectCreated' => 'Elément créé',
|
||||
'Change:ObjectDeleted' => 'Elément effacé',
|
||||
'Change:ObjectModified' => 'Elément modifié',
|
||||
|
||||
Reference in New Issue
Block a user