Kaynağa Gözat

Ticket #4953 - Contexts: Add possibility for an author/admins to enable/disable tabs.

AntonLV 1 yıl önce
ebeveyn
işleme
ed8c49db83

+ 5 - 0
inc/classes/BxDolMenu.php

@@ -286,6 +286,11 @@ class BxDolMenu extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
     	return $bVisible;
     }
 
+    public function getQueryObject()
+    {
+        return $this->_oQuery;
+    }
+
     public function getTemplateId()
     {
         return $this->_aObject['template_id'];

+ 12 - 2
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -16,6 +16,7 @@ define('BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR', 1);
 define('BX_BASE_MOD_GROUPS_ROLE_MODERATOR', 2);
 
 define('BX_BASE_MOD_GROUPS_ACTION_EDIT', 'edit');
+define('BX_BASE_MOD_GROUPS_ACTION_CHANGE_SETTINGS', 'change_settings');
 define('BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER', 'change_cover');
 define('BX_BASE_MOD_GROUPS_ACTION_INVITE', 'invite');
 define('BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS', 'manage_fans');
@@ -977,7 +978,7 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
 
         return $oGrid->getCode();
     }
-    
+
     public function serviceEntityInvite ($iContentId = 0, $bErrorMsg = true)
     {
         $CNF = &$this->_oConfig->CNF;
@@ -1746,6 +1747,7 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
                 switch ($sAction) {
                     case BX_BASE_MOD_GROUPS_ACTION_DELETE:
                     case BX_BASE_MOD_GROUPS_ACTION_EDIT:
+                    case BX_BASE_MOD_GROUPS_ACTION_CHANGE_SETTINGS:
                     case BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER:
                     case BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES:
                         if($this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR)) 
@@ -1919,7 +1921,7 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
 
         return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
     }
-    
+
     public function checkAllowedChangeCover($aDataEntry, $isPerformAction = false)
     {
         if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
@@ -1928,6 +1930,14 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         return parent::checkAllowedChangeCover($aDataEntry, $isPerformAction);
     }
 
+    public function checkAllowedChangeSettings($aDataEntry, $isPerformAction = false)
+    {
+        if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_SETTINGS, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
+            return CHECK_ACTION_RESULT_ALLOWED;
+
+        return parent::checkAllowedChangeSettings($aDataEntry, $isPerformAction);
+    }
+
     public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
     {
         if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_DELETE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)

+ 16 - 0
modules/base/profile/classes/BxBaseModProfileFormEntry.php

@@ -100,6 +100,22 @@ class BxBaseModProfileFormEntry extends BxBaseModGeneralFormEntry
         }
 
         parent::initChecker($aValues, $aSpecificValues);
+
+        if(($sField = 'FIELD_STG_TABS') && !empty($CNF[$sField]) && !empty($this->aInputs[$CNF[$sField]]) && is_array($this->aInputs[$CNF[$sField]]) && ($sValue = $this->aInputs[$CNF[$sField]]['value']))
+            $this->aInputs[$CNF[$sField]]['value'] = !is_array($sValue) ? explode(',', $sValue) : [];
+    }
+
+    function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if(($sField = 'FIELD_STG_TABS') && !empty($CNF[$sField]) && empty($aValsToAdd[$CNF[$sField]])) {
+            $mixedValue = $this->getCleanValue($CNF[$sField]);
+            if(is_array($mixedValue))
+                self::setSubmittedValue($CNF[$sField], implode(',', $mixedValue), $this->aFormAttrs['method']);
+        }
+
+        return parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
     }
 
     function delete ($iContentId, $aContentInfo = array())

+ 28 - 0
modules/base/profile/classes/BxBaseModProfileFormsEntryHelper.php

@@ -45,6 +45,34 @@ class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
         return ($this->_sAutoApproval = $mValue);
     }
 
+    public function getObjectFormEdit ($sDisplay = false)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $oForm = parent::getObjectFormEdit ($sDisplay);
+        if(!$oForm)
+            return $oForm;
+
+        switch($sDisplay) {
+            case $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_SETTINGS']:
+                //--- Fill in tabs list
+                if(($sField = 'FIELD_STG_TABS') && !empty($CNF[$sField]) && !empty($oForm->aInputs[$CNF[$sField]]) && is_array($oForm->aInputs[$CNF[$sField]])) 
+                    if(($sMenu = 'OBJECT_MENU_SUBMENU_VIEW_ENTRY') && !empty($CNF[$sMenu]) && ($oMenu = BxDolMenu::getObjectInstance($CNF[$sMenu])) !== false && ($aMenuItems = $oMenu->getQueryObject()->getMenuItems()))
+                        foreach($aMenuItems as $aMenuItem) {
+                            if($aMenuItem['name'] == 'more-auto' || (int)$aMenuItem['active'] == 0)
+                                continue;
+
+                            $oForm->aInputs[$CNF[$sField]]['values'][] = [
+                                'key' => $aMenuItem['name'],
+                                'value' => _t($aMenuItem['title'])
+                            ];
+                        }
+                break;
+        }
+
+        return $oForm;
+    }
+
     protected function _getProfileAndContentData ($iContentId)
     {
         $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);

+ 49 - 2
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -1069,9 +1069,19 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
         );
     }
 
-    public function serviceEntityEditCover ($iContentId = 0)
+    public function serviceEntityEditCover($iContentId = 0)
     {
-        return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
+        return $this->_serviceEntityForm('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
+    }
+    
+    public function serviceEntityEditSettings($iContentId = 0)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_SETTINGS']))
+            return false;
+
+        return $this->_serviceEntityForm('editDataForm', $iContentId, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_SETTINGS']);
     }
 
     /**
@@ -1821,6 +1831,26 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
         return _t('_sys_txt_access_denied');
     }
 
+    /**
+     * Check if user can change settings
+     */
+    public function checkAllowedChangeSettings ($aDataEntry, $isPerformAction = false)
+    {
+        // moderator always has access
+        if ($this->_isModerator($isPerformAction))
+            return CHECK_ACTION_RESULT_ALLOWED;
+
+        // owner (checked by account instead of author!) always have access
+        $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
+        if (!$oProfile)
+            return _t('_sys_txt_error_occured');
+
+        if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
+            return CHECK_ACTION_RESULT_ALLOWED;
+
+        return _t('_sys_txt_access_denied');
+    }
+
     /**
      * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
      */
@@ -2051,6 +2081,23 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
     }
 
     // ====== COMMON METHODS
+    public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $bResult = parent::isMenuItemVisible($sObject, $aItem, $aContentInfo);
+        if(!$bResult)
+            return $bResult;
+
+        if(($sField = 'FIELD_STG_TABS') && !empty($CNF[$sField]) && ($sTabs = $aContentInfo[$CNF[$sField]])) {
+            $aTabs = explode(',', $sTabs);
+            if(in_array($aItem['name'], $aTabs))
+                return false;
+        }
+
+        return $bResult;
+    }
+
     public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0)
     {
         $CNF = &$this->_oConfig->CNF;