Просмотр исходного кода

Ticket #5218 - Notifications: Notify admins/moderators about new report(s).

AntonLV 1 год назад
Родитель
Сommit
0ee1f1fb47

+ 3 - 0
inc/classes/BxDolRequest.php

@@ -170,6 +170,9 @@ class BxDolRequest extends BxDol
         if (!$aModule)
             return false;
 
+        if (isset($aModule['name']) && 'system' == $aModule['name'] && 'Module' == $sClass)
+            $sClass = 'BaseServices';
+
         $sClass = $aModule['class_prefix'] . $sClass;
         if(($oModule = BxDolRequest::_require($aModule, $sClass)) === false)
             return false;

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

@@ -147,7 +147,9 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('sys_cmts_reactions', 'undoVote', @iHandler),
 
 ('sys_cmts', 'doVoteUp', @iHandler),
-('sys_cmts', 'doVoteDown', @iHandler);
+('sys_cmts', 'doVoteDown', @iHandler),
+
+('sys_cmts', 'reported_content', @iHandler);
 
 
 -- EMAIL TEMPLATES

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

@@ -201,6 +201,16 @@ INSERT INTO `bx_notifications_settings`(`group`, `handler_id`, `delivery`, `type
 ('score_down', @iHandlerId, 'email', 'follow_context', '_bx_ntfs_alert_action_doVoteDown_follow_context', 4),
 ('score_down', @iHandlerId, 'push', 'follow_context', '_bx_ntfs_alert_action_doVoteDown_follow_context', 4);
 
+INSERT INTO `bx_notifications_handlers`(`group`, `type`, `alert_unit`, `alert_action`, `content`, `privacy`) VALUES 
+('sys_cmts_object_reported', 'insert', 'sys_cmts', 'reported_content', 'a:3:{s:11:"module_name";s:6:"system";s:13:"module_method";s:34:"get_notifications_comment_reported";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
+('action_required', @iHandlerId, 'site', 'personal', '_bx_ntfs_alert_action_reported_content_personal', 8),
+('action_required', @iHandlerId, 'email', 'personal', '_bx_ntfs_alert_action_reported_content_personal', 8),
+('action_required', @iHandlerId, 'push', 'personal', '_bx_ntfs_alert_action_reported_content_personal', 8);
+
+
 CREATE TABLE IF NOT EXISTS `bx_notifications_queue` (
   `id` int(11) NOT NULL auto_increment,
   `profile_id` int(11) NOT NULL DEFAULT '0',

+ 35 - 0
template/scripts/BxBaseCmtsServices.php

@@ -425,6 +425,41 @@ class BxBaseCmtsServices extends BxDol
         ];
     }
 
+    public function serviceGetNotificationsCommentReported($aEvent)
+    {
+        $iCmtIdUnique = (int)$aEvent['object_id'];
+
+        $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
+        if(empty($aCmtInfo) || !is_array($aCmtInfo))
+            return [];
+
+        $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
+        if(!$oCmts || !$oCmts->isEnabled())
+            return [];
+
+        $iCmtId = (int)$aCmtInfo['cmt_id'];
+        $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
+        $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
+
+        $sCmtUrlApi = '';
+        if(bx_is_api() && getParam('sys_api_comment_notif_link_content') == 'on') {
+            $aCmt = $oCmts->getCommentsBy(['type' => 'uniq_id', 'uniq_id' => $iCmtIdUnique]);
+            if(!empty($aCmt) && is_array($aCmt)) {
+                $oCmts->init($aCmt['cmt_object_id']);
+
+                $sCmtUrlApi = $oCmts->getBaseUrl('{bx_url_root}') . '#cid=' . $iCmtId;
+            }
+        }
+
+        return [
+            'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
+            'entry_url' => $sCmtUrl,
+            'entry_url_api' => $sCmtUrlApi,
+            'entry_caption' => $sCmtCaption,
+            '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
      */

+ 1 - 1
template/scripts/BxBaseReport.php

@@ -459,7 +459,7 @@ class BxBaseReport extends BxDolReport
                          *      - `report_text` - [string] message attached to report
                          * @hook @ref hook-bx_base_general-reported_content
                          */
-                        bx_alert($sModule, 'reported_content', $iObjectId, $iAuthorId, [
+                        bx_alert($this->_sSystem, 'reported_content', $iObjectId, $iAuthorId, [
                             'object_author_id' => (int)$iModeratorId,
 
                             'report_id' => $iId,

+ 16 - 0
template/scripts/BxBaseServices.php

@@ -935,6 +935,22 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
         return false;
     }
 
+    public function serviceGetModerators($iContentId)
+    {
+        $aModerators = BxDolAclQuery::getInstance()->getProfilesByMembership([
+            MEMBERSHIP_ID_MODERATOR, 
+            MEMBERSHIP_ID_ADMINISTRATOR
+        ]);
+
+        $aIds = [];
+        array_walk($aModerators, function ($aItem, $iKey, $aParams) {
+            if(!empty($aItem['id']))
+                $aParams[0][] = (int)$aItem['id'];
+        }, [&$aIds]);
+
+        return $aIds;
+    }
+
     public function servicePrepareFields ($aFieldsProfile)
     {
         return $aFieldsProfile;