Răsfoiți Sursa

#287 Convos: email notifications

Alex Trofimov 10 ani în urmă
părinte
comite
41fbf25fe5

+ 1 - 1
modules/boonex/convos/classes/BxCnvAlertsResponse.php

@@ -20,7 +20,7 @@ class BxCnvAlertsResponse extends BxBaseModTextAlertsResponse
     public function response($oAlert)
     {
         if ($this->MODULE == $oAlert->sUnit && 'commentPost' == $oAlert->sAction)
-            BxDolService::call($this->MODULE, 'trigger_comment_post', array($oAlert->iObject, $oAlert->aExtras['comment_author_id'], $oAlert->aExtras['comment_id']));
+            BxDolService::call($this->MODULE, 'trigger_comment_post', array($oAlert->iObject, $oAlert->aExtras['comment_author_id'], $oAlert->aExtras['comment_id'], 0, $oAlert->aExtras['comment_text']));
 
         parent::response($oAlert);
     }

+ 24 - 0
modules/boonex/convos/classes/BxCnvFormsEntryHelper.php

@@ -34,6 +34,30 @@ class BxCnvFormsEntryHelper extends BxBaseModTextFormsEntryHelper
 
         return '';
     }
+
+    public function onDataAddAfter ($iAccountId, $iContentId)
+    {
+        if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
+            return $s;
+
+        if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
+            return MsgBox(_t('_sys_txt_error_occured'));
+
+        // send notification to all collaborators
+        $oProfile = BxDolProfile::getInstance($aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_AUTHOR']]);
+        $aCollaborators = $this->_oModule->_oDb->getCollaborators($aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ID']]);
+        foreach ($aCollaborators as $iCollaborator => $iReadComments) {
+            if ($iCollaborator == $oProfile->id())
+                continue;
+            sendMailTemplate('bx_cnv_new_message', 0, $iCollaborator, array(
+                'SenderDisplayName' => $oProfile->getDisplayName(),
+                'SenderUrl' => $oProfile->getUrl(),
+                'Message' => $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_TEXT']],
+            ), BX_EMAIL_NOTIFY);
+        }
+            
+        return '';
+    }
 }
 
 /** @} */

+ 19 - 2
modules/boonex/convos/classes/BxCnvModule.php

@@ -236,7 +236,7 @@ class BxCnvModule extends BxBaseModTextModule
     /**
      * Update last comment time and author
      */
-    public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iCommentId, $iTimestamp = 0)
+    public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iCommentId, $iTimestamp = 0, $sCommentText = '')
     {
         if (!(int)$iContentId)
             return false;
@@ -250,7 +250,24 @@ class BxCnvModule extends BxBaseModTextModule
         if ($iProfileId == bx_get_logged_profile_id())
             $this->_oDb->updateReadComments($iProfileId, $aContentInfo[$this->_oConfig->CNF['FIELD_ID']], $aContentInfo[$this->_oConfig->CNF['FIELD_COMMENTS']]);
 
-        return $this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, (int)$iCommentId, $iTimestamp);
+        if (!$this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, (int)$iCommentId, $iTimestamp))
+            return false;
+
+        // send notification to all collaborators
+        if ($oProfile = BxDolProfile::getInstance($iProfileId)) {
+            $aCollaborators = $this->_oDb->getCollaborators($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]);
+            foreach ($aCollaborators as $iCollaborator => $iReadComments) {
+                if ($iCollaborator == $iProfileId)
+                    continue;
+                sendMailTemplate('bx_cnv_new_reply', 0, $iCollaborator, array(
+                    'SenderDisplayName' => $oProfile->getDisplayName(),
+                    'SenderUrl' => $oProfile->getUrl(),
+                    'Message' => $sCommentText,
+                ), BX_EMAIL_NOTIFY);
+            }
+        }
+
+        return true;
     }
 
     /**

+ 18 - 0
modules/boonex/convos/install/langs/en.xml

@@ -107,4 +107,22 @@
     <string name="_bx_cnv_draft_saving_error"><![CDATA[Draft saving error!]]></string>
     <string name="_bx_cnv_draft_saved_success"><![CDATA[Draft saved.]]></string>
 
+    <string name="_bx_cnv_email_new_message"><![CDATA[New message]]></string>
+    <string name="_bx_cnv_email_new_message_subject"><![CDATA[New message from {SenderDisplayName}]]></string>
+    <string name="_bx_cnv_email_new_message_body"><![CDATA[
+<bx_include_auto:_email_header.html />
+<p>New message from <a href="{SenderUrl}">{SenderDisplayName}</a>:</p>
+<hr />
+<p>{Message}</p>
+<bx_include_auto:_email_footer.html />]]></string>
+
+    <string name="_bx_cnv_email_new_reply"><![CDATA[New reply]]></string>
+    <string name="_bx_cnv_email_new_reply_subject"><![CDATA[New reply from {SenderDisplayName}]]></string>
+    <string name="_bx_cnv_email_new_reply_body"><![CDATA[
+<bx_include_auto:_email_header.html />
+<p>New reply from <a href="{SenderUrl}">{SenderDisplayName}</a>:</p>
+<hr />
+<p>{Message}</p>
+<bx_include_auto:_email_footer.html />]]></string>
+
 </resources>

+ 4 - 0
modules/boonex/convos/install/sql/disable.sql

@@ -34,3 +34,7 @@ DELETE FROM `sys_objects_view` WHERE `Name` = 'bx_convos';
 SET @iHandler := (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = 'bx_convos' LIMIT 1);
 DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandler;
 DELETE FROM `sys_alerts_handlers` WHERE `id` = @iHandler;
+
+-- EMAIL TEMPLATES
+DELETE FROM `sys_email_templates` WHERE `Module` = 'bx_convos';
+

+ 6 - 0
modules/boonex/convos/install/sql/enable.sql

@@ -190,3 +190,9 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_convos', 'commentRemoved', @iHandler),
 ('profile', 'delete', @iHandler);
 
+-- EMAIL TEMPLATES
+
+INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `Body`) VALUES
+('bx_convos', '_bx_cnv_email_new_message', 'bx_cnv_new_message', '_bx_cnv_email_new_message_subject', '_bx_cnv_email_new_message_body'),
+('bx_convos', '_bx_cnv_email_new_reply', 'bx_cnv_new_reply', '_bx_cnv_email_new_reply_subject', '_bx_cnv_email_new_reply_body');
+

+ 18 - 0
modules/boonex/russian/data/langs/bx_convos/ru.xml

@@ -107,4 +107,22 @@
     <string name="_bx_cnv_draft_saving_error"><![CDATA[Ошибка сохранения черновика!]]></string>
     <string name="_bx_cnv_draft_saved_success"><![CDATA[Черновик сохранён.]]></string>
 
+    <string name="_bx_cnv_email_new_message"><![CDATA[Новое сообщение]]></string>
+    <string name="_bx_cnv_email_new_message_subject"><![CDATA[Новое сообщение от {SenderDisplayName}]]></string>
+    <string name="_bx_cnv_email_new_message_body"><![CDATA[
+<bx_include_auto:_email_header.html />
+<p>Новое сообщение от <a href="{SenderUrl}">{SenderDisplayName}</a>:</p>
+<hr />
+<p>{Message}</p>
+<bx_include_auto:_email_footer.html />]]></string>
+
+    <string name="_bx_cnv_email_new_reply"><![CDATA[Новый ответ]]></string>
+    <string name="_bx_cnv_email_new_reply_subject"><![CDATA[Новый ответ от {SenderDisplayName}]]></string>
+    <string name="_bx_cnv_email_new_reply_body"><![CDATA[
+<bx_include_auto:_email_header.html />
+<p>Новый ответ от <a href="{SenderUrl}">{SenderDisplayName}</a>:</p>
+<hr />
+<p>{Message}</p>
+<bx_include_auto:_email_footer.html />]]></string>
+
 </resources>

+ 2 - 2
template/scripts/BxBaseCmts.php

@@ -577,10 +577,10 @@ class BxBaseCmts extends BxDolCmts
                     $oMetatags->keywordsAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
                 }
 
-                $oZ = new BxDolAlerts($this->_sSystem, 'commentPost', $iCmtObjectId, $iCmtAuthorId, array('comment_id' => $iCmtId, 'comment_author_id' => $iCmtAuthorId, 'object_author_id' => $iCmtObjectAuthorId));
+                $oZ = new BxDolAlerts($this->_sSystem, 'commentPost', $iCmtObjectId, $iCmtAuthorId, array('comment_id' => $iCmtId, 'comment_text' => $sCmtText, 'comment_author_id' => $iCmtAuthorId, 'object_author_id' => $iCmtObjectAuthorId));
                 $oZ->alert();
 
-                $oZ = new BxDolAlerts('comment', 'added', $iCmtId, $iCmtAuthorId, array('object_system' => $this->_sSystem, 'object_id' => $iCmtObjectId, 'object_author_id' => $iCmtObjectAuthorId));
+                $oZ = new BxDolAlerts('comment', 'added', $iCmtId, $iCmtAuthorId, array('object_system' => $this->_sSystem, 'object_id' => $iCmtObjectId, 'object_author_id' => $iCmtObjectAuthorId, 'comment_text' => $sCmtText));
         		$oZ->alert();
 
                 return array('id' => $iCmtId, 'parent_id' => $iCmtParentId);