undefined';
$oAppContext = new ApplicationContext();
$sExtClassNameAtt = MetaModel::GetNameAttributeCode($sObjClass);
$sPage = self::ComputeUIPage($sObjClass);
// Use the "name" of the target class as the label of the hyperlink
// unless it's not available in the external attributes...
if (isset($aAvailableFields[$sExtClassNameAtt]))
{
$sLabel = $aAvailableFields[$sExtClassNameAtt];
}
else
{
$sLabel = implode(' / ', $aAvailableFields);
}
// Safety belt
//
if (empty($sLabel))
{
// Developer's note:
// This is doing the job for you, but that is just there in case
// the external fields associated to the external key are blanks
// The ultimate solution will be to query the name automatically
// and independantly from the data model (automatic external field)
// AND make the name be a mandatory field
//
$sObject = MetaModel::GetObject($sObjClass, $sObjKey);
$sLabel = $sObject->GetDisplayName();
}
// Safety net
//
if (empty($sLabel))
{
$sLabel = MetaModel::GetName($sObjClass)." #$sObjKey";
}
$sHint = MetaModel::GetName($sObjClass)."::$sObjKey";
return "GetForLink()."\" title=\"$sHint\">$sLabel";
}
public function GetDisplayValue($sAttCode)
{
$sDisplayValue = "";
$sStateAttCode = MetaModel::GetStateAttributeCode(get_class($this));
if ($sStateAttCode == $sAttCode)
{
$aStates = MetaModel::EnumStates(get_class($this));
$sDisplayValue = $aStates[$this->Get($sAttCode)]['label'];
}
else
{
$oAtt = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
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)
{
$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];
}
else
{
$sDisplayValue = implode(' / ', $aAvailableFields);
}
}
else
{
$sDisplayValue = $this->GetAsHTML($sAttCode);
}
}
return $sDisplayValue;
}
function DisplayBareHeader(web_page $oPage)
{
// Standard Header with name, actions menu and history block
//
$oPage->add("
\n");
// action menu
$oSingletonFilter = new DBObjectSearch(get_class($this));
$oSingletonFilter->AddCondition('pkey', array($this->GetKey()));
$oBlock = new MenuBlock($oSingletonFilter, 'popup', false);
$oBlock->Display($oPage, -1);
$oPage->add("
\n");
// history block (with toggle)
$oHistoryFilter = new DBObjectSearch('CMDBChangeOpSetAttribute');
$oHistoryFilter->AddCondition('objkey', $this->GetKey());
$oBlock = new HistoryBlock($oHistoryFilter, 'toggle', false);
$oBlock->Display($oPage, -1);
$oPage->add("
\n");
}
function DisplayBareDetails(web_page $oPage)
{
$oPage->add($this->GetBareDetails($oPage));
}
function DisplayBareRelations(web_page $oPage)
{
// Related objects
$oPage->AddTabContainer('Related Objects');
$oPage->SetCurrentTabContainer('Related Objects');
foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode=>$oAttDef)
{
if ((get_class($oAttDef) == 'AttributeLinkedSetIndirect') || (get_class($oAttDef) == 'AttributeLinkedSet'))
{
$oPage->SetCurrentTab($oAttDef->GetLabel());
$oPage->p($oAttDef->GetDescription());
if (get_class($oAttDef) == 'AttributeLinkedSet')
{
$sTargetClass = $oAttDef->GetLinkedClass();
$oFilter = new DBObjectSearch($sTargetClass);
$oFilter->AddCondition($oAttDef->GetExtKeyToMe(), $this->GetKey()); // @@@ condition has same name as field ??
$oBlock = new DisplayBlock($oFilter, 'list', false);
$oBlock->Display($oPage, 0);
}
else // get_class($oAttDef) == 'AttributeLinkedSetIndirect'
{
$sLinkClass = $oAttDef->GetLinkedClass();
// Transform the DBObjectSet into a CMBDObjectSet !!!
$aLinkedObjects = $this->Get($sAttCode)->ToArray(false);
if (count($aLinkedObjects) > 0)
{
$oSet = CMDBObjectSet::FromArray($sLinkClass, $aLinkedObjects);
$aParams = array(
'link_attr' => $oAttDef->GetExtKeyToMe(),
'object_id' => $this->GetKey(),
'target_attr' => $oAttDef->GetExtKeyToRemote(),
);
self::DisplaySet($oPage, $oSet, $aParams);
}
}
}
}
$oPage->SetCurrentTab('');
}
function GetDisplayName()
{
return $this->GetAsHTML(MetaModel::GetNameAttributeCode(get_class($this)));
}
function GetBareDetails(web_page $oPage)
{
$sHtml = '';
$oAppContext = new ApplicationContext();
$sStateAttCode = MetaModel::GetStateAttributeCode(get_class($this));
$aDetails = array();
$sClass = get_class($this);
$aList = MetaModel::GetZListItems($sClass, 'details');
foreach($aList as $sAttCode)
{
$iFlags = $this->GetAttributeFlags($sAttCode);
if ( ($iFlags & OPT_ATT_HIDDEN) == 0)
{
// The field is visible in the current state of the object
if ($sStateAttCode == $sAttCode)
{
// Special display for the 'state' attribute itself
$sDisplayValue = $this->GetState();
}
else
{
$sDisplayValue = $this->GetAsHTML($sAttCode);
}
$aDetails[] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'value' => $sDisplayValue);
}
}
$sHtml .= $oPage->GetDetails($aDetails);
return $sHtml;
}
function DisplayDetails(web_page $oPage)
{
$sTemplate = Utils::ReadFromFile(MetaModel::GetDisplayTemplate(get_class($this)));
if (!empty($sTemplate))
{
$oTemplate = new DisplayTemplate($sTemplate);
$oTemplate->Render($oPage, array('class_name'=> MetaModel::GetName(get_class($this)),'class'=> get_class($this),'pkey'=> $this->GetKey(), 'name' => $this->GetName()));
}
else
{
// Object's details
// template not found display the object using the *old style*
$this->DisplayBareHeader($oPage);
$this->DisplayBareDetails($oPage);
$this->DisplayBareRelations($oPage);
}
}
function DisplayPreview(web_page $oPage)
{
$aDetails = array();
$sClass = get_class($this);
$aList = MetaModel::GetZListItems($sClass, 'preview');
foreach($aList as $sAttCode)
{
$aDetails[] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'value' =>$this->GetAsHTML($sAttCode));
}
$oPage->details($aDetails);
}
// Comment by Rom: this helper may be used to display objects of class DBObject
// -> I am using this to display the changes history
public static function DisplaySet(web_page $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
{
$oPage->add(self::GetDisplaySet($oPage, $oSet, $aExtraParams));
}
//public static function GetDisplaySet(web_page $oPage, CMDBObjectSet $oSet, $sLinkageAttribute = '', $bDisplayMenu = true, $bSelectMode = false)
public static function GetDisplaySet(web_page $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
{
static $iListId = 0;
$iListId++;
// Initialize and check the parameters
$sLinkageAttribute = isset($aExtraParams['link_attr']) ? $aExtraParams['link_attr'] : '';
$iLinkedObjectId = isset($aExtraParams['object_id']) ? $aExtraParams['object_id'] : 0;
$sTargetAttr = isset($aExtraParams['target_attr']) ? $aExtraParams['target_attr'] : '';
if (!empty($sLinkageAttribute))
{
if($iLinkedObjectId == 0)
{
// if 'links' mode is requested the id of the object to link to must be specified
throw new ApplicationException("Parameter object_id is mandatory when link_attr is specified. Check the definition of the display template.");
}
if($sTargetAttr == '')
{
// if 'links' mode is requested the d of the object to link to must be specified
throw new ApplicationException("Parameter target_attr is mandatory when link_attr is specified. Check the definition of the display template.");
}
}
$bDisplayMenu = isset($aExtraParams['menu']) ? $aExtraParams['menu'] == true : true;
$bSelectMode = isset($aExtraParams['selection_mode']) ? $aExtraParams['selection_mode'] == true : false;
$sHtml = '';
$oAppContext = new ApplicationContext();
$sClassName = $oSet->GetFilter()->GetClass();
$aAttribs = array();
$aList = MetaModel::GetZListItems($sClassName, 'list');
if (!empty($sLinkageAttribute))
{
// The set to display is in fact a set of links between the object specified in the $sLinkageAttribute
// and other objects...
// The display will then group all the attributes related to the link itself:
// | Link_attr1 | link_attr2 | ... || Object_attr1 | Object_attr2 | Object_attr3 | .. | Object_attr_n |
$aAttDefs = MetaModel::ListAttributeDefs($sClassName);
assert(isset($aAttDefs[$sLinkageAttribute]));
$oAttDef = $aAttDefs[$sLinkageAttribute];
assert($oAttDef->IsExternalKey());
// First display all the attributes specific to the link record
foreach($aList as $sLinkAttCode)
{
$oLinkAttDef = $aAttDefs[$sLinkAttCode];
if ( (!$oLinkAttDef->IsExternalKey()) && (!$oLinkAttDef->IsExternalField()) )
{
$aDisplayList[] = $sLinkAttCode;
}
}
// Then display all the attributes neither specific to the link record nor to the 'linkage' object (because the latter are constant)
foreach($aList as $sLinkAttCode)
{
$oLinkAttDef = $aAttDefs[$sLinkAttCode];
if (($oLinkAttDef->IsExternalKey() && ($sLinkAttCode != $sLinkageAttribute))
|| ($oLinkAttDef->IsExternalField() && ($oLinkAttDef->GetKeyAttCode()!=$sLinkageAttribute)) )
{
$aDisplayList[] = $sLinkAttCode;
}
}
// First display all the attributes specific to the link
// Then display all the attributes linked to the other end of the relationship
$aList = $aDisplayList;
}
foreach($aList as $sAttCode)
{
if ($bSelectMode)
{
$aAttribs['form::select'] = array('label' => "", 'description' => 'Select / Deselect All');
}
$aAttribs['key'] = array('label' => '', 'description' => 'Click to display');
$aAttribs[$sAttCode] = array('label' => MetaModel::GetLabel($sClassName, $sAttCode), 'description' => MetaModel::GetDescription($sClassName, $sAttCode));
}
$aValues = array();
$oSet->Seek(0);
while ($oObj = $oSet->Fetch())
{
$aRow['key'] = $oObj->GetKey();
if ($bSelectMode)
{
$aRow['form::select'] = "GetKey()."\">";
}
$aRow['key'] = $oObj->GetKey();
foreach($aList as $sAttCode)
{
$aRow[$sAttCode] = $oObj->GetAsHTML($sAttCode);
}
$aValues[] = $aRow;
}
$oMenuBlock = new MenuBlock($oSet->GetFilter());
$sHtml .= '