mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°7157 - Migrate enum values from strings to PHP Enum
This commit is contained in:
@@ -53,7 +53,7 @@ abstract class Trigger extends cmdbAbstractObject
|
|||||||
MetaModel::Init_AddAttribute(new AttributeEnumSet("context", array("allowed_values" => null, "possible_values" => new ValueSetEnumPadded($aTags, true), "sql" => "context", "depends_on" => array(), "is_null_allowed" => true, "max_items" => 12)));
|
MetaModel::Init_AddAttribute(new AttributeEnumSet("context", array("allowed_values" => null, "possible_values" => new ValueSetEnumPadded($aTags, true), "sql" => "context", "depends_on" => array(), "is_null_allowed" => true, "max_items" => 12)));
|
||||||
// "complement" is a computed field, fed by Trigger sub-classes, in general in ComputeValues method, for eg. the TriggerOnObject fed it with target_class info
|
// "complement" is a computed field, fed by Trigger sub-classes, in general in ComputeValues method, for eg. the TriggerOnObject fed it with target_class info
|
||||||
MetaModel::Init_AddAttribute(new AttributeString("complement", array("allowed_values" => null, "sql" => "complement", "default_value" => null, "is_null_allowed" => true, "depends_on" => array())));
|
MetaModel::Init_AddAttribute(new AttributeString("complement", array("allowed_values" => null, "sql" => "complement", "default_value" => null, "is_null_allowed" => true, "depends_on" => array())));
|
||||||
MetaModel::Init_AddAttribute(new AttributeEnum("subscription_policy", array("allowed_values" => new ValueSetEnum('allow_no_channel,force_at_least_one_channel,force_all_channels'), "sql" => "subscription_policy", "default_value" => 'allow_no_channel', "is_null_allowed" => false, "depends_on" => array())));
|
MetaModel::Init_AddAttribute(new AttributeEnum("subscription_policy", array("allowed_values" => new ValueSetEnum(implode(",", Combodo\iTop\Core\Trigger\Enum\SubscriptionPolicy::cases())), "sql" => "subscription_policy", "default_value" => \Combodo\iTop\Core\Trigger\Enum\SubscriptionPolicy::AllowNoChannel, "is_null_allowed" => false, "depends_on" => array())));
|
||||||
|
|
||||||
// Display lists
|
// Display lists
|
||||||
MetaModel::Init_SetZListItems('details', array('finalclass', 'description', 'context', 'subscription_policy', 'action_list', 'complement')); // Attributes to be displayed for the complete details
|
MetaModel::Init_SetZListItems('details', array('finalclass', 'description', 'context', 'subscription_policy', 'action_list', 'complement')); // Attributes to be displayed for the complete details
|
||||||
|
|||||||
@@ -417,6 +417,7 @@ return array(
|
|||||||
'Combodo\\iTop\\Core\\Kpi\\KpiLogData' => $baseDir . '/sources/Core/Kpi/KpiLogData.php',
|
'Combodo\\iTop\\Core\\Kpi\\KpiLogData' => $baseDir . '/sources/Core/Kpi/KpiLogData.php',
|
||||||
'Combodo\\iTop\\Core\\MetaModel\\FriendlyNameType' => $baseDir . '/sources/Core/MetaModel/FriendlyNameType.php',
|
'Combodo\\iTop\\Core\\MetaModel\\FriendlyNameType' => $baseDir . '/sources/Core/MetaModel/FriendlyNameType.php',
|
||||||
'Combodo\\iTop\\Core\\MetaModel\\HierarchicalKey' => $baseDir . '/sources/Core/MetaModel/HierarchicalKey.php',
|
'Combodo\\iTop\\Core\\MetaModel\\HierarchicalKey' => $baseDir . '/sources/Core/MetaModel/HierarchicalKey.php',
|
||||||
|
'Combodo\\iTop\\Core\\Trigger\\Enum\\SubscriptionPolicy' => $baseDir . '/sources/Core/Trigger/Enum/SubscriptionPolicy.php',
|
||||||
'Combodo\\iTop\\DesignDocument' => $baseDir . '/core/designdocument.class.inc.php',
|
'Combodo\\iTop\\DesignDocument' => $baseDir . '/core/designdocument.class.inc.php',
|
||||||
'Combodo\\iTop\\DesignElement' => $baseDir . '/core/designdocument.class.inc.php',
|
'Combodo\\iTop\\DesignElement' => $baseDir . '/core/designdocument.class.inc.php',
|
||||||
'Combodo\\iTop\\Form\\Field\\AbstractSimpleField' => $baseDir . '/sources/Form/Field/AbstractSimpleField.php',
|
'Combodo\\iTop\\Form\\Field\\AbstractSimpleField' => $baseDir . '/sources/Form/Field/AbstractSimpleField.php',
|
||||||
|
|||||||
@@ -792,6 +792,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
|
|||||||
'Combodo\\iTop\\Core\\Kpi\\KpiLogData' => __DIR__ . '/../..' . '/sources/Core/Kpi/KpiLogData.php',
|
'Combodo\\iTop\\Core\\Kpi\\KpiLogData' => __DIR__ . '/../..' . '/sources/Core/Kpi/KpiLogData.php',
|
||||||
'Combodo\\iTop\\Core\\MetaModel\\FriendlyNameType' => __DIR__ . '/../..' . '/sources/Core/MetaModel/FriendlyNameType.php',
|
'Combodo\\iTop\\Core\\MetaModel\\FriendlyNameType' => __DIR__ . '/../..' . '/sources/Core/MetaModel/FriendlyNameType.php',
|
||||||
'Combodo\\iTop\\Core\\MetaModel\\HierarchicalKey' => __DIR__ . '/../..' . '/sources/Core/MetaModel/HierarchicalKey.php',
|
'Combodo\\iTop\\Core\\MetaModel\\HierarchicalKey' => __DIR__ . '/../..' . '/sources/Core/MetaModel/HierarchicalKey.php',
|
||||||
|
'Combodo\\iTop\\Core\\Trigger\\Enum\\SubscriptionPolicy' => __DIR__ . '/../..' . '/sources/Core/Trigger/Enum/SubscriptionPolicy.php',
|
||||||
'Combodo\\iTop\\DesignDocument' => __DIR__ . '/../..' . '/core/designdocument.class.inc.php',
|
'Combodo\\iTop\\DesignDocument' => __DIR__ . '/../..' . '/core/designdocument.class.inc.php',
|
||||||
'Combodo\\iTop\\DesignElement' => __DIR__ . '/../..' . '/core/designdocument.class.inc.php',
|
'Combodo\\iTop\\DesignElement' => __DIR__ . '/../..' . '/core/designdocument.class.inc.php',
|
||||||
'Combodo\\iTop\\Form\\Field\\AbstractSimpleField' => __DIR__ . '/../..' . '/sources/Form/Field/AbstractSimpleField.php',
|
'Combodo\\iTop\\Form\\Field\\AbstractSimpleField' => __DIR__ . '/../..' . '/sources/Form/Field/AbstractSimpleField.php',
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use Combodo\iTop\Application\UI\Base\Component\Input\Set\SetUIBlockFactory;
|
|||||||
use Combodo\iTop\Application\UI\Base\Component\Panel\Panel;
|
use Combodo\iTop\Application\UI\Base\Component\Panel\Panel;
|
||||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||||
use Combodo\iTop\Application\WebPage\iTopWebPage;
|
use Combodo\iTop\Application\WebPage\iTopWebPage;
|
||||||
|
use Combodo\iTop\Core\Trigger\Enum\SubscriptionPolicy;
|
||||||
use Combodo\iTop\Renderer\BlockRenderer;
|
use Combodo\iTop\Renderer\BlockRenderer;
|
||||||
use Combodo\iTop\Service\Notification\NotificationsRepository;
|
use Combodo\iTop\Service\Notification\NotificationsRepository;
|
||||||
use Combodo\iTop\Service\Router\Router;
|
use Combodo\iTop\Service\Router\Router;
|
||||||
@@ -82,7 +83,7 @@ class NotificationsCenterController extends Controller
|
|||||||
// Add the action notification to the list of actions notifications for the trigger
|
// Add the action notification to the list of actions notifications for the trigger
|
||||||
$oActionsNotificationsByTrigger[$iTriggerId][] = $oSubscribedActionNotification;
|
$oActionsNotificationsByTrigger[$iTriggerId][] = $oSubscribedActionNotification;
|
||||||
// Add the subscribed status to the list of subscribed actions notifications for the trigger
|
// Add the subscribed status to the list of subscribed actions notifications for the trigger
|
||||||
$aSubscribedActionsNotificationsByTrigger[$iTriggerId][$oSubscribedActionNotification->GetKey()] = $oLnkActionsNotifications->Get('subscribed') || $oTrigger->Get('subscription_policy') === 'force_all_channels';
|
$aSubscribedActionsNotificationsByTrigger[$iTriggerId][$oSubscribedActionNotification->GetKey()] = $oLnkActionsNotifications->Get('subscribed') || $oTrigger->Get('subscription_policy') === SubscriptionPolicy::ForceAllChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build table rows
|
// Build table rows
|
||||||
@@ -155,7 +156,7 @@ class NotificationsCenterController extends Controller
|
|||||||
$oChannelSet->SetOptionsTemplate('application/object/set/option_renderer.html.twig');
|
$oChannelSet->SetOptionsTemplate('application/object/set/option_renderer.html.twig');
|
||||||
$oChannelSet->SetItemsTemplate('application/preferences/notification-center/item_renderer.html.twig');
|
$oChannelSet->SetItemsTemplate('application/preferences/notification-center/item_renderer.html.twig');
|
||||||
// Disable the input set if the subscription policy is 'force_all_channels'
|
// Disable the input set if the subscription policy is 'force_all_channels'
|
||||||
if($sTriggerSubscriptionPolicy === 'force_all_channels'){
|
if ($sTriggerSubscriptionPolicy === SubscriptionPolicy::ForceAllChannels) {
|
||||||
$oChannelSet->SetIsDisabled(true);
|
$oChannelSet->SetIsDisabled(true);
|
||||||
}
|
}
|
||||||
// Add a CSRF Token
|
// Add a CSRF Token
|
||||||
@@ -190,8 +191,8 @@ $.ajax({
|
|||||||
});
|
});
|
||||||
JS
|
JS
|
||||||
);
|
);
|
||||||
// Set the minimum number of channels to 1 if the subscription policy is 'force_at_least_one_channel'
|
// Set the minimum number of channels to 1 if the subscription policy is {@see SubscriptionPolicy::ForceAtLeastOneChannel}
|
||||||
if($sTriggerSubscriptionPolicy === 'force_at_least_one_channel')
|
if($sTriggerSubscriptionPolicy === SubscriptionPolicy::ForceAtLeastOneChannel)
|
||||||
{
|
{
|
||||||
$oChannelSet->SetMinItems(1);
|
$oChannelSet->SetMinItems(1);
|
||||||
}
|
}
|
||||||
@@ -289,7 +290,7 @@ JS
|
|||||||
// Add the action notification to the list of actions notifications for the trigger
|
// Add the action notification to the list of actions notifications for the trigger
|
||||||
$oActionsNotificationsByTrigger[$iTriggerId][] = $oSubscribedActionNotification;
|
$oActionsNotificationsByTrigger[$iTriggerId][] = $oSubscribedActionNotification;
|
||||||
// Add the subscribed status to the list of subscribed actions notifications for the trigger
|
// Add the subscribed status to the list of subscribed actions notifications for the trigger
|
||||||
$aSubscribedActionsNotificationsByTrigger[$iTriggerId][$oSubscribedActionNotification->GetKey()] = $oLnkActionsNotifications->Get('subscribed') || $oTrigger->Get('subscription_policy') === 'force_all_channels';
|
$aSubscribedActionsNotificationsByTrigger[$iTriggerId][$oSubscribedActionNotification->GetKey()] = $oLnkActionsNotifications->Get('subscribed') || $oTrigger->Get('subscription_policy') === SubscriptionPolicy::ForceAllChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
$oPage->AddTabContainer('NotificationsCenter', '', $oNotificationsPanel);
|
$oPage->AddTabContainer('NotificationsCenter', '', $oNotificationsPanel);
|
||||||
@@ -491,7 +492,7 @@ JS
|
|||||||
throw new \Exception('Invalid trigger');
|
throw new \Exception('Invalid trigger');
|
||||||
}
|
}
|
||||||
// Check the trigger subscription policy
|
// Check the trigger subscription policy
|
||||||
if($oTrigger->Get('subscription_policy') === 'force_all_channels'){
|
if ($oTrigger->Get('subscription_policy') === SubscriptionPolicy::ForceAllChannels) {
|
||||||
throw new \Exception('You are not allowed to unsubscribe from this channel');
|
throw new \Exception('You are not allowed to unsubscribe from this channel');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,7 +502,7 @@ JS
|
|||||||
throw new \Exception('You are not subscribed to any channel');
|
throw new \Exception('You are not subscribed to any channel');
|
||||||
}
|
}
|
||||||
// Check the trigger subscription policy and if we are subscribed to at least 1 channel if necessary
|
// Check the trigger subscription policy and if we are subscribed to at least 1 channel if necessary
|
||||||
if($oTrigger->Get('subscription_policy') === 'force_at_least_one_channel') {
|
if($oTrigger->Get('subscription_policy') === SubscriptionPolicy::ForceAtLeastOneChannel) {
|
||||||
$oTotalSubscribedActionsNotificationsSet = NotificationsRepository::GetInstance()->SearchSubscriptionByTriggerContactAndSubscription($iTriggerId, \UserRights::GetContactId(), '1');
|
$oTotalSubscribedActionsNotificationsSet = NotificationsRepository::GetInstance()->SearchSubscriptionByTriggerContactAndSubscription($iTriggerId, \UserRights::GetContactId(), '1');
|
||||||
if (($oTotalSubscribedActionsNotificationsSet->Count() - $oSubscribedActionsNotificationsSet->Count()) === 0) {
|
if (($oTotalSubscribedActionsNotificationsSet->Count() - $oSubscribedActionsNotificationsSet->Count()) === 0) {
|
||||||
throw new \Exception('You can\'t unsubscribe from this channel, you must be subscribed to at least one channel');
|
throw new \Exception('You can\'t unsubscribe from this channel, you must be subscribed to at least one channel');
|
||||||
|
|||||||
16
sources/Core/Trigger/Enum/SubscriptionPolicy.php
Normal file
16
sources/Core/Trigger/Enum/SubscriptionPolicy.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Combodo\iTop\Core\Trigger\Enum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class SubscriptionPolicy
|
||||||
|
*
|
||||||
|
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||||
|
* @package Combodo\iTop\Core\Trigger\Enum
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
enum SubscriptionPolicy: string {
|
||||||
|
case AllowNoChannel = "allow_no_channel";
|
||||||
|
case ForceAtLeastOneChannel = "force_at_least_one_channel";
|
||||||
|
case ForceAllChannels = "force_all_channels";
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ namespace Combodo\iTop\Service\Notification;
|
|||||||
|
|
||||||
|
|
||||||
use ActionNotification;
|
use ActionNotification;
|
||||||
|
use Combodo\iTop\Core\Trigger\Enum\SubscriptionPolicy;
|
||||||
use Contact;
|
use Contact;
|
||||||
use lnkActionNotificationToContact;
|
use lnkActionNotificationToContact;
|
||||||
use Trigger;
|
use Trigger;
|
||||||
@@ -99,7 +100,7 @@ class NotificationsService {
|
|||||||
public function IsSubscribed(Trigger $oTrigger, ActionNotification $oActionNotification, Contact $oRecipient): bool
|
public function IsSubscribed(Trigger $oTrigger, ActionNotification $oActionNotification, Contact $oRecipient): bool
|
||||||
{
|
{
|
||||||
// Check if the trigger subscription policy is 'force_all_channels'
|
// Check if the trigger subscription policy is 'force_all_channels'
|
||||||
if ($oTrigger->Get('subscription_policy') === 'force_all_channels') {
|
if ($oTrigger->Get('subscription_policy') === SubscriptionPolicy::ForceAllChannels) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Check if the user is already subscribed to the action notification
|
// Check if the user is already subscribed to the action notification
|
||||||
|
|||||||
Reference in New Issue
Block a user