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

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

AntonLV 4 лет назад
Родитель
Сommit
ea205c7f76

+ 41 - 0
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -1541,6 +1541,47 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         return true;
     }
 
+    public function serviceIsInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
+    {
+        if(!$iProfileId)
+            $iProfileId = bx_get_logged_profile_id();
+
+        if(empty($sKey) && ($sKey = bx_get('key')) !== false)
+            $sKey = bx_process_input($sKey);
+
+        if(!empty($sKey))
+            $mixedInvited = $this->isInvited($sKey, $iGroupProfileId);
+        else if($iProfileId !== false)
+            $mixedInvited = $this->isInvitedByProfileId($iProfileId, $iGroupProfileId);
+
+        return $mixedInvited === true;
+    }
+
+    public function serviceIsNotInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
+    {
+        return !$this->serviceIsInvited($iGroupProfileId, $iProfileId, $sKey);
+    }
+
+    public function serviceGetInvitedKey($iGroupProfileId, $iProfileId = false)
+    {
+        $sKey = '';
+        if(($sKey = bx_get('key')) !== false)
+            $sKey = bx_process_input($sKey);
+
+        if(!$sKey) {
+            if(!$iProfileId)
+                $iProfileId = bx_get_logged_profile_id();
+
+            if($iProfileId !== false) {
+                $aInvite = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
+                if(!empty($aInvite) && is_array($aInvite))
+                    $sKey = $aInvite['key'];
+            }
+        }
+
+        return $sKey;
+    }
+
     public function getRole($iGroupProfileId, $iFanProfileId)
     {
         if(!$this->isFanByGroupProfileId($iGroupProfileId, $iFanProfileId))

+ 34 - 41
modules/base/groups/classes/BxBaseModGroupsPageEntry.php

@@ -70,51 +70,44 @@ class BxBaseModGroupsPageEntry extends BxBaseModProfilePageEntry
         $this->_oModule->checkAllowedView($this->_aContentInfo, true);
     }
     
-    public function getCode ()
+    protected function _getInvitationCode($aParams = [])
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        $sInvitation = '';
-        if(!empty($CNF['TABLE_INVITES'])) {
-            $sKey = '';
-            $iProfileId = bx_get_logged_profile_id();
-            $iGroupProfileId = $this->_oProfile->id();
-
-            if(($sKey = bx_get('key')) !== false) {
-                $sKey = bx_process_input($sKey);
-                $mixedInvited = $this->_oModule->isInvited($sKey, $iGroupProfileId);
-            }
-            else if($iProfileId !== false)
-                $mixedInvited = $this->_oModule->isInvitedByProfileId($iProfileId, $iGroupProfileId);
-
-            if ($mixedInvited === true) {
-                $sId = $this->_oModule->getName() . '_popup_invite';
-
-                if(empty($sKey)) {
-                    $aInvite = $this->_oModule->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
-                    if(!empty($aInvite) && is_array($aInvite))
-                        $sKey = $aInvite['key'];
-                }
-
-                $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);
-            }
-        }
+        if(empty($CNF['TABLE_INVITES']))
+            return '';
+
+        $iProfileId = bx_get_logged_profile_id();
+        $iGroupProfileId = $this->_oProfile->id();
+        if(!$this->_oModule->serviceIsInvited($iGroupProfileId, $iProfileId)) 
+            return '';
+
+        $sId = $this->_oModule->getName() . '_popup_invite';
+        $sKey = $this->_oModule->serviceGetInvitedKey($iGroupProfileId, $iProfileId);
+
+        $sCode = $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(),
+        ));
+
+        if(!isset($aParams['use_invitation_popup']) || $aParams['use_invitation_popup'] === true)
+            $sCode .= 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);
+
+        $this->_oTemplate->addJs(array('invite_popup.js'));        
+        return $sCode;
+    }
 
-        return $sInvitation . parent::getCode();
+    public function getCode ()
+    {
+        return $this->_getInvitationCode() . parent::getCode();
     }
 }