Explorar el Código

Ticket #3643 - Groups: Invited user should be auto accepted Join Group button was clicked.

AntonLV hace 4 años
padre
commit
9f82fecb5c

+ 1 - 1
modules/base/groups/classes/BxBaseModGroupsAlertsResponse.php

@@ -84,7 +84,7 @@ class BxBaseModGroupsAlertsResponse extends BxBaseModProfileAlertsResponse
             if(!$oConnection->isConnected($iInviter, $oAlert->iSender))
                 return;
 
-            if($this->_oModule->_oDb->getInviteByInvited($iInvited, $oAlert->iSender) != 0)
+            if($this->_oModule->_oDb->isInviteByInvited($iInvited, $oAlert->iSender))
                 return;
 
             $sKey = BxDolKey::getInstance()->getNewKey(false, $CNF["INVITES_KEYS_LIFETIME"]);

+ 16 - 10
modules/base/groups/classes/BxBaseModGroupsDb.php

@@ -370,24 +370,30 @@ class BxBaseModGroupsDb extends BxBaseModProfileDb
     
     public function getInviteByKey($sKey, $iGroupProfileId)
     {
-        $aBindings = array(
+        $CNF = &$this->_oConfig->CNF;
+
+        return $this->getRow("SELECT * FROM `" . $CNF["TABLE_INVITES"] . "` WHERE `key` = :key AND group_profile_id = :group_profile_id", [
             'key' => $sKey,
             'group_profile_id' => $iGroupProfileId
-        );
-        $CNF = $this->_oConfig->CNF; 
-        return $this->getRow("SELECT * FROM `" . $CNF["TABLE_INVITES"] . "` WHERE `key` = :key AND group_profile_id = :group_profile_id", $aBindings);
+        ]);
     }
-    
+
     public function getInviteByInvited($iInvitedProfileId, $iGroupProfileId)
     {
-        $aBindings = array(
+        $CNF = &$this->_oConfig->CNF; 
+
+        return $this->getRow("SELECT * FROM `" . $CNF["TABLE_INVITES"] . "` WHERE `invited_profile_id` = :invited_profile_id AND group_profile_id = :group_profile_id", [
             'invited_profile_id' => $iInvitedProfileId,
             'group_profile_id' => $iGroupProfileId
-        );
-        $CNF = $this->_oConfig->CNF; 
-        return $this->getOne("SELECT COUNT(*) FROM `" . $CNF["TABLE_INVITES"] . "` WHERE `invited_profile_id` = :invited_profile_id AND group_profile_id = :group_profile_id", $aBindings);
+        ]);
     }
-    
+
+    public function isInviteByInvited($iInvitedProfileId, $iGroupProfileId)
+    {
+        $aInvite = $this->getInviteByInvited($iInvitedProfileId, $iGroupProfileId);
+        return !empty($aInvite) && is_array($aInvite);
+    }
+
     public function updateInviteByKey($sKey, $iGroupProfileId, $sColumn, $sValue)
     {
         $aBindings = array(

+ 17 - 3
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -1514,19 +1514,33 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         return false;
     }
 
-    public function isInvited ($sKey, $iProfileId) 
+    public function isInvited ($sKey, $iGroupProfileId) 
     {
         $CNF = &$this->_oConfig->CNF;
-        $aData = $this->_oDb->getInviteByKey($sKey,  $iProfileId);
+        $aData = $this->_oDb->getInviteByKey($sKey,  $iGroupProfileId);
         if (!isset($aData['invited_profile_id']))
             return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
         
         if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
-            return  _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
+            return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
         
         return true;
     }
 
+    public function isInvitedByProfileId ($iProfileId, $iGroupProfileId) 
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $aData = $this->_oDb->getInviteByInvited($iProfileId,  $iGroupProfileId);
+        if (!isset($aData['invited_profile_id']))
+            return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
+
+        if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
+            return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
+
+        return true;
+    }
+
     public function getRole($iGroupProfileId, $iFanProfileId)
     {
         if(!$this->isFanByGroupProfileId($iGroupProfileId, $iFanProfileId))

+ 23 - 17
modules/base/groups/classes/BxBaseModGroupsPageEntry.php

@@ -74,32 +74,38 @@ class BxBaseModGroupsPageEntry extends BxBaseModProfilePageEntry
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        $sRv = '';
-        $sKey = '';
-        if(!empty($CNF['TABLE_INVITES']) && ($sKey = bx_get('key')) !== false) {
-            $sId = $this->_oModule->getName() . '_popup_invite';
+        $sInvitation = '';
+        if(!empty($CNF['TABLE_INVITES'])) {
+            $sKey = '';
+            $iGroupProfileId = $this->_oProfile->id();
+
+            if(($sKey = bx_get('key')) !== false)
+                $mixedInvited = $this->_oModule->isInvited($sKey, $iGroupProfileId);
+            else if(($iProfileId = bx_get_logged_profile_id()) !== false)
+                $mixedInvited = $this->_oModule->isInvitedByProfileId($iProfileId, $iGroupProfileId);
 
-            $mixedInvited = $this->_oModule->isInvited($sKey, $this->_oProfile->id());
             if ($mixedInvited === true) {
-                $sRv = $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', array(
+                $sId = $this->_oModule->getName() . '_popup_invite';
+
+                $this->_oTemplate->addJs(array('invite_popup.js'));
+
+                $sInvitation .= $this->_oModule->_oTemplate->getJsCode('invite_popup', array(
+                    'sPopupId' => $sId,
+                    'sKey' => $sKey,
+                    'sAcceptUrl' =>  BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $this->_aProfileInfo['content_id']),
+                    'sDeclineUrl' => BX_DOL_URL_ROOT,
+                    'iGroupProfileId' => $this->_oProfile->id(),
+                ));
+                $sInvitation .= BxTemplFunctions::getInstance()->popupBox($sId, _t($CNF['T']['txt_invitation_popup_title']), $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', array(
                     'popup_id' => $sId,
                     'text' => _t($CNF['T']['txt_invitation_popup_text']),
                     'button_accept' => _t($CNF['T']['txt_invitation_popup_accept_button']),
                     'button_decline' => _t($CNF['T']['txt_invitation_popup_decline_button']),
-                ));
+                )), true);
             }
-            else
-                $sRv = $mixedInvited;
         }
 
-        $this->_oTemplate->addJs(array('invite_popup.js'));
-        return ($sRv != '' ? $this->_oModule->_oTemplate->getJsCode('invite_popup', array(
-            'sPopupId' => $sId,
-            'sKey' => $sKey,
-            'sAcceptUrl' =>  BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $this->_aProfileInfo['content_id']),
-            'sDeclineUrl' => BX_DOL_URL_ROOT,
-            'iGroupProfileId' => $this->_oProfile->id(),
-        )) .  BxTemplFunctions::getInstance()->popupBox($sId, _t($CNF['T']['txt_invitation_popup_title']), $sRv, true) : '') . parent::getCode();
+        return $sInvitation . parent::getCode();
     }
 }