Przeglądaj źródła

Ticket #3985 - Anyone comments on a post that you have commented on.

AntonLV 4 lat temu
rodzic
commit
88958f3bf6

+ 1 - 0
modules/boonex/notifications/classes/BxNtfsConfig.php

@@ -45,6 +45,7 @@ class BxNtfsConfig extends BxBaseModNotificationsConfig
 
             // some params
             'PARAM_QUEUE_ADD_THRESHOLD' => 0,
+            'PARAM_COMMENT_POST_EXT' => 'bx_notifications_enable_comment_post_ext',
 
             // objects
             'OBJECT_MENU_SUBMENU' => 'bx_notifications_submenu', // main module submenu

+ 48 - 2
modules/boonex/notifications/classes/BxNtfsResponse.php

@@ -95,7 +95,7 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
 
         if($iObjectPrivacyView < 0)
             $iOwnerId = abs($iObjectPrivacyView);
-        
+
         $mixedSubobjectId = $this->_getSubObjectId($oAlert->aExtras);
         if(!is_array($mixedSubobjectId))
             $mixedSubobjectId = array($mixedSubobjectId);
@@ -150,7 +150,53 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
         );
     }
 
-	/**
+    /*
+     * Custom insert data getter for comment -> added and deleted alerts. 
+     */
+    protected function getInsertDataCommentAdded(&$oAlert, &$aHandler)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if(getParam($CNF['PARAM_COMMENT_POST_EXT']) != 'on')
+            return [];
+
+        $oCmts = BxDolCmts::getObjectInstance($oAlert->aExtras['object_system'], $oAlert->aExtras['object_id']);
+        if(!$oCmts)
+            return [];
+
+        $iOwnerId = $oAlert->iSender;
+        $iObjectId = $oAlert->aExtras['object_id'];
+        $iObjectOwnerId = $this->_getObjectOwnerId($oAlert->aExtras);
+        $iObjectPrivacyView = $this->_getObjectPrivacyView($oAlert->aExtras);
+
+        $aResults = $aRecipients = [];        
+
+        $aComments = $oCmts->getCommentsBy(['type' => 'object_id', 'object_id' => $iObjectId]);
+        foreach($aComments as $aComment) {
+            $iCmtAuthorId = (int)$aComment['cmt_author_id'];
+            if(in_array($iCmtAuthorId, $aRecipients) || $iCmtAuthorId == $iOwnerId || $iCmtAuthorId == $iObjectOwnerId)
+                continue;
+
+            $aResults[] = [
+                'owner_id' => $iOwnerId,
+                'type' => $oAlert->sUnit,
+                'action' => $oAlert->sAction,
+                'object_id' => $iObjectId,
+                'object_owner_id' => $iCmtAuthorId,
+                'object_privacy_view' => $iObjectPrivacyView,
+                'subobject_id' => $oAlert->aExtras['comment_uniq_id'],
+                'content' => $this->_getContent($oAlert->aExtras),
+                'allow_view_event_to' => $this->_oModule->_oConfig->getPrivacyViewDefault('event'),
+                'processed' => 0
+            ];
+
+            $aRecipients[] = $iCmtAuthorId;
+        }
+
+        return $aResults;
+    }
+
+    /**
      * Custom insert data getter for sys_profiles_friends -> connection_added and connection_removed alerts. 
      */
     protected function getInsertDataSysProfilesFriendsConnectionAdded(&$oAlert, &$aHandler)

+ 1 - 0
modules/boonex/notifications/install/langs/en.xml

@@ -46,6 +46,7 @@
     <string name="_bx_ntfs_option_delivery_timeout"><![CDATA[Delay before sending Email and/or Push notifications (in seconds)]]></string>
     <string name="_bx_ntfs_option_processed_event"><![CDATA[The last processed event upon notifications sending]]></string>
     <string name="_bx_ntfs_option_clear_interval"><![CDATA[Notification lifetime, in days (0 - no limit)]]></string>
+    <string name="_bx_ntfs_option_enable_comment_post_ext"><![CDATA[Notify a user about new comments for a content he's previously commented]]></string>
 
     <string name="_bx_ntfs_privacy_view"><![CDATA[View event]]></string>
 

+ 4 - 1
modules/boonex/notifications/install/sql/enable.sql

@@ -93,7 +93,8 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_notifications_events_per_preview', '5', @iCategId, '_bx_ntfs_option_events_per_preview', 'digit', '', '', '', '', 5),
 ('bx_notifications_enable_group_settings', 'on', @iCategId, '_bx_ntfs_option_enable_group_settings', 'checkbox', '', '', '', '', 10), 
 ('bx_notifications_delivery_timeout', '120', @iCategId, '_bx_ntfs_option_delivery_timeout', 'digit', '', '', '', '', 20),
-('bx_notifications_clear_interval', '0', @iCategId, '_bx_ntfs_option_clear_interval', 'digit', '', '', '', '', 30);
+('bx_notifications_clear_interval', '0', @iCategId, '_bx_ntfs_option_clear_interval', 'digit', '', '', '', '', 30),
+('bx_notifications_enable_comment_post_ext', '', @iCategId, '_bx_ntfs_option_enable_comment_post_ext', 'checkbox', '', '', '', '', 40);
 
 
 -- PRIVACY 
@@ -115,6 +116,8 @@ SET @iHandler := LAST_INSERT_ID();
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('profile', 'delete', @iHandler),
 
+('comment', 'added', @iHandler),
+
 ('meta_mention', 'added', @iHandler),
 
 ('sys_profiles_friends', 'connection_added', @iHandler),

+ 13 - 0
modules/boonex/notifications/install/sql/install.sql

@@ -102,6 +102,19 @@ INSERT INTO `bx_notifications_settings`(`group`, `handler_id`, `delivery`, `type
 INSERT INTO `bx_notifications_handlers`(`group`, `type`, `alert_unit`, `alert_action`, `content`) VALUES 
 ('subscription', 'delete', 'sys_profiles_subscriptions', 'connection_removed', '');
 
+-- Comments
+INSERT INTO `bx_notifications_handlers`(`group`, `type`, `alert_unit`, `alert_action`, `content`) VALUES 
+('comment', 'insert', 'comment', 'added', 'a:3:{s:11:"module_name";s:6:"system";s:13:"module_method";s:31:"get_notifications_comment_added";s:12:"module_class";s:17:"TemplCmtsServices";}');
+SET @iHandlerId = LAST_INSERT_ID();
+
+INSERT INTO `bx_notifications_settings`(`group`, `handler_id`, `delivery`, `type`, `title`, `order`) VALUES
+('comment', @iHandlerId, 'site', 'personal', '_bx_ntfs_alert_action_comment_added_personal', 1),
+('comment', @iHandlerId, 'email', 'personal', '_bx_ntfs_alert_action_comment_added_personal', 1),
+('comment', @iHandlerId, 'push', 'personal', '_bx_ntfs_alert_action_comment_added_personal', 1);
+
+INSERT INTO `bx_notifications_handlers`(`group`, `type`, `alert_unit`, `alert_action`, `content`) VALUES 
+('comment', 'delete', 'comment', 'deleted', '');
+
 -- Comments Actions (Like, Reaction, Score Up\Down)
 INSERT INTO `bx_notifications_handlers`(`group`, `type`, `alert_unit`, `alert_action`, `content`, `privacy`) VALUES 
 ('sys_cmts_vote', 'insert', 'sys_cmts', 'doVote', 'a:3:{s:11:"module_name";s:6:"system";s:13:"module_method";s:22:"get_notifications_vote";s:12:"module_class";s:17:"TemplCmtsServices";}', '');

+ 1 - 0
modules/boonex/russian/data/langs/bx_notifications/ru.xml

@@ -46,6 +46,7 @@
     <string name="_bx_ntfs_option_delivery_timeout"><![CDATA[Задержка перед отправкой Email и/или Push уведомлений (в секундах)]]></string>
     <string name="_bx_ntfs_option_clear_interval"><![CDATA[Срок жизни уведомления, в днях (0 - без ограничений)]]></string>
     <string name="_bx_ntfs_option_processed_event"><![CDATA[Последнее событие, обработанное в процессе отправки оповещений]]></string>
+    <string name="_bx_ntfs_option_enable_comment_post_ext"><![CDATA[Оповещать пользователя о новых комментариях к контенту, котороый он комментировал ранее]]></string>
 
     <string name="_bx_ntfs_privacy_view"><![CDATA[Просматривать события]]></string>
 

+ 43 - 0
template/scripts/BxBaseCmtsServices.php

@@ -242,6 +242,49 @@ class BxBaseCmtsServices extends BxDol
         );
     }
 
+    /**
+     * Comment added for Notifications module
+     */
+    public function serviceGetNotificationsCommentAdded($aEvent)
+    {
+        $aCommentGi = BxDolCmts::getGlobalInfo($aEvent['subobject_id']);
+        if(empty($aCommentGi) || !is_array($aCommentGi))
+            return [];
+
+        $iContentId = (int)$aEvent['object_id'];
+
+        $oComment = BxDolCmts::getObjectInstance($aCommentGi['system_name'], $iContentId);
+        if(!$oComment)
+            return [];
+
+        $aCommentSystem = $oComment->getSystemInfo();
+        
+        $oContentModule = BxDolModule::getInstance($aCommentSystem['module']);
+        if(!$oContentModule)
+            return [];
+
+        $aContentInfo = $oContentModule->_oDb->getContentInfoById($iContentId);
+        if(empty($aContentInfo) || !is_array($aContentInfo))
+            return [];
+
+        $CNF = &$oContentModule->_oConfig->CNF;
+        if(empty($CNF['FIELD_ID']) || empty($CNF['FIELD_AUTHOR']) || !(isset($CNF['FIELD_TITLE']) || isset($CNF['FIELD_TEXT'])) || empty($CNF['URI_VIEW_ENTRY']))
+            return [];
+
+        $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
+        $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
+
+        return array(
+            'entry_sample' => $CNF['T']['txt_sample_single'],
+            'entry_url' => $sEntryUrl,
+            'entry_caption' => $sEntryCaption,
+            'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
+            'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
+            'subentry_url' => $oComment->getViewUrl((int)$aCommentGi['cmt_id']),
+            'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
+        );
+    }
+
     /**
      * Comment vote for Notifications module
      */