mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01: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)
|
||||
{
|
||||
if ($sObjKey == 0) return '<em>undefined</em>';
|
||||
if ($sObjKey <= 0) return '<em>undefined</em>'; // Objects built in memory have negative IDs
|
||||
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sExtClassNameAtt = MetaModel::GetNameAttributeCode($sObjClass);
|
||||
@@ -89,23 +89,35 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
|
||||
if ($oAtt->IsExternalKey())
|
||||
{
|
||||
// retrieve the "external fields" linked to this external key
|
||||
$sTargetClass = $oAtt->GetTargetClass();
|
||||
$aAvailableFields = array();
|
||||
foreach (MetaModel::GetExternalFields(get_class($this), $sAttCode) as $oExtField)
|
||||
if ($this->IsNew())
|
||||
{
|
||||
$aAvailableFields[$oExtField->GetExtAttCode()] = $oExtField->GetAsHTML($this->Get($oExtField->GetCode()));
|
||||
}
|
||||
$sExtClassNameAtt = MetaModel::GetNameAttributeCode($sTargetClass);
|
||||
// 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];
|
||||
// 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
|
||||
$targetObjId = $this->Get($sAttCode);
|
||||
$oTargetObj = MetaModel::GetObject($sTargetClass, $targetObjId, false); // false => not sure it exists
|
||||
if (is_object($oTargetObj))
|
||||
{
|
||||
$sDisplayValue = $oTargetObj->GetName();
|
||||
}
|
||||
}
|
||||
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
|
||||
|
||||
@@ -89,8 +89,9 @@ switch($operation)
|
||||
{
|
||||
$sId = $oWizardHelper->GetIdForField($sAttCode);
|
||||
$value = $oObj->Get($sAttCode);
|
||||
$displayValue = $oObj->GetDisplayValue($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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user