Alex Trofimov 10 лет назад
Родитель
Сommit
b247604f37

+ 66 - 20
modules/boonex/groups/classes/BxGroupsAlertsResponse.php

@@ -19,11 +19,13 @@ class BxGroupsAlertsResponse extends BxDolAlertsResponse
     public function response($oAlert)
     {
         $this->_oModule = BxDolModule::getInstance('bx_groups');
- 
+
+        // connection events
         if ('bx_groups_fans' == $oAlert->sUnit && 'connection_added' == $oAlert->sAction) {
             $this->_oModule->serviceAddMutualConnection($oAlert->aExtras['content'], $oAlert->aExtras['initiator']);
         }
 
+        // profile delete event
         if ('profile' == $oAlert->sUnit && 'delete' == $oAlert->sAction) {
             $this->_oModule->serviceDeleteProfileFromFansAndAdmins($oAlert->iObject);
             $this->_oModule->serviceReassignEntitiesByAuthor($oAlert->iObject);
@@ -32,33 +34,77 @@ class BxGroupsAlertsResponse extends BxDolAlertsResponse
         if ('bx_groups' != $oAlert->sUnit)
             return;
 
+        // join group events
         switch ($oAlert->sAction) {
+        case 'join_invitation':
+            $this->sendMailInvitation($oAlert, $oAlert->iObject, $oAlert->iSender);
+            break;
+        case 'join_request':
+            $this->sendMailJoinRequest($oAlert, $oAlert->iObject, $oAlert->iSender);
+            break;
+        case 'join_request_accepted':
+            $this->sendMailJoinRequestAccepted($oAlert, $oAlert->iObject, $oAlert->iSender);
+            break;
+        }
 
-            case 'timeline_view':
-                $this->processTimelineView($oAlert, $oAlert->iObject);
-                break;
+        // timeline events to override permissions
+        switch ($oAlert->sAction) {
+        case 'timeline_view':
+            $this->processTimelineView($oAlert, $oAlert->iObject);
+            break;
 
-            case 'timeline_comment':
-            case 'timeline_report':
-            case 'timeline_vote':
-                $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject);
-                break;
+        case 'timeline_comment':
+        case 'timeline_report':
+        case 'timeline_vote':
+            $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject);
+            break;
 
-            case 'timeline_post':
-                $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject);
-                break;
+        case 'timeline_post':
+            $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject);
+            break;
 
-            case 'timeline_delete':
-                $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject, 'checkAllowedEdit');
-                break;
+        case 'timeline_delete':
+            $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject, 'checkAllowedEdit');
+            break;
 
-            case 'timeline_share':
-                $this->processTimelineShare($oAlert, $oAlert->iObject);
-                break;
+        case 'timeline_share':
+            $this->processTimelineShare($oAlert, $oAlert->iObject);
+            break;
         }
 
     }
 
+    protected function sendMailInvitation ($oAlert, $iProfileId, $iSender = 0)
+    {
+        sendMailTemplate('bx_groups_invitation', 0, $iProfileId, array(
+            'InviterUrl' => BxDolProfile::getInstance($iSender)->getUrl(),
+            'InviterDisplayName' => BxDolProfile::getInstance($iSender)->getDisplayName(),
+            'EntryUrl' => $oAlert->aExtras['entry_url'],
+            'EntryTitle' => $oAlert->aExtras['entry_title'],
+        ), BX_EMAIL_NOTIFY);
+    }
+
+    protected function sendMailJoinRequest ($oAlert, $iProfileId, $iSender = 0)
+    {
+        $aAdmins = $this->_oModule->_oDb->getAdmins($oAlert->aExtras['group_profile']);
+        foreach ($aAdmins as $iAdminProfileId) {
+            sendMailTemplate('bx_groups_join_request', 0, $iAdminProfileId, array(
+                'NewMemberUrl' => BxDolProfile::getInstance($iProfileId)->getUrl(),
+                'NewMemberDisplayName' => BxDolProfile::getInstance($iProfileId)->getDisplayName(),
+                'EntryUrl' => $oAlert->aExtras['entry_url'],
+                'EntryTitle' => $oAlert->aExtras['entry_title'],
+            ), BX_EMAIL_NOTIFY);
+        }
+    }
+
+    protected function sendMailJoinRequestAccepted ($oAlert, $iProfileId, $iSender = 0)
+    {
+        sendMailTemplate('bx_groups_join_confirm', 0, $iProfileId, array(
+            'EntryUrl' => $oAlert->aExtras['entry_url'],
+            'EntryTitle' => $oAlert->aExtras['entry_title'],
+        ), BX_EMAIL_NOTIFY);
+    }
+    
     protected function processTimelineView ($oAlert, $iGroupProfileId)
     {
         $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
@@ -111,11 +157,11 @@ class BxGroupsAlertsResponse extends BxDolAlertsResponse
     protected function processTimelineShare ($oAlert, $iGroupProfileId)
     {
         if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
-            break;
+            return;
 
         $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
         if (!$oGroupProfile) 
-            break;
+            return;
 
         $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
         if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] || 'c' == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) {

+ 17 - 23
modules/boonex/groups/classes/BxGroupsModule.php

@@ -123,36 +123,30 @@ class BxGroupsModule extends BxBaseModProfileModule
         $sEntryTitle = $aContentInfo[$CNF['FIELD_NAME']];
         $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
 
-        // send invitation to the group
+        // send invitation to the group (@see BxGroupsAlertsResponse)
         if ($iIgnoreJoinConfirmation && !$oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && bx_get_logged_profile_id() != $iProfileId) {
-            sendMailTemplate('bx_groups_invitation', 0, $iProfileId, array(
-                'InviterUrl' => BxDolProfile::getInstance()->getUrl(),
-                'InviterDisplayName' => BxDolProfile::getInstance()->getDisplayName(),
-                'EntryUrl' => $sEntryUrl,
-                'EntryTitle' => $sEntryTitle,
-            ), BX_EMAIL_NOTIFY);
+
+            bx_alert($this->getName(), 'join_invitation', $iProfileId, bx_get_logged_profile_id(), array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId));
+
         }
-        // send notification to group's admins that new connection is pending confirmation
+        // send notification to group's admins that new connection is pending confirmation (@see BxGroupsAlertsResponse)
         elseif (!$iIgnoreJoinConfirmation && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && $aContentInfo['join_confirmation']) {
-            $aAdmins = $this->_oDb->getAdmins($iGroupProfileId);
-            foreach ($aAdmins as $iAdminProfileId) {
-                sendMailTemplate('bx_groups_join_request', 0, $iAdminProfileId, array(
-                    'NewMemberUrl' => BxDolProfile::getInstance($iProfileId)->getUrl(),
-                    'NewMemberDisplayName' => BxDolProfile::getInstance($iProfileId)->getDisplayName(),
-                    'EntryUrl' => $sEntryUrl,
-                    'EntryTitle' => $sEntryTitle,
-                ), BX_EMAIL_NOTIFY);
-            }
+
+            bx_alert($this->getName(), 'join_request', $iProfileId, bx_get_logged_profile_id(), array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId));
+
         }
-        // send notification that join request was accepted
+        // send notification that join request was accepted (@see BxGroupsAlertsResponse)
         else if (!$iIgnoreJoinConfirmation && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id(), true) && $oGroupProfile->getModule() != $this->getName() && bx_get_logged_profile_id() != $iProfileId) {
-            sendMailTemplate('bx_groups_join_confirm', 0, $iProfileId, array(
-                'EntryUrl' => $sEntryUrl,
-                'EntryTitle' => $sEntryTitle,
-            ), BX_EMAIL_NOTIFY);
-        }
+            
+            bx_alert($this->getName(), 'join_request_accepted', $iProfileId, bx_get_logged_profile_id(), array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId));
 
+        }
 
+        // new fan was added
+        if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true)) {
+            bx_alert($this->getName(), 'fan_added', $iProfileId, bx_get_logged_profile_id(), array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId));
+            return false;
+        }
 
         // don't automatically add back connection (mutual) if group requires manual join confirmation
         if (!$iIgnoreJoinConfirmation && $aContentInfo['join_confirmation'])

+ 4 - 0
modules/boonex/groups/install/sql/enable.sql

@@ -374,6 +374,10 @@ SET @iHandler := LAST_INSERT_ID();
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_groups_fans', 'connection_added', @iHandler),
 ('profile', 'delete', @iHandler),
+('bx_groups', 'fan_added', @iHandler),
+('bx_groups', 'join_invitation', @iHandler),
+('bx_groups', 'join_request', @iHandler),
+('bx_groups', 'join_request_accepted', @iHandler),
 ('bx_groups', 'timeline_view', @iHandler),
 ('bx_groups', 'timeline_post', @iHandler),
 ('bx_groups', 'timeline_delete', @iHandler),