Quellcode durchsuchen

#281 Groups: remove admins and subscriptions upon leaving the group

Alex Trofimov vor 10 Jahren
Ursprung
Commit
f9bc27ec56

+ 3 - 0
modules/boonex/groups/classes/BxGroupsAlertsResponse.php

@@ -24,6 +24,9 @@ class BxGroupsAlertsResponse extends BxDolAlertsResponse
         if ('bx_groups_fans' == $oAlert->sUnit && 'connection_added' == $oAlert->sAction) {
             $this->_oModule->serviceAddMutualConnection($oAlert->aExtras['content'], $oAlert->aExtras['initiator']);
         }
+        elseif ('bx_groups_fans' == $oAlert->sUnit && 'connection_removed' == $oAlert->sAction) {
+            $this->_oModule->serviceOnRemoveConnection($oAlert->aExtras['content'], $oAlert->aExtras['initiator']);
+        }
 
         // profile delete event
         if ('profile' == $oAlert->sUnit && 'delete' == $oAlert->sAction) {

+ 32 - 9
modules/boonex/groups/classes/BxGroupsModule.php

@@ -97,21 +97,28 @@ class BxGroupsModule extends BxBaseModProfileModule
         return $aFieldsProfile;
     }
 
+    public function serviceOnRemoveConnection ($iGroupProfileId, $iInitiatorId)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
+        if (!$oGroupProfile)
+            return false;
+
+        $this->_oDb->fromAdmins($iGroupProfileId, $iProfileId);
+
+        if ($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions'))
+            $oConn->removeConnection($iProfileId, $iGroupProfileId);
+    }
+
     public function serviceAddMutualConnection ($iGroupProfileId, $iInitiatorId, $iIgnoreJoinConfirmation = false)
     {        
         $CNF = &$this->_oConfig->CNF;
 
-        if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
+        list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
+        if (!$oGroupProfile)
             return false;
 
-        if ($oGroupProfile->getModule() == $this->getName()) {
-            $iProfileId = $iInitiatorId;
-            $iGroupProfileId = $oGroupProfile->id();
-        } else {
-            $iProfileId = $oGroupProfile->id();
-            $iGroupProfileId = $iInitiatorId;
-        }
-
         if (!($aContentInfo = $this->_oDb->getContentInfoById((int)BxDolProfile::getInstance($iGroupProfileId)->getContentId())))
             return false;
 
@@ -419,6 +426,22 @@ class BxGroupsModule extends BxBaseModProfileModule
 		    array('url' => $sUrl, 'src' => $oGroupProfile->getPicture()),
 		);
     }
+
+    protected function _prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId)
+    {
+        if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
+            return array(0, 0, null);
+
+        if ($oGroupProfile->getModule() == $this->getName()) {
+            $iProfileId = $iInitiatorId;
+            $iGroupProfileId = $oGroupProfile->id();
+        } else {
+            $iProfileId = $oGroupProfile->id();
+            $iGroupProfileId = $iInitiatorId;
+        }
+
+        return array($iProfileId, $iGroupProfileId, $oGroupProfile);
+    }
 }
 
 /** @} */

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

@@ -373,6 +373,7 @@ SET @iHandler := LAST_INSERT_ID();
 
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_groups_fans', 'connection_added', @iHandler),
+('bx_groups_fans', 'connection_removed', @iHandler),
 ('profile', 'delete', @iHandler),
 ('bx_groups', 'fan_added', @iHandler),
 ('bx_groups', 'join_invitation', @iHandler),