N°3917 Refactor algorithm to get object details semantic image icon in object's GetIcon method in order to propagate this feature anywhere where GetIcon is called

This commit is contained in:
Stephen Abello
2021-09-28 15:01:06 +02:00
parent ec47645ef7
commit 5680d9579c
3 changed files with 42 additions and 18 deletions

View File

@@ -1471,9 +1471,11 @@ abstract class DBObject implements iDisplay
public function GetIcon($bImgTag = true)
{
$sCode = $this->ComputeHighlightCode();
$sClass = get_class($this);
if($sCode != '')
{
$aHighlightScale = MetaModel::GetHighlightScale(get_class($this));
$aHighlightScale = MetaModel::GetHighlightScale($sClass);
if (array_key_exists($sCode, $aHighlightScale))
{
$sIconUrl = $aHighlightScale[$sCode]['icon'];
@@ -1486,10 +1488,45 @@ abstract class DBObject implements iDisplay
return $sIconUrl;
}
}
}
}
// Get object instance own image if it exists
$sImageAttCode = MetaModel::GetImageAttributeCode($sClass);
$sIconUrl = $this->HasInstanceIcon() ? $this->Get($sImageAttCode)->GetDisplayURL($sClass, $this->GetKey(), $sImageAttCode) : '';
if (strlen($sIconUrl) > 0) {
if($bImgTag) {
return "<img src=\"$sIconUrl\"/>";
}
else {
return $sIconUrl;
}
}
return MetaModel::GetClassIcon(get_class($this), $bImgTag);
}
/**
* @return bool True if the object has an image attribute as semantic attribute and its value is not empty
* @throws \ArchivedObjectException
* @throws \CoreException
* @since 3.0.0
*/
public function HasInstanceIcon(): bool
{
$bHasInstanceIcon = false;
$sClass = get_class($this);
if (!$this->IsNew() && MetaModel::HasImageAttributeCode($sClass)) {
$sImageAttCode = MetaModel::GetImageAttributeCode($sClass);
if (!empty($sImageAttCode)) {
/** @var \ormDocument $oImage */
$oImage = $this->Get($sImageAttCode);
$bHasInstanceIcon = !$oImage->IsEmpty();
}
}
return $bHasInstanceIcon;
}
/**
* Get the label of a class
*

View File

@@ -409,7 +409,7 @@ class DisplayableNode extends GraphNode
{
$oNewNode = new DisplayableGroupNode($oGraph, $sNewId);
$oNewNode->SetProperty('label', 'x'.$aGroupProps['count']);
$oNewNode->SetProperty('icon_url', $aGroupProps['icon_url']);
$oNewNode->SetProperty('icon_url', MetaModel::GetClassIcon($sClass, false));
$oNewNode->SetProperty('class', $sClass);
$oNewNode->SetProperty('is_reached', ($sStatus == 'reached'));
$oNewNode->SetProperty('count', $aGroupProps['count']);
@@ -589,7 +589,7 @@ class DisplayableRedundancyNode extends DisplayableNode
{
$oNewNode = new DisplayableGroupNode($oGraph, '-'.$this->GetId().'::'.$sClass.'/'.$sStatus);
$oNewNode->SetProperty('label', 'x'.count($aGroupProps['nodes']));
$oNewNode->SetProperty('icon_url', $aGroupProps['icon_url']);
$oNewNode->SetProperty('icon_url', MetaModel::GetClassIcon($sClass, false));
$oNewNode->SetProperty('is_reached', ($sStatus == 'is_reached'));
$oNewNode->SetProperty('class', $sClass);
$oNewNode->SetProperty('count', count($aGroupProps['nodes']));

View File

@@ -204,20 +204,7 @@ class ObjectDetails extends Panel implements iKeyboardShortcut
// Default icon is the class icon
$sIconUrl = $oObject->GetIcon(false);
// Note: Class icons are a square image with no margin around, so they need to be zoomed out in the medallion
$sIconCoverMethod = static::ENUM_ICON_COVER_METHOD_ZOOMOUT;
// Use object image from semantic attribute only if it's not the default image
if (!$oObject->IsNew() && MetaModel::HasImageAttributeCode($this->sClassName)) {
$sImageAttCode = MetaModel::GetImageAttributeCode($this->sClassName);
if (!empty($sImageAttCode)) {
/** @var \ormDocument $oImage */
$oImage = $oObject->Get($sImageAttCode);
if (!$oImage->IsEmpty()) {
$sIconUrl = $oImage->GetDisplayURL($this->sClassName, $this->sObjectId, $sImageAttCode);
$sIconCoverMethod = static::ENUM_ICON_COVER_METHOD_COVER;
}
}
}
$sIconCoverMethod = $oObject->HasInstanceIcon() ? static::ENUM_ICON_COVER_METHOD_COVER : static::ENUM_ICON_COVER_METHOD_ZOOMOUT;
$this->SetIcon($sIconUrl, $sIconCoverMethod, true);
}