Răsfoiți Sursa

Ticket #3636 - Ability to select multiple membership levels for privacy field.

AntonLV 4 ani în urmă
părinte
comite
dd411c600f

+ 114 - 41
inc/classes/BxDolPrivacy.php

@@ -15,7 +15,7 @@ define('BX_DOL_PG_FRIENDS', '5');
 define('BX_DOL_PG_FRIENDS_SELECTED', '6');
 define('BX_DOL_PG_RELATIONS', '7');
 define('BX_DOL_PG_RELATIONS_SELECTED', '8');
-define('BX_DOL_PG_ACL', '9');
+define('BX_DOL_PG_MEMBERSHIPS_SELECTED', '9');
 define('BX_DOL_PG_CUSTOM', '99');
 
 define('BX_DOL_PG_DEFAULT', BX_DOL_PG_ALL);
@@ -71,8 +71,9 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
     protected $_aGroupsSettings;
     protected $_aGroupsExclude;
     
-    protected $_sFormUsers;
-    protected $_sFormDisplayUsersSelect;
+    protected $_sFormGroupCustom;
+    protected $_sFormDisplayGcMembers;
+    protected $_sFormDisplayGcMemberships;
 
     /**
      * Constructor
@@ -90,19 +91,39 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
 
         $this->_aGroupsSettings = [
             BX_DOL_PG_FRIENDS_SELECTED => [
+                'name' => 'friends',
+                'is_allowed' => '',
                 'connection' => 'sys_profiles_friends', 
-                'js_method_create_group' => 'selectUsers'
+                'js_method_create_group' => 'selectMembers',
+                'db_table_items' => 'sys_privacy_groups_custom_members',
+                'db_field_item' => 'member_id',
+                'uri_get_items' => 'users_list',
             ],
             BX_DOL_PG_RELATIONS_SELECTED => [
+                'name' => 'relations',
+                'is_allowed' => '',
                 'connection' => 'sys_profiles_relations', 
-                'js_method_create_group' => 'selectUsers'
+                'js_method_create_group' => 'selectMembers',
+                'db_table_items' => 'sys_privacy_groups_custom_members',
+                'db_field_item' => 'member_id',
+                'uri_get_items' => 'users_list',
+            ],
+            BX_DOL_PG_MEMBERSHIPS_SELECTED => [
+                'name' => 'memberships',
+                'is_allowed' => 'isAllowedMemberships',
+                'connection' => '',
+                'js_method_create_group' => 'selectMemberships',
+                'db_table_items' => 'sys_privacy_groups_custom_memberships',
+                'db_field_item' => 'membership_id',
+                'uri_get_items' => 'memberships_list',
             ]
         ];
 
         $this->_aGroupsExclude = array();
 
-        $this->_sFormUsers = 'sys_privacy_group_custom';
-        $this->_sFormDisplayUsersSelect = 'sys_privacy_group_custom_manage';
+        $this->_sFormGroupCustom = 'sys_privacy_group_custom';
+        $this->_sFormDisplayGcMembers = 'sys_privacy_group_custom_members';
+        $this->_sFormDisplayGcMemberships = 'sys_privacy_group_custom_memberships';
     }
 
     /**
@@ -154,12 +175,10 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         if(empty($sValue))
             $sValue = $oPrivacy->_oDb->getDefaultGroup($sModule, $sAction);
 
-        $aValues = $oPrivacy->getGroups();
+        $aValues = $oPrivacy->getGroups($iOwnerId, $aParams);
 
         $aValues = $oPrivacy->addDynamicGroups($aValues, $iOwnerId, $aParams);
 
-        $aValues = $oPrivacy->addAclGroups($aValues, $iOwnerId, $aParams);
-
         $aValues = $oPrivacy->addSpaces($aValues, $iOwnerId, $aParams);
 
         $sName = $oPrivacy->convertActionToField($sAction);
@@ -230,7 +249,7 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         $iContentId = (int)bx_get('content_id');
         $iGroupId = (int)bx_get('group_id');
 
-        $oForm = BxDolForm::getObjectInstance($this->_sFormUsers, $this->_sFormDisplayUsersSelect);
+        $oForm = BxDolForm::getObjectInstance($this->_sFormGroupCustom, $this->_sFormDisplayGcMembers);
         return echoJson(array('eval' => $this->getJsObjectName() . '.onSelectGroup(oData);', 'content' => $oForm->getElementGroupCustom(array(
             'profile_id' => $iProfileId, 
             'content_id' => $iContentId, 
@@ -239,7 +258,7 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         ))));
     }
 
-    public function actionSelectGroup()
+    public function actionSelectMembers()
     {
         $aValues = array(
             'profile_id' => (int)bx_get('profile_id'),
@@ -258,12 +277,37 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         if($aValues['profile_id'] != bx_get_logged_profile_id())
             return echoJson(array('msg' => _t('_sys_ps_ferr_incorrect_gc_owner')));
 
-        if(($mixedResult = $this->isSelectGroupCustom($aValues)) !== true)
+        if(($mixedResult = $this->isSelectGroupCustomUsers($aValues)) !== true)
             return echoJson(array('msg' => $mixedResult));
 
         return echoJson($this->getSelectGroup($aValues, $aParams));
     }
 
+    public function actionSelectMemberships()
+    {
+        $aValues = array(
+            'profile_id' => (int)bx_get('profile_id'),
+            'content_id' => (int)bx_get('content_id'),
+            'object' => $this->_sObject,
+            'group_id' => (int)bx_get('group_id')
+        );
+
+        $aParams = array(
+            'popup_only' => (bool)bx_get('popup_only')
+        );
+
+        if(!isset($this->_aGroupsSettings[$aValues['group_id']]))
+            return echoJson(array());
+
+        if($aValues['profile_id'] != bx_get_logged_profile_id())
+            return echoJson(array('msg' => _t('_sys_ps_ferr_incorrect_gc_owner')));
+
+        if(($mixedResult = $this->isSelectGroupCustomMemberships($aValues)) !== true)
+            return echoJson(array('msg' => $mixedResult));
+
+        return echoJson($this->getSelectMemberships($aValues, $aParams));
+    }
+
     public function actionUsersList()
     {
         $iGroup = (int)bx_get('group');
@@ -304,7 +348,7 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
     {
         $aGroups = $this->_oDb->getGroupsBy(array('type' => 'active_list'));
 
-        return in_array(BX_DOL_PG_FRIENDS_SELECTED, $aGroups) || in_array(BX_DOL_PG_RELATIONS_SELECTED, $aGroups);                
+        return in_array(BX_DOL_PG_FRIENDS_SELECTED, $aGroups) || in_array(BX_DOL_PG_RELATIONS_SELECTED, $aGroups) || in_array(BX_DOL_PG_MEMBERSHIPS_SELECTED, $aGroups);
     }
         
     public function getGroupsBy($aParams)
@@ -378,24 +422,6 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         return $aValues;
     }
 
-    public function addAclGroups($aValues, $iOwnerId, $aParams)
-    {
-        $aCheck = checkActionModule($iOwnerId, 'show membership levels in privacy groups', 'system', false);
-        if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
-            return $aValues;
-
-        $aLevels = BxDolAcl::getInstance()->getMemberships(false, true, true, true);
-        if(empty($aLevels) || !is_array($aLevels))
-            return $aValues;
-
-        $aValues[] = array('type' => 'group_header', 'value' => mb_strtoupper(_t('_sys_privacy_groups_acl')));
-        foreach($aLevels as $iId => $sTitle)
-            $aValues[] = array('key' => 'ml' . $iId, 'value' => $sTitle);
-        $aValues[] = array('type' => 'group_end');
-
-        return $aValues;
-    }
-
     public function addSpaces($aValues, $iOwnerId, $aParams)
     {
         if (!$this->_aObject['spaces'])
@@ -599,10 +625,12 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
             'profile_id' => $aObject['owner_id'], 
             'content_id' => $aObject['id'], 
             'object' => $this->_sObject, 
-            'group_id' => $aObject['group_id']
+            'group_id' => $aObject['group_id'],
+            'group_items_table' => $this->_aGroupsSettings[$aObject['group_id']]['db_table_items'],
+            'group_items_field' => $this->_aGroupsSettings[$aObject['group_id']]['db_field_item']
         ));
 
-        return !empty($aGroupCustom['members']) && is_array($aGroupCustom['members']) && in_array($iViewerId, $aGroupCustom['members']);
+        return !empty($aGroupCustom['items']) && is_array($aGroupCustom['items']) && in_array($iViewerId, $aGroupCustom['items']);
     }
 
     public function checkRelations($iOwnerId, $iViewerId)
@@ -620,10 +648,27 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
             'profile_id' => $aObject['owner_id'], 
             'content_id' => $aObject['id'], 
             'object' => $this->_sObject, 
-            'group_id' => $aObject['group_id']
+            'group_id' => $aObject['group_id'],
+            'group_items_table' => $this->_aGroupsSettings[$aObject['group_id']]['db_table_items'],
+            'group_items_field' => $this->_aGroupsSettings[$aObject['group_id']]['db_field_item']
+        ));
+
+        return !empty($aGroupCustom['items']) && is_array($aGroupCustom['items']) && in_array($iViewerId, $aGroupCustom['items']);
+    }
+
+    public function checkMembershipsSelectedByObject($aObject, $iViewerId)
+    {
+        $aGroupCustom = $this->getGroupCustom(array(
+            'type' => 'pcog_ext', 
+            'profile_id' => $aObject['owner_id'], 
+            'content_id' => $aObject['id'], 
+            'object' => $this->_sObject, 
+            'group_id' => $aObject['group_id'],
+            'group_items_table' => $this->_aGroupsSettings[$aObject['group_id']]['db_table_items'],
+            'group_items_field' => $this->_aGroupsSettings[$aObject['group_id']]['db_field_item']
         ));
 
-        return !empty($aGroupCustom['members']) && is_array($aGroupCustom['members']) && in_array($iViewerId, $aGroupCustom['members']);
+        return !empty($aGroupCustom['items']) && is_array($aGroupCustom['items']) && BxDolAcl::getInstance()->isMemberLevelInSet($aGroupCustom['items'], $iViewerId);
     }
 
     public function checkCustomByObject($aObject, $iViewerId)
@@ -688,31 +733,59 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
     /**
      * get privacy groups for getGroupChooser
      */ 
-    protected function getGroups() 
+    protected function getGroups($iOwnerId = 0, $aParams = []) 
     {
         $aValues = array();
+
         $aGroups = $this->_oDb->getGroupsBy(array('type' => 'active'));
         foreach($aGroups as $aGroup) {
-            if((int)$aGroup['active'] == 0 || in_array($aGroup['id'], $this->_aGroupsExclude))
+            $iGroupId = (int)$aGroup['id'];
+
+            if((int)$aGroup['active'] == 0 || in_array($iGroupId, $this->_aGroupsExclude))
                continue;
 
+            if(isset($this->_aGroupsSettings[$iGroupId]) && !empty($this->_aGroupsSettings[$iGroupId]['is_allowed'])) {
+                $sMethodIsAllowed = $this->_aGroupsSettings[$iGroupId]['is_allowed'];
+                if(method_exists($this, $sMethodIsAllowed) && $this->$sMethodIsAllowed($iOwnerId) !== true)
+                    continue;
+            }
+
             $aValues[] = array('key' => $aGroup['id'], 'value' => _t($aGroup['title']));
         }
+
         return $aValues;
     }
 
     /**
-     * Check whethere custom group is allowed in current circumstances.
+     * Check whethere a custom group (based on users list) is allowed in current circumstances.
      * NOTE. Can be overwritten if it's needed.
      * 
      * @param type $aParams an array of parameters.
      * @return boolean result of operation.
      */
-    protected function isSelectGroupCustom($aParams)
+    protected function isSelectGroupCustomUsers($aParams)
     {
         return true;
     }
-    
+
+    /**
+     * Check whethere a custom group (based on memberships list) is allowed in current circumstances.
+     * NOTE. Can be overwritten if it's needed.
+     * 
+     * @param type $aParams an array of parameters.
+     * @return boolean result of operation.
+     */
+    protected function isSelectGroupCustomMemberships($aParams)
+    {
+        return true;
+    }
+
+    public function isAllowedMemberships($iUserId)
+    {
+        $aCheck = checkActionModule($iUserId, 'show membership levels in privacy groups', 'system', false);
+        return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
+    }
+
     /**
      * Check whether the viewer can make requested action.
      *

+ 33 - 13
inc/classes/BxDolPrivacyQuery.php

@@ -193,8 +193,8 @@ class BxDolPrivacyQuery extends BxDolDb
                     'id' => $aParams['id']
                 );
 
-                $sSelectClause .= ", GROUP_CONCAT(`tgm`.`member_id` SEPARATOR  '" . $sDiv . "') AS `members`";
-                $sJoinClause = "LEFT JOIN `sys_privacy_groups_custom_members` AS `tgm` ON `tg`.`id`=`tgm`.`group_id`";
+                $sSelectClause .= ", GROUP_CONCAT(`tgm`.`" . $aParams['group_items_field'] . "` SEPARATOR  '" . $sDiv . "') AS `items`";
+                $sJoinClause = "LEFT JOIN `" . $aParams['group_items_table'] . "` AS `tgm` ON `tg`.`id`=`tgm`.`group_id`";
                 $sWhereClause = " AND `tg`.`id`=:id";
                 $sGroupClause = "`tg`.`id`";
                 break;
@@ -219,8 +219,8 @@ class BxDolPrivacyQuery extends BxDolDb
                     'group_id' => $aParams['group_id'],
                 );
 
-                $sSelectClause .= ", GROUP_CONCAT(`tgm`.`member_id` SEPARATOR  '" . $sDiv . "') AS `members`";
-                $sJoinClause = "LEFT JOIN `sys_privacy_groups_custom_members` AS `tgm` ON `tg`.`id`=`tgm`.`group_id`";
+                $sSelectClause .= ", GROUP_CONCAT(`tgi`.`" . $aParams['group_items_field'] . "` SEPARATOR  '" . $sDiv . "') AS `items`";
+                $sJoinClause = "LEFT JOIN `" . $aParams['group_items_table'] . "` AS `tgi` ON `tg`.`id`=`tgi`.`group_id`";
                 $sWhereClause = " AND `tg`.`profile_id`=:profile_id AND (`tg`.`content_id`=:content_id" . (!empty($aParams['content_id']) ? " OR `tg`.`content_id`='0'" : "") . ") AND `tg`.`object`=:object AND `tg`.`group_id`=:group_id";
                 $sGroupClause = "`tg`.`id`";
                 break;
@@ -245,7 +245,7 @@ class BxDolPrivacyQuery extends BxDolDb
 
         $aResult = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
         if(in_array($aParams['type'], array('id_ext', 'pcog_ext')) && !empty($aResult) && is_array($aResult))
-            $aResult['members'] = explode($sDiv, $aResult['members']);
+            $aResult['items'] = explode($sDiv, $aResult['items']);
 
         return $aResult;
     }
@@ -289,21 +289,25 @@ class BxDolPrivacyQuery extends BxDolDb
 
     public function insertGroupCustomMember($aParamsSet)
     {
-        if(empty($aParamsSet))
-            return false;
-
-        return $this->query("INSERT IGNORE INTO `sys_privacy_groups_custom_members` SET " . $this->arrayToSQL($aParamsSet));
+        return $this->_insertGroupCustomItem('sys_privacy_groups_custom_members', $aParamsSet);
     }
 
     public function deleteGroupCustomMember($aParamsWhere)
     {
-        if(empty($aParamsWhere))
-            return false;
+        return $this->_deleteGroupCustomItem('sys_privacy_groups_custom_members', $aParamsWhere);
+    }
 
-        return $this->query("DELETE FROM `sys_privacy_groups_custom_members` WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
+    public function insertGroupCustomMembership($aParamsSet)
+    {
+        return $this->_insertGroupCustomItem('sys_privacy_groups_custom_memberships', $aParamsSet);
     }
 
-    function getContentByGroupAsSQLPart($sField, $mixedGroupId)
+    public function deleteGroupCustomMembership($aParamsWhere)
+    {
+        return $this->_deleteGroupCustomItem('sys_privacy_groups_custom_memberships', $aParamsWhere);
+    }
+
+    public function getContentByGroupAsSQLPart($sField, $mixedGroupId)
     {
         if(is_array($mixedGroupId))
             $sWhere = " AND `" . $this->_sTable . "`.`" . $sField . "` IN (" . $this->implode_escape($mixedGroupId) . ")";
@@ -330,6 +334,22 @@ class BxDolPrivacyQuery extends BxDolDb
         $sCacheKey = $this->_sCachePrivacyObject . $sModule . '_' . $sAction;
         return $this->fromCache($sCacheKey, 'getRow', $sQuery);
     }
+
+    protected function _insertGroupCustomItem($sTable, $aParamsSet)
+    {
+        if(empty($aParamsSet))
+            return false;
+
+        return $this->query("INSERT IGNORE INTO `" . $sTable . "` SET " . $this->arrayToSQL($aParamsSet));
+    }
+
+    protected function _deleteGroupCustomItem($sTable, $aParamsWhere)
+    {
+        if(empty($aParamsWhere))
+            return false;
+
+        return $this->query("DELETE FROM `" . $sTable . "` WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
+    }
 }
 
 /** @} */

+ 34 - 4
inc/js/classes/BxDolPrivacy.js

@@ -84,7 +84,7 @@ BxDolPrivacy.prototype.selectGroup = function(oElement)
     if(!this._aGroupSettings[iGroupId])
         return;
 
-    var sMethodCreateGroup = 'selectUsers';
+    var sMethodCreateGroup = 'selectMembers';
     if(this._aGroupSettings[iGroupId]['js_method_create_group'])
         sMethodCreateGroup = this._aGroupSettings[iGroupId]['js_method_create_group'];
 
@@ -103,15 +103,19 @@ BxDolPrivacy.prototype.editGroup = function(oElement)
 {
     var iGroupId = parseInt($(oElement).parents('.bx-form-element:first').find('.sys-privacy-group').val());
 
-    this.selectUsers(oElement, iGroupId, {
+    var sMethodCreateGroup = 'selectMembers';
+    if(this._aGroupSettings[iGroupId]['js_method_create_group'])
+        sMethodCreateGroup = this._aGroupSettings[iGroupId]['js_method_create_group'];
+
+    this[sMethodCreateGroup](oElement, iGroupId, {
         popup_only: 1
     });
 };
 
-BxDolPrivacy.prototype.selectUsers = function(oElement, iGroupId, aParams)
+BxDolPrivacy.prototype.selectMembers = function(oElement, iGroupId, aParams)
 {
     var $this = this;
-    var oData = $.extend({}, $this._getDefaultParams(), {action: 'select_group', group_id: iGroupId}, (aParams || {}));
+    var oData = $.extend({}, $this._getDefaultParams(), {action: 'select_members', group_id: iGroupId}, (aParams || {}));
 
     this._loadingInFormElement(oElement, true);
 
@@ -134,6 +138,32 @@ BxDolPrivacy.prototype.onSelectUsers = function(oData)
     this.onSelectGroup(oData);
 };
 
+BxDolPrivacy.prototype.selectMemberships = function(oElement, iGroupId, aParams)
+{
+    var $this = this;
+    var oData = $.extend({}, $this._getDefaultParams(), {action: 'select_memberships', group_id: iGroupId}, (aParams || {}));
+
+    this._loadingInFormElement(oElement, true);
+
+    $.get(
+        this._sActionsUrl, 
+        oData,
+        function(oData) {
+            $this._loadingInFormElement(oElement, false);
+
+            processJsonData(oData);
+        }, 
+        'json'
+    );
+};
+
+BxDolPrivacy.prototype.onSelectMemberships = function(oData)
+{
+    $('#' + this._aHtmlIds['group_custom_element']).remove();
+
+    this.onSelectGroup(oData);
+};
+
 BxDolPrivacy.prototype._loading = function(e, bShow)
 {
     var oParent = $(e).length ? $(e) : $('body'); 

Fișier diff suprimat deoarece este prea mare
+ 0 - 0
install/sql/system.sql


+ 11 - 1
modules/base/profile/classes/BxBaseModProfilePrivacy.php

@@ -47,7 +47,17 @@ class BxBaseModProfilePrivacy extends BxTemplPrivacy
         return $a;
     }
 
-    protected function isSelectGroupCustom($aParams)
+    protected function isSelectGroupCustomUsers($aParams)
+    {
+        return $this->_isSelectGroupCustomItems($aParams);
+    }
+
+    protected function isSelectGroupCustomMemberships($aParams)
+    {
+        return $this->_isSelectGroupCustomItems($aParams);
+    }
+
+    protected function _isSelectGroupCustomItems($aParams)
     {
         if($this->_oModule->serviceActAsProfile() && empty($aParams['content_id']))
             return _t('_sys_ps_ferr_incorrect_gc_not_allowed');

+ 11 - 1
modules/base/profile/classes/BxBaseModProfilePrivacyContact.php

@@ -33,7 +33,17 @@ class BxBaseModProfilePrivacyContact extends BxTemplPrivacy
         return $a;
     }
 
-    protected function isSelectGroupCustom($aParams)
+    protected function isSelectGroupCustomUsers($aParams)
+    {
+        return $this->_isSelectGroupCustomItems($aParams);
+    }
+
+    protected function isSelectGroupCustomMemberships($aParams)
+    {
+        return $this->_isSelectGroupCustomItems($aParams);
+    }
+
+    protected function _isSelectGroupCustomItems($aParams)
     {
         if($this->_oModule->serviceActAsProfile() && empty($aParams['content_id']))
             return _t('_sys_ps_ferr_incorrect_gc_not_allowed');

+ 11 - 1
modules/base/profile/classes/BxBaseModProfilePrivacyPost.php

@@ -33,7 +33,17 @@ class BxBaseModProfilePrivacyPost extends BxTemplPrivacy
         return $a;
     }
 
-    protected function isSelectGroupCustom($aParams)
+    protected function isSelectGroupCustomUsers($aParams)
+    {
+        return $this->_isSelectGroupCustomItems($aParams);
+    }
+
+    protected function isSelectGroupCustomMemberships($aParams)
+    {
+        return $this->_isSelectGroupCustomItems($aParams);
+    }
+
+    protected function _isSelectGroupCustomItems($aParams)
     {
         if($this->_oModule->serviceActAsProfile() && empty($aParams['content_id']))
             return _t('_sys_ps_ferr_incorrect_gc_not_allowed');

+ 4 - 1
modules/boonex/artificer/data/template/system/css/forms.css

@@ -265,7 +265,7 @@ import url(../../../../../../../template/css/forms.css);
 .bx-form-value .bx-form-input-autotoken:not(.bx-form-input-labels) b {
     display: block;
     margin: 0.25rem;
-    padding-right: 1.5rem; 
+    padding-right: 1.5rem;
     border-radius: 1.25rem;
 
     line-height: 2.5rem;
@@ -273,6 +273,9 @@ import url(../../../../../../../template/css/forms.css);
     font-weight: normal;    
     cursor: pointer;
 }
+.bx-form-value .bx-form-input-autotoken:not(.bx-form-input-labels) b.val-wo-icon {
+    padding-left: 1.5rem;
+}
 .bx-form-value .bx-form-input-autotoken:not(.bx-form-input-labels) b:first-child {
     margin-left: 0.75rem;
 }

+ 7 - 4
modules/boonex/english/data/langs/system/en.xml

@@ -1925,8 +1925,8 @@
         <string name="_sys_acl_action_use_macros_desc"><![CDATA[Use special constructions to insert dynamic content almost anywhere]]></string>
 	<string name="_sys_acl_action_set_acl_level"><![CDATA[Set membership level]]></string>
 	<string name="_sys_acl_action_set_acl_level_desc"><![CDATA[Set membership level for profiles]]></string>
-        <string name="_sys_acl_action_show_membership_levels_in_privacy_groups"><![CDATA[Show membership levels in privacy groups]]></string>
-        <string name="_sys_acl_action_show_membership_levels_in_privacy_groups_desc"><![CDATA[Show membership levels in privacy groups]]></string>
+        <string name="_sys_acl_action_show_membership_levels_in_privacy_groups"><![CDATA[Use membership level(s) in privacy fields]]></string>
+        <string name="_sys_acl_action_show_membership_levels_in_privacy_groups_desc"><![CDATA[Allow to limit access by membership level(s) in privacy fields]]></string>
         <string name="_sys_acl_action_show_membership_private_info"><![CDATA[Show membership private info]]></string>
         <string name="_sys_acl_action_show_membership_private_info_desc"><![CDATA[Show membership private info]]></string>
         <string name="_sys_acl_action_set_badge"><![CDATA[Set badge]]></string>
@@ -2474,7 +2474,8 @@ If it is not enabled then please consider implement this optimization, since it
         <string name="_sys_form_acl_input_do_cancel"><![CDATA[Cancel]]></string>
 	<string name="_sys_form_paceholder_profiles_suggestions"><![CDATA[Type name here...]]></string>
         <string name="_sys_form_ps_group_custom"><![CDATA[Privacy: Custom group]]></string>
-        <string name="_sys_form_display_ps_gc_manage"><![CDATA[Privacy: Manage custom group display]]></string>
+        <string name="_sys_form_display_ps_gc_members"><![CDATA[Privacy: Profiles based custom group display]]></string>
+        <string name="_sys_form_display_ps_gc_memberships"><![CDATA[Privacy: Memberships based custom group display]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_profile_id"><![CDATA[Profile ID]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_content_id"><![CDATA[Content ID]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_object"><![CDATA[Object]]></string>
@@ -2484,6 +2485,8 @@ If it is not enabled then please consider implement this optimization, since it
         <string name="_sys_form_ps_gc_input_caption_search"><![CDATA[Search]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_list"><![CDATA[List]]></string>
         <string name="_sys_form_ps_gc_input_caption_list"><![CDATA[or select]]></string>
+        <string name="_sys_form_ps_gc_input_caption_system_memberships"><![CDATA[Memberships List]]></string>
+        <string name="_sys_form_ps_gc_input_caption_memberships"><![CDATA[Select]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_do_submit"><![CDATA[Submit]]></string>
         <string name="_sys_form_ps_gc_input_caption_do_submit"><![CDATA[Submit]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_do_cancel"><![CDATA[Cancel]]></string>
@@ -3226,7 +3229,7 @@ If it is not enabled then please consider implement this optimization, since it
             <li><b>{0}</b> total</li>
             <li><b>{1}</b> deleted</li>
         </ul>]]></string>
-    <string name="_sys_ps_group_title_acl_selected"><![CDATA[Selected Membership Levels...]]></string>
+    <string name="_sys_ps_group_title_memberships_selected"><![CDATA[Selected Membership Levels...]]></string>
     <string name="_sys_ps_group_title_custom"><![CDATA[Custom]]></string>
     <string name="_sys_ps_group_title_followers"><![CDATA[Followers]]></string>
     <string name="_sys_ps_group_title_friends"><![CDATA[Friends]]></string>

+ 7 - 4
modules/boonex/russian/data/langs/system/ru.xml

@@ -1910,8 +1910,8 @@
         <string name="_sys_acl_action_use_macros_desc"><![CDATA[Использовать специально сконструированный вызов, для вставки динамического контента практически в любой текст]]></string>
 	<string name="_sys_acl_action_set_acl_level"><![CDATA[Назначить членство]]></string>
 	<string name="_sys_acl_action_set_acl_level_desc"><![CDATA[Назначить членство для профилей]]></string>
-        <string name="_sys_acl_action_show_membership_levels_in_privacy_groups"><![CDATA[Показывать членство в группах конфиденциальности]]></string>
-        <string name="_sys_acl_action_show_membership_levels_in_privacy_groups_desc"><![CDATA[Показывать членство в группах конфиденциальности]]></string>
+        <string name="_sys_acl_action_show_membership_levels_in_privacy_groups"><![CDATA[Использовать уровни членства в полях конфиденциальности]]></string>
+        <string name="_sys_acl_action_show_membership_levels_in_privacy_groups_desc"><![CDATA[Разрешить ограничивать доступ по уровню(ям) членства в полях конфиденциальности]]></string>
         <string name="_sys_acl_action_show_membership_private_info"><![CDATA[Показывать конфиденциальную информацию о членстве]]></string>
         <string name="_sys_acl_action_show_membership_private_info_desc"><![CDATA[Показывать конфиденциальную информацию о членстве]]></string>
         <string name="_sys_acl_action_set_badge"><![CDATA[Назначение бейджей]]></string>
@@ -2461,7 +2461,8 @@
         <string name="_sys_form_acl_input_do_cancel"><![CDATA[Отмена]]></string>
 	<string name="_sys_form_paceholder_profiles_suggestions"><![CDATA[Введите имя...]]></string>
         <string name="_sys_form_ps_group_custom"><![CDATA[Конфиденциальность: Пользовательская группа]]></string>
-        <string name="_sys_form_display_ps_gc_manage"><![CDATA[Конфиденциальность: Управлять пользовательской группой]]></string>
+        <string name="_sys_form_display_ps_gc_members"><![CDATA[Конфиденциальность: Пользовательская группа на основании профилей]]></string>
+        <string name="_sys_form_display_ps_gc_memberships"><![CDATA[Конфиденциальность: Пользовательская группа на основании членств]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_profile_id"><![CDATA[ID профиля]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_content_id"><![CDATA[ID контента]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_object"><![CDATA[Объект]]></string>
@@ -2471,6 +2472,8 @@
         <string name="_sys_form_ps_gc_input_caption_search"><![CDATA[Найти]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_list"><![CDATA[Список]]></string>
         <string name="_sys_form_ps_gc_input_caption_list"><![CDATA[или выбрать]]></string>
+        <string name="_sys_form_ps_gc_input_caption_system_memberships"><![CDATA[Список членств]]></string>
+        <string name="_sys_form_ps_gc_input_caption_memberships"><![CDATA[Выбрать]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_do_submit"><![CDATA[Отправить]]></string>
         <string name="_sys_form_ps_gc_input_caption_do_submit"><![CDATA[Отправить]]></string>
         <string name="_sys_form_ps_gc_input_caption_system_do_cancel"><![CDATA[Отменить]]></string>
@@ -3191,7 +3194,7 @@
             <li><b>{0}</b> всего</li>
             <li><b>{1}</b> удалено</li>
         </ul>]]></string>
-    <string name="_sys_ps_group_title_acl_selected"><![CDATA[Избранные уровни членства...]]></string>
+    <string name="_sys_ps_group_title_memberships_selected"><![CDATA[Избранные уровни членства...]]></string>
     <string name="_sys_ps_group_title_custom"><![CDATA[Индивидуально]]></string>
     <string name="_sys_ps_group_title_followers"><![CDATA[Подписчики]]></string>
     <string name="_sys_ps_group_title_friends"><![CDATA[Друзья]]></string>

+ 3 - 0
template/css/forms.css

@@ -660,6 +660,9 @@
     font-weight:normal;
 	border-radius: 1.25rem;
 }
+.bx-form-value .bx-form-input-autotoken b.val-wo-icon {
+    padding-left: 1.5em;
+}
 .bx-form-value .bx-form-input-autotoken b:hover {
     opacity:0.7;
 }

+ 1 - 1
template/privacy_group_custom.html

@@ -1 +1 @@
-<div id="__html_id__" class="sys-privacy-group-custom bx-def-margin-top" onclick="javascript:__js_object__.editGroup(this)">__input_id____input_members__</div>
+<div id="__html_id__" class="sys-privacy-group-custom bx-def-margin-top" onclick="javascript:__js_object__.editGroup(this)">__input_id____input_items__</div>

+ 0 - 0
template/privacy_users_select_popup.html → template/privacy_group_custom_select_popup.html


+ 3 - 0
template/privacy_memberships_value.html

@@ -0,0 +1,3 @@
+<bx_repeat:vals>
+    <b class="val val-wo-icon bx-def-color-bg-hl bx-def-round-corners">__title__<input type="hidden" name="__name__[]" value="__value__" /></b>
+</bx_repeat:vals>

+ 60 - 4
template/scripts/BxBasePrivacy.php

@@ -34,7 +34,7 @@ class BxBasePrivacy extends BxDolPrivacy
         $this->_aHtmlIds = array(
             'group_element' => 'bx-form-element-' . $this->convertActionToField($this->_aObject['action']),
             'group_custom_element' => 'sys-pgc-' . $sHtmlId,
-            'users_select_popup' => 'sys-privacy-usp-' . $sHtmlId . '-'
+            'group_custom_select_popup' => 'sys-privacy-gcsp-' . $sHtmlId . '-'
         );
     }
 
@@ -104,7 +104,7 @@ class BxBasePrivacy extends BxDolPrivacy
     {
         $sJsObject = $this->getJsObjectName();
 
-        $oForm = BxDolForm::getObjectInstance($this->_sFormUsers, $this->_sFormDisplayUsersSelect);
+        $oForm = BxDolForm::getObjectInstance($this->_sFormGroupCustom, $this->_sFormDisplayGcMembers);
         $oForm->initChecker($aValues);
 
         if($oForm->isSubmittedAndValid()) {
@@ -141,12 +141,68 @@ class BxBasePrivacy extends BxDolPrivacy
 
             return array('eval' => $sJsObject . '.onSelectUsers(oData);', 'content' => $oForm->getElementGroupCustom(array(
                 'value' => $iGroupCustomId, 
-                'value_members' => $aMembers
+                'value_items' => $aMembers
             )));
         }
 
         $iGroupId = $oForm->getGroupId();
-        $sContent = BxTemplFunctions::getInstance()->transBox($this->_aHtmlIds['users_select_popup'] . $iGroupId, $this->_oTemplate->parseHtmlByName('privacy_users_select_popup.html', array(
+        $sContent = BxTemplFunctions::getInstance()->transBox($this->_aHtmlIds['group_custom_select_popup'] . $iGroupId, $this->_oTemplate->parseHtmlByName('privacy_group_custom_select_popup.html', array(
+            'js_object' => $sJsObject,
+            'group' => $iGroupId,
+            'form' => $oForm->getCode(),
+            'form_id' => $oForm->getId()
+        )));
+
+        $aResult = array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false)));
+        if(isset($aParams['popup_only']) && (bool)$aParams['popup_only'] === true)
+            return $aResult;
+
+        return array_merge($aResult, array(
+            'eval' => $sJsObject . '.onSelectGroup(oData);', 
+            'content' => $oForm->getElementGroupCustom()
+        ));
+    }
+
+    protected function getSelectMemberships($aValues = array(), $aParams = array())
+    {
+        $sJsObject = $this->getJsObjectName();
+
+        $oForm = BxDolForm::getObjectInstance($this->_sFormGroupCustom, $this->_sFormDisplayGcMemberships);
+        $oForm->initChecker($aValues);
+
+        if($oForm->isSubmittedAndValid()) {
+            $aMemberships = $oForm->getCleanValue('memberships');
+
+            $iGroupCustomId = $oForm->getGroupCustomId();
+            if(!$iGroupCustomId) {
+                if(empty($aMemberships) || !is_array($aMemberships))
+                    return array();
+
+                $this->deleteGroupCustom(array(
+                    'profile_id' => $oForm->getCleanValue('profile_id'),
+                    'content_id' => $oForm->getCleanValue('content_id'),
+                    'object' => $oForm->getCleanValue('object')
+                ));
+
+                $iGroupCustomId = $oForm->insert();
+                foreach($aMemberships as $iMembershipId)
+                    $this->_oDb->insertGroupCustomMembership(array('group_id' => $iGroupCustomId, 'membership_id' => $iMembershipId));
+            }
+            else {
+                $this->_oDb->deleteGroupCustomMembership(array('group_id' => $iGroupCustomId));
+
+                foreach($aMemberships as $iMembershipId)
+                    $this->_oDb->insertGroupCustomMembership(array('group_id' => $iGroupCustomId, 'membership_id' => $iMembershipId));
+            }
+
+            return array('eval' => $sJsObject . '.onSelectMemberships(oData);', 'content' => $oForm->getElementGroupCustom(array(
+                'value' => $iGroupCustomId, 
+                'value_items' => $aMemberships
+            )));
+        }
+
+        $iGroupId = $oForm->getGroupId();
+        $sContent = BxTemplFunctions::getInstance()->transBox($this->_aHtmlIds['group_custom_select_popup'] . $iGroupId, $this->_oTemplate->parseHtmlByName('privacy_group_custom_select_popup.html', array(
             'js_object' => $sJsObject,
             'group' => $iGroupId,
             'form' => $oForm->getCode(),

+ 64 - 15
template/scripts/BxBasePrivacyFormGroupCustom.php

@@ -38,8 +38,12 @@ class BxBasePrivacyFormGroupCustom extends BxTemplFormView
         $this->_aGroupCustomInfo = array();
 
         switch($this->aParams['display']) {
-            case 'sys_privacy_group_custom_manage':
-                $this->aInputs['action']['value'] = 'select_group';
+            case 'sys_privacy_group_custom_members':
+                $this->aInputs['action']['value'] = 'select_members';
+                break;
+
+            case 'sys_privacy_group_custom_memberships':
+                $this->aInputs['action']['value'] = 'select_memberships';
                 break;
         }
     }
@@ -48,6 +52,21 @@ class BxBasePrivacyFormGroupCustom extends BxTemplFormView
     {
         $this->initData($aValues);
 
+        if(isset($this->aInputs['memberships']) && $this->_oObject->isAllowedMemberships($this->_iProfileId)) {
+            $aSelected = array();
+            if(!empty($this->_aGroupCustomInfo) && is_array($this->_aGroupCustomInfo))
+                $this->aInputs['memberships']['value'] = $this->_aGroupCustomInfo['items'];
+
+            $aLevels = BxDolAcl::getInstance()->getMemberships(false, true, true, true);
+            if(!empty($aLevels) && is_array($aLevels)) {
+                $aLevelsValues = [];
+                foreach($aLevels as $iId => $sTitle)
+                    $aLevelsValues[] = array('key' => $iId, 'value' => $sTitle);
+
+                $this->aInputs['memberships']['values'] = $aLevelsValues;
+            }
+        }
+
         return parent::initChecker($aValues, $aSpecificValues);
     }
 
@@ -67,11 +86,17 @@ class BxBasePrivacyFormGroupCustom extends BxTemplFormView
 
         $sName = 'sys-pgc-' . str_replace('_', '-', $this->_sObject);
         $iValue = !empty($aParams['value']) ? (int)$aParams['value'] : $this->_iGroupCustomId;
-        $aValueMembers = array();
-        if(!empty($aParams['value_members']) && is_array($aParams['value_members']))
-            $aValueMembers = $aParams['value_members'];
+
+        $sItemsName = $sName . '-items';
+        $aItemsValue = array();
+        if(!empty($aParams['value_items']) && is_array($aParams['value_items']))
+            $aItemsValue = $aParams['value_items'];
         else if($this->_iGroupCustomId)
-            $aValueMembers = $this->_aGroupCustomInfo['members'];
+            $aItemsValue = $this->_aGroupCustomInfo['items'];
+
+        $sMethodItemsValue = 'getElementGroupCustomValue' . bx_gen_method_name($this->_aGroupSettings['name']);
+        if(!empty($aItemsValue) && method_exists($this, $sMethodItemsValue))
+            $aItemsValue = $this->$sMethodItemsValue($sItemsName, $aItemsValue);
 
         $aInput = array(
             'type' => 'hidden',
@@ -83,14 +108,14 @@ class BxBasePrivacyFormGroupCustom extends BxTemplFormView
             )
         );
 
-        $aInputMembers = array(
+        $aInputItems = array(
             'type' => 'custom',
-            'name' => $sName . '-members',
+            'name' => $sItemsName,
             'caption' => '',
-            'value' => $aValueMembers,
+            'value' => $aItemsValue,
             'ajax_get_suggestions' => BX_DOL_URL_ROOT . bx_append_url_params('privacy.php', array(
                 'object' => $this->_sObject,
-                'action' => 'users_list',
+                'action' => $this->_aGroupSettings['uri_get_items'],
                 'group' => $this->_iGroupId
             )),
             'attrs' => array(
@@ -98,12 +123,34 @@ class BxBasePrivacyFormGroupCustom extends BxTemplFormView
             )
         );
 
-        return $this->oTemplate->parseHtmlByName('privacy_group_custom.html', array(
+        return $this->oTemplate->parseHtmlByName('privacy_group_custom.html', [
             'js_object' => $this->_oObject->getJsObjectName(),
             'html_id' => $sName,
             'input_id' => $this->genInputStandard($aInput),
-            'input_members' => $this->genCustomInputUsernamesSuggestions($aInputMembers)
-        ));
+            'input_items' => $this->genCustomInputUsernamesSuggestions($aInputItems)
+        ]);
+    }
+
+    protected function getElementGroupCustomValueMemberships($sName, $aItems)
+    {
+        $oAcl = BxDolAcl::getInstance();
+
+        $aTmplVarsItems = [];
+        foreach($aItems as $iItem) {
+            $aItemInfo = $oAcl->getMembershipInfo($iItem);
+            if(empty($aItemInfo) || !is_array($aItemInfo))
+                continue;
+
+            $aTmplVarsItems[] = [
+                'name' => $sName,
+                'value' => $iItem,
+                'title' => _t($aItemInfo['name'])
+            ];
+        }
+
+        return $this->oTemplate->parseHtmlByName('privacy_memberships_value.html', [
+            'bx_repeat:vals' => $aTmplVarsItems
+        ]);
     }
 
     protected function genCustomInputSearch($aInput)
@@ -129,7 +176,7 @@ class BxBasePrivacyFormGroupCustom extends BxTemplFormView
 
         $aSelected = array();
         if(!empty($this->_aGroupCustomInfo) && is_array($this->_aGroupCustomInfo))
-            $aSelected = $this->_aGroupCustomInfo['members'];
+            $aSelected = $this->_aGroupCustomInfo['items'];
 
         $aTmplVarsUsers = array();
         if(!empty($aConnectedIds) && is_array($aConnectedIds)) {
@@ -184,7 +231,9 @@ class BxBasePrivacyFormGroupCustom extends BxTemplFormView
                 'profile_id' => $this->_iProfileId,
                 'content_id' => $this->_iContentId,
                 'object' => $this->_sObject,
-                'group_id' => $this->_iGroupId
+                'group_id' => $this->_iGroupId,
+                'group_items_table' => $this->_aGroupSettings['db_table_items'],
+                'group_items_field' => $this->_aGroupSettings['db_field_item']
             ));
 
             if(!empty($this->_aGroupCustomInfo) && is_array($this->_aGroupCustomInfo))

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff