26 function __construct($sTable =
'', $sFieldId =
'', $sFieldOwnerId =
'')
28 parent::__construct();
30 $this->_sTable = $sTable;
31 $this->_sFieldId = $sFieldId;
32 $this->_sFieldOwnerId = $sFieldOwnerId;
34 $this->_sGroupCache =
'sys_ps_group_';
35 $this->_sGroupsByOwnersCache =
'sys_ps_groups_owners_';
36 $this->_sGroupMembersCache =
'sys_ps_group_members_';
37 $this->_sObjectCache =
'sys_ps_object_';
38 $this->_sActionCache =
'sys_ps_action_';
39 $this->_sActionDefaultCache =
'sys_ps_action_default_';
43 if(
empty($this->_sTable) ||
empty($this->_sFieldId) ||
empty($this->_sFieldOwnerId))
47 $this->_sObjectCache . $this->_sTable .
'_' .
$sAction .
'_' . $iObjectId,
49 "SELECT `" . $this->_sFieldOwnerId .
"` AS `owner_id`, `" .
$sAction .
"` AS `group_id` FROM `" . $this->_sTable .
"` WHERE `" . $this->_sFieldId .
"`= ? LIMIT 1",
53 function isGroupMember($mixedObjectGroupId, $iObjectOwnerId, $iViewerId)
55 $iGroupId = (int)$mixedObjectGroupId;
57 $aGroup = $this->
getGroupsBy(array(
'type' =>
'id',
'id' => $iGroupId));
58 if(
empty($aGroup) || !is_array($aGroup))
62 if((
int)$aGroup[
'owner_id'] != 0) {
64 $this->_sGroupMembersCache . $iGroupId,
66 "SELECT `id`, `member_id` FROM `sys_privacy_members` WHERE `group_id`='" . $iGroupId .
"'",
70 if(array_key_exists($iViewerId, $aGroupMembers))
74 if($this->
getParam(
'sys_ps_enabled_group_' . $aGroup[
'id']) ==
'on' && (
int)$aGroup[
'owner_id'] == 0 && !
empty($aGroup[
'get_content'])) {
75 $oFunction =
function($arg0, $arg1, $arg2)
use ($aGroup) {
76 return eval($aGroup[
'get_content']);
79 if($oFunction($this, $iObjectOwnerId, $iViewerId))
83 if((
int)$aGroup[
'owner_id'] == 0 && !
empty($aGroup[
'get_parent'])) {
84 $oFunction =
function($arg0, $arg1, $arg2)
use ($aGroup) {
85 return eval($aGroup[
'get_parent']);
88 $iId = $oFunction($this, $iObjectOwnerId, $iViewerId);
93 if((
int)$aGroup[
'parent_id'] != 0 && $this->
isGroupMember($aGroup[
'parent_id'], $iObjectOwnerId, $iViewerId))
100 switch($aParams[
'type']) {
102 $sCacheFunction =
'fromCache';
103 $sCacheName = $this->_sGroupCache . $aParams[
'id'];
105 $sWhereClause =
"`id`='" . (int)$aParams[
'id'] .
"'";
109 $aIds = array($aParams[
'owner_id']);
110 if(isset($aParams[
'full']))
113 $sCacheFunction =
'fromMemory';
114 $sCacheName = $this->_sGroupsByOwnersCache . implode(
"_", $aIds);
116 $sWhereClause =
"`owner_id` IN ('" . implode(
"','", $aIds) .
"')";
120 $$sCacheFunction =
'';
123 $sWhereClause =
"(`owner_id`='0' AND `get_content`<>'') OR `owner_id`='" . (int)$aParams[
'owner_id'] .
"'";
135 FROM `sys_privacy_groups`
136 WHERE " . $sWhereClause;
138 return !
empty($sCacheFunction) && !
empty($sCacheName) ? $this->$sCacheFunction($sCacheName, $sMethod, $sSql) : $this->$sMethod($sSql);
142 if(is_array($mixedValues)) {
143 foreach ($mixedValues
as $k => $v)
144 $mixedValues[$k] = (int)$v;
145 $sGroupIds = implode(
"','", $mixedValues);
146 }
else if(is_string($mixedValues)) {
150 $this->
query(
"DELETE FROM `sys_privacy_members` WHERE `group_id` IN ('" . $sGroupIds .
"')");
151 $this->
query(
"DELETE FROM `sys_privacy_groups` WHERE `id` IN ('" . $sGroupIds .
"')");
155 $sSql =
"SELECT `member_id` AS `id` FROM `sys_privacy_members` WHERE `group_id`= ?";
156 return $this->
getAll($sSql, [$iGroupId]);
162 $iCount += $this->
query(
"INSERT IGNORE INTO `sys_privacy_members` SET `group_id`='" . $iGroupId .
"', `member_id`='" . (
int)
$iMemberId .
"'");
163 $this->
cleanCache($this->_sGroupMembersCache . $iGroupId);
165 $this->
query(
"UPDATE `sys_privacy_groups` SET `members_count`=`members_count`+'" . $iCount .
"' WHERE `id`='" . $iGroupId .
"' LIMIT 1");
166 $this->
cleanCache($this->_sGroupCache . $iGroupId);
170 foreach ($aMemberIds
as $k => $v)
171 $aMemberIds[$k] = (int)$v;
172 $iCount = $this->
query(
"DELETE FROM `sys_privacy_members` WHERE `group_id`='" . $iGroupId .
"' AND `member_id` IN ('" . implode(
"','", $aMemberIds) .
"')");
173 $this->
cleanCache($this->_sGroupMembersCache . $iGroupId);
175 $this->
query(
"UPDATE `sys_privacy_groups` SET `members_count`=`members_count`-'" . $iCount .
"' WHERE `id`='" . $iGroupId .
"' LIMIT 1");
176 $this->
cleanCache($this->_sGroupCache . $iGroupId);
181 $sSql =
"SELECT `PrivacyDefaultGroup` FROM `Profiles` WHERE `ID`='" . $iOwnerId .
"' LIMIT 1";
182 return $this->
getOne($sSql);
186 $sSql =
"UPDATE `Profiles` SET `PrivacyDefaultGroup`='" . $iGroupId .
"' WHERE `ID`='" . $iOwnerId .
"'";
187 return (
int)$this->
query($sSql);
192 `tm`.`uri` AS `module_uri`,
193 `tm`.`title` AS `module_title`,
194 `ta`.`id` AS `action_id`,
195 `ta`.`title` AS `action_title`,
196 `ta`.`default_group` AS `action_default_value`,
197 `td`.`group_id` AS `default_value`
198 FROM `sys_privacy_actions` AS `ta`
199 LEFT JOIN `sys_privacy_defaults` AS `td` ON `ta`.`id`=`td`.`action_id` AND `td`.`owner_id`= ?
200 INNER JOIN `sys_modules` AS `tm` ON `ta`.`module_uri`=`tm`.`uri`
202 ORDER BY `tm`.`title`";
203 return $this->
getAll($sSql, [$iOwnerId]);
209 FROM `sys_privacy_actions` AS `ta`
210 LEFT JOIN `sys_privacy_defaults` AS `td` ON `ta`.`id`=`td`.`action_id` AND `td`.`owner_id`='" . $iOwnerId .
"'
211 WHERE `ta`.`module_uri`='" . $sModuleUri .
"' AND `ta`.`name`='" . $sActionName .
"'
213 return $this->
fromMemory($this->_sActionDefaultCache . $sModuleUri .
'_' . $sActionName .
'_' . $iOwnerId,
'getOne', $sSql);
217 $aAction = $this->
_getAction($sModuleUri, $sActionName);
218 return !
empty($aAction) && isset($aAction[
'default_group']) ? $aAction[
'default_group'] :
CH_WSB_PG_ALL;
222 $sSql =
"REPLACE INTO `sys_privacy_defaults` SET `owner_id`='" . $iOwnerId .
"', `action_id`='" . $iActionId .
"', `group_id`='" . $iGroupId .
"'";
223 return $this->
query($sSql);
227 $aAction = $this->
_getAction($sModuleUri, $sActionName);
228 return !
empty($aAction) && isset($aAction[
'title']) ? $aAction[
'title'] :
'';
242 FROM `sys_privacy_actions` AS `ta`
243 WHERE `module_uri`= ? AND `name`= ?
245 return $this->
fromCache($this->_sActionCache . $sModuleUri .
'_' . $sActionName,
'getRow', $sSql, [$sModuleUri, $sActionName]);