Sidebar

Using iTop

Creating your iTop

iTop Customization

"How to" examples
DataModel

User Interface

Automation & Ticket management

Portal Customization

:: Version 3.3.0 ::

Computed icon on an object

Prerequisite: You must be familiar with the Syntax used in Tutorials and have already created an extension.

learning:
Compute the object icon on the fly based on another related object
level:
Medium
domains:
PHP
min version:
3.0.0

Since iTop 3.0 when displaying an object details, summary (over card) or in an impact analysis graph.

  • Out of the box each instances of a given class share the same icon defined in the DataModel
  • Out of the box, on class such as UserRequest the icon depends on the status of the Request
  • Out of the box, on class such as Person with a picture field, that picture can be used as icon for this object. This mechanism can be set on other classes
  • Out of the box from iTop 3.3.0, on sub-classes of SoftwareInstance, the object icon is the logo of the associate software (See code below)

All those setting can be changed in the Designer or with an iTop extension

class:SoftwareInstance
public function GetIcon($bImgTag = true)
{
        // If there is an image defined on the associated Software, we use it
        $sIconClass = 'Software'; // the class storing the image which will be used as icon for the current object
        $sExtKeyCode = 'software_id'; // the attribute code pointing to the class having the image to display
        $sIconAttCode = 'logo'; // the attribute code of the image to display on the IconClass
 
        $iObj = $this->Get($sExtKeyCode);
        if ($iObj > 0) {
                $oObj = MetaModel::GetObject($sIconClass, $iObj, true, true);
                $oImage = $oObj->Get($sIconAttCode);
                $sIconUrl = $oImage->IsEmpty() ? '' : $oImage->GetDisplayURL($sIconClass, $iObj, $sIconAttCode);
                if (strlen($sIconUrl) > 0) {
                         if ($bImgTag) {
                                  return "<img src=\"$sIconUrl\" alt=''/>";
                         } else {
                                  return $sIconUrl;
                         }
                }
        }
        // Return the default image
        return parent::GetIcon($bImgTag);
}
3_3_0/customization/dynamic-icon.txt ยท Last modified: 2026/07/23 16:11 by 127.0.0.1
Back to top
Contact us