Procházet zdrojové kódy

Ticket #3833 - Unlink Invite action from edit action for group roles.

AntonLV před 4 roky
rodič
revize
03d024a575

+ 87 - 4
modules/base/groups/classes/BxBaseModGroupsFormsEntryHelper.php

@@ -18,6 +18,71 @@ class BxBaseModGroupsFormsEntryHelper extends BxBaseModProfileFormsEntryHelper
     {
         parent::__construct($oModule);
     }
+    
+    public function getObjectFormInvite ($sDisplay = false)
+    {
+    	$CNF = &$this->_oModule->_oConfig->CNF;
+
+        if($sDisplay === false)
+            $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE'];
+
+        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
+        if($this->_bAjaxMode)
+            $oForm->setAjaxMode($this->_bAjaxMode);
+
+        if($this->_bAbsoluteActionUrl)
+            $this->_setAbsoluteActionUrl('edit', $oForm);
+
+        return $oForm;
+    }
+
+    public function inviteForm ($iContentId, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
+    {
+        if (!$sCheckFunction)
+            $sCheckFunction = 'checkAllowedInvite';
+
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        // get content data and profile info
+        list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
+
+        if(!$aContentInfo)
+            return $bErrorMsg ? MsgBox(_t('_sys_txt_error_entry_is_not_defined')) : '';
+
+        // check access
+        if(($sMsg = $this->_oModule->$sCheckFunction($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
+            return $bErrorMsg ? MsgBox($sMsg) : '';
+
+        // check and display form
+        $oForm = $this->getObjectFormInvite($sDisplay);
+        if(!$oForm)
+            return $bErrorMsg ? MsgBox(_t('_sys_txt_error_occured')) : '';
+
+        $oForm->initChecker($aContentInfo);
+        if (!$oForm->isSubmittedAndValid())
+            return $oForm->getCode();
+
+        $this->onDataInviteBefore($aContentInfo[$CNF['FIELD_ID']], $aContentInfo);
+
+        if (!$oForm->update($aContentInfo[$CNF['FIELD_ID']])) {
+            if (!$oForm->isValid())
+                return $oForm->getCode();
+            else
+                return MsgBox(_t('_sys_txt_error_entry_update'));
+        }
+
+        list($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
+
+        $sResult = $this->onDataInviteAfter($aContentInfo[$CNF['FIELD_ID']], $aContentInfo);
+        if($sResult)
+            return $sResult;
+
+        // Perform ACL action
+        $this->_oModule->$sCheckFunction($aContentInfo, true);
+
+        // Redirect
+        $this->redirectAfterEdit($aContentInfo);
+    }
 
     protected function _getProfileAndContentData ($iContentId)
     {
@@ -44,10 +109,11 @@ class BxBaseModGroupsFormsEntryHelper extends BxBaseModProfileFormsEntryHelper
 
     public function onDataAddAfter ($iAccountId, $iContentId)
     {
-        if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
+        if($s = parent::onDataAddAfter($iAccountId, $iContentId))
             return $s;
 
-        if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName())))
+        $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName());
+        if(!$oGroupProfile)
             return '';
 
         $this->makeAuthorAdmin ($oGroupProfile, bx_get('initial_members'));
@@ -59,16 +125,33 @@ class BxBaseModGroupsFormsEntryHelper extends BxBaseModProfileFormsEntryHelper
 
     public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
     {
-        if ($s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm))
+        if($s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm))
             return $s;
 
-        if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName())))
+        $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName());
+        if(!$oGroupProfile)
             return ''; 
 
         $this->inviteMembers ($oGroupProfile, bx_get('initial_members'));
 
         return '';
     }
+
+    public function onDataInviteBefore ($iContentId, $aContentInfo)
+    {
+        return '';
+    }
+
+    public function onDataInviteAfter ($iContentId, $aContentInfo)
+    {
+        $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName());
+        if(!$oGroupProfile)
+            return '';
+
+        $this->inviteMembers($oGroupProfile, bx_get('initial_members'));
+
+        return '';
+    }   
     
     protected function redirectAfterEdit($aContentInfo)
     {

+ 7 - 4
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -682,9 +682,12 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
     
     public function serviceEntityInvite ($iContentId = 0, $bErrorMsg = true)
     {
-        if (isset($this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE']))
-            return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE'], false, $bErrorMsg);
-        return false;
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE']))
+            return false;
+
+        return $this->_serviceEntityForm ('inviteForm', $iContentId, false, false, $bErrorMsg);
     }
     
     /**
@@ -1463,7 +1466,7 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_INVITE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
             return CHECK_ACTION_RESULT_ALLOWED;
 
-        return $this->checkAllowedEdit ($aDataEntry, $isPerformAction);
+        return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
     }
     
     public function checkAllowedChangeCover($aDataEntry, $isPerformAction = false)