mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
Completed the implementation of 1:n links. The default value should now works for all external keys (whether they are displayed as an autocomplete or or a simple select)
SVN:trunk[253]
This commit is contained in:
@@ -35,7 +35,7 @@ abstract class cmdbAbstractObject extends CMDBObject
|
|||||||
|
|
||||||
protected static function MakeHyperLink($sObjClass, $sObjKey, $aAvailableFields)
|
protected static function MakeHyperLink($sObjClass, $sObjKey, $aAvailableFields)
|
||||||
{
|
{
|
||||||
if ($sObjKey == 0) return '<em>undefined</em>';
|
if ($sObjKey <= 0) return '<em>undefined</em>'; // Objects built in memory have negative IDs
|
||||||
|
|
||||||
$oAppContext = new ApplicationContext();
|
$oAppContext = new ApplicationContext();
|
||||||
$sExtClassNameAtt = MetaModel::GetNameAttributeCode($sObjClass);
|
$sExtClassNameAtt = MetaModel::GetNameAttributeCode($sObjClass);
|
||||||
@@ -89,23 +89,35 @@ abstract class cmdbAbstractObject extends CMDBObject
|
|||||||
|
|
||||||
if ($oAtt->IsExternalKey())
|
if ($oAtt->IsExternalKey())
|
||||||
{
|
{
|
||||||
// retrieve the "external fields" linked to this external key
|
|
||||||
$sTargetClass = $oAtt->GetTargetClass();
|
$sTargetClass = $oAtt->GetTargetClass();
|
||||||
$aAvailableFields = array();
|
if ($this->IsNew())
|
||||||
foreach (MetaModel::GetExternalFields(get_class($this), $sAttCode) as $oExtField)
|
|
||||||
{
|
{
|
||||||
$aAvailableFields[$oExtField->GetExtAttCode()] = $oExtField->GetAsHTML($this->Get($oExtField->GetCode()));
|
// The current object exists only in memory, don't try to query it in the DB !
|
||||||
}
|
// instead let's query for the object pointed by the external key, and get its name
|
||||||
$sExtClassNameAtt = MetaModel::GetNameAttributeCode($sTargetClass);
|
$targetObjId = $this->Get($sAttCode);
|
||||||
// Use the "name" of the target class as the label of the hyperlink
|
$oTargetObj = MetaModel::GetObject($sTargetClass, $targetObjId, false); // false => not sure it exists
|
||||||
// unless it's not available in the external fields...
|
if (is_object($oTargetObj))
|
||||||
if (isset($aAvailableFields[$sExtClassNameAtt]))
|
{
|
||||||
{
|
$sDisplayValue = $oTargetObj->GetName();
|
||||||
$sDisplayValue = $aAvailableFields[$sExtClassNameAtt];
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sDisplayValue = implode(' / ', $aAvailableFields);
|
// retrieve the "external fields" linked to this external key
|
||||||
|
foreach (MetaModel::GetExternalFields(get_class($this), $sAttCode) as $oExtField)
|
||||||
|
{
|
||||||
|
$aAvailableFields[$oExtField->GetExtAttCode()] = $oExtField->GetAsHTML($this->Get($oExtField->GetCode()));
|
||||||
|
}
|
||||||
|
// Use the "name" of the target class as the label of the hyperlink
|
||||||
|
// unless it's not available in the external fields...
|
||||||
|
if (isset($aAvailableFields[$sExtClassNameAtt]))
|
||||||
|
{
|
||||||
|
$sDisplayValue = $aAvailableFields[$sExtClassNameAtt];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sDisplayValue = implode(' / ', $aAvailableFields);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -89,8 +89,9 @@ switch($operation)
|
|||||||
{
|
{
|
||||||
$sId = $oWizardHelper->GetIdForField($sAttCode);
|
$sId = $oWizardHelper->GetIdForField($sAttCode);
|
||||||
$value = $oObj->Get($sAttCode);
|
$value = $oObj->Get($sAttCode);
|
||||||
|
$displayValue = $oObj->GetDisplayValue($sAttCode);
|
||||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||||
$sHTMLValue = cmdbAbstractObject::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value, '', 'att_'.$sId, '', 0, array('this' => $oObj));
|
$sHTMLValue = cmdbAbstractObject::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value, $displayValue, 'att_'.$sId, '', 0, array('this' => $oObj));
|
||||||
|
|
||||||
$oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
|
$oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user