From e9bd76f2cdacfa4609ac047440659c27e00c1fae Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 22 Feb 2024 15:28:16 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B02039=20-=20Choose=20news=20icon=20depend?= =?UTF-8?q?ing=20on=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Icon from action if defined > Icon from source object class > Icon from branding (compact) --- core/datamodel.core.xml | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/core/datamodel.core.xml b/core/datamodel.core.xml index fab9c2572..f574095f6 100644 --- a/core/datamodel.core.xml +++ b/core/datamodel.core.xml @@ -253,7 +253,7 @@ false public Get('recipients')); $oRecipientsSearch->AllowAllData(); @@ -262,15 +262,36 @@ while ($oRecipient = $oRecipientsSet->Fetch()) { // Skip recipients that have no users if (get_class($oRecipient) === Person::class && UserRights::GetUserFromPerson($oRecipient) === null) { - continue; - } + continue; + } if (!\Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->IsSubscribed($oTrigger, $this, $oRecipient)) { - continue; - } + continue; + } + + if (array_key_exists('this->object()', $aContextArgs)) { + $iObjectId = $aContextArgs['this->object()']->GetKey(); + $sObjectClass = get_class($aContextArgs['this->object()']); + } else { + $iObjectId = 0; + $sObjectClass = null; + } + $oEvent = new EventiTopNotification(); $oEvent->Set('title', MetaModel::ApplyParams($this->Get('title'), $aContextArgs)); $oEvent->Set('message', MetaModel::ApplyParams($this->Get('message'), $aContextArgs)); - $oIcon = !$this->Get('icon')->IsEmpty() ? $this->Get('icon') : MetaModel::GetAttributeDef('EventiTopNotification', 'icon')->MakeRealValue(Combodo\iTop\Application\Branding::GetCompactMainLogoAbsoluteUrl(), $oEvent); + // Compute icon + // - First check if one is defined on the action + if (false === $this->Get('icon')->IsEmpty()) { + $oIcon = $this->Get('icon'); + } + // - Then, check if the action is for a DM object and if its class has an icon + elseif ($iObjectId > 0 && utils::IsNotNullOrEmptyString(MetaModel::GetClassIcon($sObjectClass, false))) { + $oIcon = MetaModel::GetAttributeDef(EventiTopNotification::class, 'icon')->MakeRealValue(MetaModel::GetClassIcon($sObjectClass, false), $oEvent); + } + // - Otherwise, fallback on the compact logo of the application + else { + $oIcon = MetaModel::GetAttributeDef(EventiTopNotification::class, 'icon')->MakeRealValue(\Combodo\iTop\Application\Branding::GetCompactMainLogoAbsoluteUrl(), $oEvent); + } $oEvent->Set('icon', $oIcon); $oEvent->Set('priority', $this->Get('priority')); $oEvent->Set('contact_id', $oRecipient->GetKey()); @@ -281,7 +302,7 @@ $oEvent->Set('url', MetaModel::ApplyParams($this->Get('url'), $aContextArgs)); $oEvent->DBInsertNoReload(); - \Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->RegisterSubscription($oTrigger, $this, $oRecipient); + \Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->RegisterSubscription($oTrigger, $this, $oRecipient); } $this->SetNotificationLanguage($sPreviousLanguage, $aPreviousPluginProperties['language_code'] ?? null); }