From da32362ef6c831cc6c4eec8defdf11d65a16a1b5 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Tue, 12 Mar 2024 09:12:02 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B07157=20-=20Remove=20advanced=20mode=20in?= =?UTF-8?q?=20notifications=20center?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotificationsCenterController.php | 202 ------------------ 1 file changed, 202 deletions(-) diff --git a/sources/Controller/Notifications/NotificationsCenterController.php b/sources/Controller/Notifications/NotificationsCenterController.php index f058dbf53..4636bad32 100644 --- a/sources/Controller/Notifications/NotificationsCenterController.php +++ b/sources/Controller/Notifications/NotificationsCenterController.php @@ -59,9 +59,6 @@ class NotificationsCenterController extends Controller $oNotificationsPanel = new Panel(Dict::S('UI:NotificationsCenter:Panel:Title'), array(), 'grey', 'ibo-notifications-center'); $oNotificationsPanel->AddCSSClass('ibo-datatable-panel'); $oSubtitleBlock = new UIContentBlock(null, ['ibo-notifications-center--sub-title']); - $sDisplayAdvancedPageUrl = Router::GetInstance()->GenerateUrl(self::ROUTE_NAMESPACE.'.display_advanced_page', [], true); - $oSubtitleBlock->AddSubBlock(new Html(Dict::Format('UI:NotificationsCenter:Panel:SubTitle', $sDisplayAdvancedPageUrl))); - $oNotificationsPanel->SetSubTitleBlock($oSubtitleBlock); $oNotificationsCenterTableColumns = [ 'trigger' => array('label' => MetaModel::GetName('Trigger')), 'trigger_class' => array('label' => MetaModel::GetAttributeDef('Trigger', 'finalclass')->GetLabel()), @@ -267,205 +264,6 @@ JS return $oPage; } - - public function OperationDisplayAdvancedPage(){ - $oPage = new iTopWebPage(Dict::S('UI:NotificationsCenter:Page:Title')); - // Create a panel that will contain the table - $oNotificationsPanel = new Panel(Dict::S('UI:NotificationsCenter:Panel:Title'), array(), 'grey', 'ibo-notifications-center'); - $oSubtitleBlock = new UIContentBlock(null, ['ibo-notifications-center--sub-title']); - $sDisplayAdvancedPageUrl = Router::GetInstance()->GenerateUrl(self::ROUTE_NAMESPACE.'.display_page', [], true); - $oSubtitleBlock->AddSubBlock(new Html(Dict::Format('UI:NotificationsCenter:Panel:Advanced:SubTitle', $sDisplayAdvancedPageUrl))); - $oNotificationsPanel->SetSubTitleBlock($oSubtitleBlock); - $oPage->AddUiBlock($oNotificationsPanel); - - // Get all subscribed/unsubscribed actions notifications for the current user - $oLnkNotificationsSet = NotificationsRepository::GetInstance()->SearchSubscriptionsByContact(\UserRights::GetContactId()); - $oActionsNotificationsByTrigger = []; - $aSubscribedActionsNotificationsByTrigger = []; - while ($oLnkActionsNotifications = $oLnkNotificationsSet->Fetch()) { - $oSubscribedActionNotification = MetaModel::GetObject(ActionNotification::class, $oLnkActionsNotifications->Get('action_id')); - $oTrigger = MetaModel::GetObject('Trigger', $oLnkActionsNotifications->Get('trigger_id')); - $iTriggerId = $oTrigger->GetKey(); - // Create a new array for the trigger if it doesn't exist - if (!isset($oActionsNotificationsByTrigger[$iTriggerId])) { - $oActionsNotificationsByTrigger[$iTriggerId] = []; - $aSubscribedActionsNotificationsByTrigger[$iTriggerId] = []; - } - // Add the action notification to the list of actions notifications for the trigger - $oActionsNotificationsByTrigger[$iTriggerId][] = $oSubscribedActionNotification; - // 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') === SubscriptionPolicy::ForceAllChannels->value; - } - - $oPage->AddTabContainer('NotificationsCenter', '', $oNotificationsPanel); - $oPage->SetCurrentTabContainer('NotificationsCenter'); - // Create a new tab for each trigger - foreach ($oActionsNotificationsByTrigger as $iTriggerId => $aActionsNotifications) { - $oTrigger = MetaModel::GetObject('Trigger', $iTriggerId, false); - if ($oTrigger === null) { - continue; - } - foreach ($aActionsNotifications as $oActionNotification) { - $oPage->SetCurrentTab(MetaModel::GetName(get_class($oActionNotification))); - $oCheckBox = InputUIBlockFactory::MakeForInputWithLabel( - Dict::Format('UI:NotificationsCenter:Advanced:Input:Label', $oTrigger->Get('description'), $oActionNotification->Get('name')), - $oTrigger->GetKey().'|'.$oActionNotification->GetKey(), - "", - $oTrigger->GetKey().'|'.$oActionNotification->GetKey(), - "checkbox" - ); - $oCheckBox->GetInput()->SetIsChecked($aSubscribedActionsNotificationsByTrigger[$iTriggerId][$oActionNotification->GetKey()] === true); - $oCheckBox->SetBeforeInput(false); - $oCheckBox->GetInput()->AddCSSClass('ibo-input--label-right'); - $oCheckBox->GetInput()->AddCSSClass('ibo-input-checkbox'); - $oContainer = new UIContentBlock(null, ['ibo-notifications-center-advanced--input--container']); - $oContainer->AddSubBlock($oCheckBox); - $oPage->AddUiBlock($oContainer); - } - } - $sSubscribeUrl = Router::GetInstance()->GenerateUrl(self::ROUTE_NAMESPACE.'.subscribe', [], true); - $sUnsubscribeUrl = Router::GetInstance()->GenerateUrl(self::ROUTE_NAMESPACE.'.unsubscribe', [], true); - $sCSRFToken = utils::GetNewTransactionId(); - $oPage->add_ready_script( -<<CheckPostedCSRF()) { - throw new \Exception('Invalid token'); - } - - $sChannel = utils::ReadParam('channel', '', true, 'raw_data'); - $aChannel = explode('|', $sChannel); - $oPage = new \JsonPage(); - $aReturnData = []; - try { - if (count($aChannel) !== 2) { - throw new \Exception('Invalid channel'); - } - $iTriggerKey = $aChannel[0]; - $iActionNotificationKey = $aChannel[1]; - $oTrigger = MetaModel::GetObject('Trigger', $iTriggerKey, false); - if ($oTrigger === null) { - throw new \Exception('Invalid trigger'); - } - $oActionNotification = MetaModel::GetObject('ActionNotification', $iActionNotificationKey, false); - if ($oActionNotification === null) { - throw new \Exception('Invalid action notification'); - } - $oSubscribedActionsNotificationsSet = NotificationsRepository::GetInstance()->SearchSubscribedSubscriptionsByTriggerContactAndAction($iTriggerKey, $iActionNotificationKey); - if ($oSubscribedActionsNotificationsSet->Count() === 0) { - throw new \Exception('You are not subscribed to this channel'); - } - while ($oSubscribedActionsNotifications = $oSubscribedActionsNotificationsSet->Fetch()) { - $oSubscribedActionsNotifications->Set('subscribed', false); - $oSubscribedActionsNotifications->DBUpdate(); - } - $aReturnData = [ - 'status' => 'success', - 'message' => Dict::S('UI:NotificationsCenter:Unsubscribe:Success'), - ]; - } - catch (Exception $e) { - $aReturnData = [ - 'status' => 'error', - 'message' => $e->getMessage(), - ]; - } - $oPage->SetData($aReturnData); - $oPage->SetOutputDataOnly(true); - - return $oPage; - } - - function OperationSubscribe() - { - - // Get the CSRF token from the request and check if it's valid - if (!$this->CheckPostedCSRF()) { - throw new \Exception('Invalid token'); - } - - $sChannel = utils::ReadParam('channel', '', true, 'raw_data'); - $aChannel = explode('|', $sChannel); - - $oPage = new \JsonPage(); - $aReturnData = []; - try { - if (count($aChannel) !== 2) { - throw new \Exception('Invalid channel'); - } - $iTriggerKey = $aChannel[0]; - $iActionNotificationKey = $aChannel[1]; - $oTrigger = MetaModel::GetObject('Trigger', $iTriggerKey, false); - if ($oTrigger === null) { - throw new \Exception('Invalid trigger'); - } - $oActionNotification = MetaModel::GetObject('ActionNotification', $iActionNotificationKey, false); - if ($oActionNotification === null) { - throw new \Exception('Invalid action notification'); - } - $oSubscribedActionsNotificationsSet = NotificationsRepository::GetInstance()->SearchUnsubscribedSubscriptionsByTriggerContactAndAction($iTriggerKey, $iActionNotificationKey); - if ($oSubscribedActionsNotificationsSet->Count() === 0) { - throw new \Exception('You are not allow to subscribe to this channel'); - } - while ($oSubscribedActionsNotifications = $oSubscribedActionsNotificationsSet->Fetch()) { - $oSubscribedActionsNotifications->Set('subscribed', true); - $oSubscribedActionsNotifications->DBUpdate(); - } - $aReturnData = [ - 'status' => 'success', - 'message' => Dict::S('UI:NotificationsCenter:Subscribe:Success'), - ]; - } - catch (Exception $e) { - $aReturnData = [ - 'status' => 'error', - 'message' => $e->getMessage(), - ]; - } - $oPage->SetData($aReturnData); - $oPage->SetOutputDataOnly(true); - - return $oPage; - } /** * @return \JsonPage