sClassName = get_class($oObject); $this->sClassLabel = MetaModel::GetName($this->GetClassName()); $this->sObjectId = $oObject->GetKey(); // Note: We get the raw name as only the front-end consumer knows when and how to encode it. $this->sObjectName = $oObject->GetRawName(); $this->sObjectMode = $sMode; $oStyle = MetaModel::GetClassStyle($this->sClassName); $sPanelColor = empty($oStyle->GetMainColor()) ? static::DEFAULT_COLOR : $oStyle->GetMainColor(); parent::__construct($this->sObjectName, [], $sPanelColor, $sId); $this->ComputeIconUrl($oObject); $this->ComputeState($oObject); } /** * @see self::$sClassName * @return string */ public function GetClassName(): string { return $this->sClassName; } /** * @see self::$sClassLabel * @return string */ public function GetClassLabel(): string { return $this->sClassLabel; } /** * @see self::$sObjectName * @return string */ public function GetObjectName(): string { return $this->sObjectName; } /** * @see self::$sObjectId * @return string */ public function GetObjectId(): string { return $this->sObjectId; } /** * @see self::$sObjectMode * @return string */ public function GetObjectMode(): string { return $this->sObjectMode; } /** * Set the status to display for the object * * @param string $sCode * @param string $sLabel * @param string $sColor * * @return $this */ public function SetStatus(string $sCode, string $sLabel, string $sColor) { $this->sStatusCode = $sColor; $this->sStatusLabel = $sLabel; $this->sStatusColor = $sColor; return $this; } /** * @see self::$sStatusCode * @return string */ public function GetStatusCode(): string { return $this->sStatusCode; } /** * @see self::$sStatusLabel * @return string */ public function GetStatusLabel(): string { return $this->sStatusLabel; } /** * @see self::$sStatusColor * @return string */ public function GetStatusColor(): string { return $this->sStatusColor; } /** * @inheritDoc */ public function HasSubTitle(): bool { return !empty($this->sStatusCode); } protected function ComputeIconUrl(DBObject $oObject): void { // 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; } } } $this->SetIcon($sIconUrl, $sIconCoverMethod, true); } protected function ComputeState(DBObject $oObject): void { if (MetaModel::HasStateAttributeCode($this->sClassName)) { $this->sStatusCode = $oObject->GetState(); $this->sStatusLabel = $oObject->GetStateLabel(); $this->sStatusColor = UIHelper::GetColorFromStatus($this->sClassName, $this->sStatusCode); } } }