BxDolPrivacy.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. define('BX_DOL_PG_HIDDEN', '1');
  10. define('BX_DOL_PG_MEONLY', '2');
  11. define('BX_DOL_PG_ALL', '3');
  12. define('BX_DOL_PG_MEMBERS', '4');
  13. define('BX_DOL_PG_FRIENDS', '5');
  14. define('BX_DOL_PG_FRIENDS_SELECTED', '6');
  15. define('BX_DOL_PG_RELATIONS', '7');
  16. define('BX_DOL_PG_RELATIONS_SELECTED', '8');
  17. define('BX_DOL_PG_CUSTOM', '9');
  18. define('BX_DOL_PG_DEFAULT', BX_DOL_PG_ALL);
  19. /**
  20. * Privacy settings for any content.
  21. *
  22. * Integration of the content with privacy engine allows site member
  23. * to organize the access to his content.
  24. *
  25. * In addition to regular privacy groups (Public, Friends), spaces are supported.
  26. * When some space (usually some another profile) is specified as privacy,
  27. * then another profile visibility is used to check the privacy.
  28. *
  29. * Related classes:
  30. * BxDolPrivacyQuery - database queries.
  31. *
  32. * Example of usage:
  33. * 1. Register your privacy actions in `sys_privacy_actions` database table.
  34. * 2. Add one privacy field(with INT type) in the table with your items for each action.
  35. * For example, for action 'comment', the field name should be 'allow_comment_to'.
  36. * 3. Add group choosers for necessary actions in the form, which is used to add new items.
  37. * @code
  38. * $oPrivacy = new BxDolPrivacy();
  39. * $oPrivacy->getGroupChooser($iItemOwnerId, $sModuleUri, $sModuleAction);
  40. * @endcode
  41. *
  42. * 4. Check privacy when any user tries to view an item.
  43. * @code
  44. * $oPrivacy = new BxDolPrivacy($sTable, $sFieldId, $sFieldOwnerId);
  45. * if($oPrivacy->check($sAction, $iObjectId, $iViewerId)) {
  46. * //show necessary content
  47. * }
  48. * @endcode
  49. *
  50. * @see an example of integration in BoonEx modules, for example: Posts
  51. *
  52. *
  53. * Memberships/ACL:
  54. * Doesn't depend on user's membership.
  55. *
  56. *
  57. * Alerts:
  58. * no alerts available
  59. *
  60. */
  61. class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
  62. {
  63. protected $_oDb;
  64. protected $_sObject;
  65. protected $_aObject;
  66. protected $_aGroupsSettings;
  67. protected $_aGroupsExclude;
  68. protected $_sFormUsers;
  69. protected $_sFormDisplayUsersSelect;
  70. /**
  71. * Constructor
  72. * @param $aObject array of grid options
  73. */
  74. protected function __construct($aObject)
  75. {
  76. parent::__construct();
  77. $this->_aObject = $aObject;
  78. $this->_sObject = $aObject['object'];
  79. $this->_oDb = new BxDolPrivacyQuery();
  80. $this->_oDb->init($this->_aObject);
  81. $this->_aGroupsSettings = array(
  82. BX_DOL_PG_FRIENDS_SELECTED => array('connection' => 'sys_profiles_friends'),
  83. BX_DOL_PG_RELATIONS_SELECTED => array('connection' => 'sys_profiles_relations')
  84. );
  85. $this->_aGroupsExclude = array();
  86. $this->_sFormUsers = 'sys_privacy_group_custom';
  87. $this->_sFormDisplayUsersSelect = 'sys_privacy_group_custom_manage';
  88. }
  89. /**
  90. * Get privacy object instance by object name
  91. * @param $sObject object name
  92. * @return object instance or false on error
  93. */
  94. public static function getObjectInstance($sObject)
  95. {
  96. if(isset($GLOBALS['bxDolClasses']['BxDolPrivacy!' . $sObject]))
  97. return $GLOBALS['bxDolClasses']['BxDolPrivacy!' . $sObject];
  98. $aObject = BxDolPrivacyQuery::getPrivacyObject($sObject);
  99. if(!$aObject || !is_array($aObject))
  100. return false;
  101. $sClass = 'BxTemplPrivacy';
  102. if(!empty($aObject['override_class_name'])) {
  103. $sClass = $aObject['override_class_name'];
  104. if(!empty($aObject['override_class_file']))
  105. require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
  106. }
  107. $o = new $sClass($aObject);
  108. return ($GLOBALS['bxDolClasses']['BxDolPrivacy!' . $sObject] = $o);
  109. }
  110. /**
  111. * Get Select element with available groups.
  112. *
  113. * @param string $sObject privacy object name.
  114. * @param integer $iOwnerId object's owner ID.
  115. * @param array $aParams an array of custom selector's params (dynamic_groups - an array of arrays('key' => group_id, 'value' => group_title), title - the title to be used for generated field).
  116. * @return an array with Select element description.
  117. */
  118. public static function getGroupChooser($sObject, $iOwnerId = 0, $aParams = array())
  119. {
  120. $oPrivacy = BxDolPrivacy::getObjectInstance($sObject);
  121. if(empty($oPrivacy))
  122. return array();
  123. $sModule = $oPrivacy->_aObject['module'];
  124. $sAction = $oPrivacy->_aObject['action'];
  125. if($iOwnerId == 0)
  126. $iOwnerId = bx_get_logged_profile_id();
  127. $sValue = $oPrivacy->_oDb->getDefaultGroupByUser($sModule, $sAction, $iOwnerId);
  128. if(empty($sValue))
  129. $sValue = $oPrivacy->_oDb->getDefaultGroup($sModule, $sAction);
  130. $aValues = $oPrivacy->getGroups();
  131. $aValues = $oPrivacy->addDynamicGroups($aValues, $iOwnerId, $aParams);
  132. $aValues = $oPrivacy->addAclGroups($aValues, $iOwnerId, $aParams);
  133. $aValues = $oPrivacy->addSpaces($aValues, $iOwnerId, $aParams);
  134. $sName = $oPrivacy->convertActionToField($sAction);
  135. $sTitle = isset($aParams['title']) && !empty($aParams['title']) ? $aParams['title'] : '';
  136. if(empty($sTitle)) {
  137. $sTitle = $oPrivacy->_oDb->getTitle($sModule, $sAction);
  138. $sTitle = _t(!empty($sTitle) ? $sTitle : '_' . $sName);
  139. }
  140. BxDolTemplate::getInstance()->addInjection('system_injection_header', 'text', $oPrivacy->getJsScript());
  141. return array(
  142. 'type' => 'select',
  143. 'name' => $sName,
  144. 'caption' => $sTitle,
  145. 'value' => $sValue,
  146. 'values' => $aValues,
  147. 'attrs' => array(
  148. 'class' => 'sys-privacy-group',
  149. 'onchange' => 'javascript: ' . $oPrivacy->getJsObjectName() . '.selectGroup(this);'
  150. ),
  151. 'checker' => array(
  152. 'func' => 'avail',
  153. 'error' => _t('_sys_ps_ferr_incorrect_select')
  154. ),
  155. 'db' => array(
  156. 'pass' => 'Int'
  157. )
  158. );
  159. }
  160. public function actionLoadGroupCustom()
  161. {
  162. $iProfileId = (int)bx_get('profile_id');
  163. $iContentId = (int)bx_get('content_id');
  164. $iGroupId = (int)bx_get('group_id');
  165. $oForm = BxDolForm::getObjectInstance($this->_sFormUsers, $this->_sFormDisplayUsersSelect);
  166. return echoJson(array('eval' => $this->getJsObjectName() . '.onSelectGroup(oData);', 'content' => $oForm->getElementGroupCustom(array(
  167. 'profile_id' => $iProfileId,
  168. 'content_id' => $iContentId,
  169. 'object' => $this->_sObject,
  170. 'group_id' => $iGroupId
  171. ))));
  172. }
  173. public function actionSelectGroup()
  174. {
  175. $aValues = array(
  176. 'profile_id' => (int)bx_get('profile_id'),
  177. 'content_id' => (int)bx_get('content_id'),
  178. 'object' => $this->_sObject,
  179. 'group_id' => (int)bx_get('group_id')
  180. );
  181. $aParams = array(
  182. 'popup_only' => (bool)bx_get('popup_only')
  183. );
  184. if(!isset($this->_aGroupsSettings[$aValues['group_id']]))
  185. return echoJson(array());
  186. if($aValues['profile_id'] != bx_get_logged_profile_id())
  187. return echoJson(array('msg' => _t('_sys_ps_ferr_incorrect_gc_owner')));
  188. if(($mixedResult = $this->isSelectGroupCustom($aValues)) !== true)
  189. return echoJson(array('msg' => $mixedResult));
  190. return echoJson($this->getSelectGroup($aValues, $aParams));
  191. }
  192. public function actionUsersList()
  193. {
  194. $iGroup = (int)bx_get('group');
  195. if(!isset($this->_aGroupsSettings[$iGroup]))
  196. return echoJson(array());
  197. $oConnection = BxDolConnection::getObjectInstance($this->_aGroupsSettings[$iGroup]['connection']);
  198. if(!$oConnection)
  199. return echoJson(array());
  200. $iProfileId = bx_get_logged_profile_id();
  201. $aConnectedIds = $oConnection->getConnectedContent($iProfileId, true);
  202. if(empty($aConnectedIds) || !is_array($aConnectedIds))
  203. return echoJson(array());
  204. $sTerm = bx_get('term');
  205. $aProfiles = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  206. if(empty($aProfiles))
  207. return echoJson(array());
  208. $aResult = array();
  209. foreach($aProfiles as $aProfile)
  210. if(in_array($aProfile['value'], $aConnectedIds))
  211. $aResult[] = $aProfile;
  212. echoJson($aResult);
  213. }
  214. public function loadGroupCustom($iProfileId, $iContentId, $iGroupId)
  215. {
  216. $sJsCode = $this->_oTemplate->_wrapInTagJsCode($this->getJsObjectName() . ".loadGroupCustom(" . json_encode(array(
  217. 'profile_id' => $iProfileId,
  218. 'content_id' => $iContentId,
  219. 'group_id' => $iGroupId
  220. )) . ");");
  221. BxDolTemplate::getInstance()->addInjection('system_injection_header', 'text', $sJsCode);
  222. }
  223. public function getGroupSettings($iGroup)
  224. {
  225. if(empty($this->_aGroupsSettings[$iGroup]) || !is_array($this->_aGroupsSettings[$iGroup]))
  226. return false;
  227. return $this->_aGroupsSettings[$iGroup];
  228. }
  229. public function getGroupCustom($aParams)
  230. {
  231. return $this->_oDb->getGroupCustom($aParams);
  232. }
  233. public function updateGroupCustom($aParamsSet, $aParamsWhere)
  234. {
  235. return $this->_oDb->updateGroupCustom($aParamsSet, $aParamsWhere);
  236. }
  237. public function deleteGroupCustom($aParamsWhere)
  238. {
  239. return $this->_oDb->deleteGroupCustom($aParamsWhere);
  240. }
  241. public function associateGroupCustomWithContent($iProfileId, $iContentId, $iGroupId)
  242. {
  243. return $this->updateGroupCustom(array('content_id' => $iContentId), array(
  244. 'profile_id' => $iProfileId,
  245. 'content_id' => 0,
  246. 'object' => $this->_sObject,
  247. 'group_id' => $iGroupId
  248. ));
  249. }
  250. public function reassociateGroupCustomWithContent($iProfileId, $iContentId, $iGroupId)
  251. {
  252. $aGroupCustom = $this->getGroupCustom(array(
  253. 'type' => 'pco',
  254. 'profile_id' => $iProfileId,
  255. 'content_id' => $iContentId,
  256. 'object' => $this->_sObject
  257. ));
  258. if(!empty($aGroupCustom) && is_array($aGroupCustom) && $aGroupCustom['group_id'] != $iGroupId)
  259. $this->deleteGroupCustom(array('id' => $aGroupCustom['id']));
  260. return $this->associateGroupCustomWithContent($iProfileId, $iContentId, $iGroupId);
  261. }
  262. public function deleteGroupCustomByContentId($iContentId)
  263. {
  264. return $this->_oDb->deleteGroupCustom(array('content_id' => $iContentId, 'object' => $this->_sObject));
  265. }
  266. public function deleteGroupCustomByProfileId($iProfileId)
  267. {
  268. $aGroups = $this->_oDb->getGroupCustom(array('type' => 'profile_id', 'profile_id' => $iProfileId));
  269. if(empty($aGroups) || !is_array($aGroups))
  270. return true;
  271. foreach($aGroups as $aGroup)
  272. $this->_oDb->deleteGroupCustom(array('id' => $aGroup['id']));
  273. return true;
  274. }
  275. public function addDynamicGroups($aValues, $iOwnerId, $aParams)
  276. {
  277. if (isset($aParams['dynamic_groups']) && is_array($aParams['dynamic_groups']))
  278. $aValues = array_merge($aValues, $aParams['dynamic_groups']);
  279. return $aValues;
  280. }
  281. public function addAclGroups($aValues, $iOwnerId, $aParams)
  282. {
  283. $aLevels = BxDolAcl::getInstance()->getMemberships(false, true, true, true);
  284. if(empty($aLevels) || !is_array($aLevels))
  285. return $aValues;
  286. $aValues[] = array('type' => 'group_header', 'value' => mb_strtoupper(_t('_sys_privacy_groups_acl')));
  287. foreach($aLevels as $iId => $sTitle)
  288. $aValues[] = array('key' => 'ml' . $iId, 'value' => $sTitle);
  289. $aValues[] = array('type' => 'group_end');
  290. return $aValues;
  291. }
  292. public function addSpaces($aValues, $iOwnerId, $aParams)
  293. {
  294. if (!$this->_aObject['spaces'])
  295. return $aValues;
  296. if (!($oProfile = BxDolProfile::getInstance($iOwnerId)))
  297. return $aValues;
  298. if (!($aModules = BxDolModuleQuery::getInstance()->getModules()))
  299. return $aValues;
  300. $bProfileProcessed = true; // don't allow to post to profiles for now
  301. foreach ($aModules as $aModule) {
  302. if (!$aModule['enabled'])
  303. continue;
  304. if ('all' != $this->_aObject['spaces'] && false === stripos($this->_aObject['spaces'], $aModule['name']))
  305. continue;
  306. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  307. continue;
  308. $bActAsProfile = BxDolService::call($aModule['name'], 'act_as_profile');
  309. if ($bActAsProfile && $bProfileProcessed)
  310. continue;
  311. if ($bActAsProfile)
  312. $bProfileProcessed = true;
  313. $a = BxDolService::call($aModule['name'], 'get_participating_profiles', array($oProfile->id()));
  314. $aSpaces = array();
  315. foreach ($a as $iProfileId) {
  316. if (!($o = BxDolProfile::getInstance($iProfileId)))
  317. continue;
  318. $aSpaces[-$iProfileId] = array('key' => -$iProfileId, 'value' => $o->getDisplayName());
  319. }
  320. if ($aSpaces) {
  321. $aItemStart = array(array('type' => 'group_header', 'value' => mb_strtoupper(BxDolService::call($aModule['name'], 'get_space_title'))));
  322. $aItemEnd = array(array('type' => 'group_end'));
  323. $aValues = array_merge($aValues, $aItemStart, array_values($aSpaces), $aItemEnd);
  324. }
  325. }
  326. return $aValues;
  327. }
  328. /**
  329. * Get database field name for action.
  330. *
  331. * @param string $sObject privacy object name.
  332. * @param string $sAction action name.
  333. * @return string with field name.
  334. */
  335. public static function getFieldName($sObject, $sAction = '')
  336. {
  337. $oPrivacy = BxDolPrivacy::getObjectInstance($sObject);
  338. if(empty($oPrivacy))
  339. return '';
  340. if(empty($sAction))
  341. $sAction = $oPrivacy->_aObject['action'];
  342. return $oPrivacy->convertActionToField($sAction);
  343. }
  344. /**
  345. * Get necessary condition array to use privacy in search classes
  346. * @param $mixedGroupId group ID or array of group IDs
  347. * @return array of conditions, for now with 'restriction' part only is returned
  348. */
  349. public function getContentByGroupAsCondition($mixedGroupId)
  350. {
  351. $aResult = array(
  352. 'restriction' => array (
  353. 'privacy_' . $this->_sObject => array(
  354. 'value' => $mixedGroupId,
  355. 'field' => $this->convertActionToField($this->_aObject['action']),
  356. 'operator' => is_array($mixedGroupId) ? 'in' : '=',
  357. 'table' => $this->_aObject['table'],
  358. ),
  359. ),
  360. );
  361. bx_alert('system', 'privacy_condition', 0, false, array(
  362. 'group_id' => $mixedGroupId,
  363. 'field' => $this->convertActionToField($this->_aObject['action']),
  364. 'object' => $this->_aObject,
  365. 'privacy_object' => $this,
  366. 'result' => &$aResult
  367. )
  368. );
  369. return $aResult;
  370. }
  371. /**
  372. * Get necessary condition array to use privacy in search classes
  373. * @param $iProfileIdOwner owner profile ID
  374. * @return array of conditions, for now with 'restriction' part only is returned
  375. */
  376. public function getContentPublicAsCondition($iProfileIdOwner = 0, $aCustomGroups = array())
  377. {
  378. $mixedPrivacyGroups = $this->getPrivacyGroupsForContentPublic($iProfileIdOwner, $aCustomGroups);
  379. if($mixedPrivacyGroups === true)
  380. return array();
  381. return $this->getContentByGroupAsCondition($mixedPrivacyGroups);
  382. }
  383. /**
  384. * Get necessary parts of SQL query to use privacy in other queries
  385. * @param $mixedGroupId group ID or array of group IDs
  386. * @return array of SQL string parts, for now 'where' part only is returned
  387. */
  388. public function getContentByGroupAsSQLPart($mixedGroupId)
  389. {
  390. $sField = $this->convertActionToField($this->_aObject['action']);
  391. return $this->_oDb->getContentByGroupAsSQLPart($sField, $mixedGroupId);
  392. }
  393. /**
  394. * Get necessary parts of SQL query to use privacy in other queries
  395. * @param $iProfileIdOwner owner profile ID
  396. * @return array of SQL string parts, for now 'where' part only is returned
  397. */
  398. public function getContentPublicAsSQLPart($iProfileIdOwner = 0, $aCustomGroups = array())
  399. {
  400. $mixedPrivacyGroups = $this->getPrivacyGroupsForContentPublic($iProfileIdOwner, $aCustomGroups);
  401. if($mixedPrivacyGroups === true)
  402. return array();
  403. return $this->getContentByGroupAsSQLPart($mixedPrivacyGroups);
  404. }
  405. /**
  406. * Check whether the viewer can make requested action.
  407. *
  408. * @param integer $iObjectId object ID the action to be performed with.
  409. * @param integer $iViewerId viewer ID.
  410. * @return boolean result of operation.
  411. */
  412. public function check($iObjectId, $iViewerId = 0)
  413. {
  414. if(empty($iViewerId))
  415. $iViewerId = (int)bx_get_logged_profile_id();
  416. $aObject = $this->getObjectInfo($this->convertActionToField($this->_aObject['action']), $iObjectId);
  417. if(empty($aObject) || !is_array($aObject))
  418. return false;
  419. if($aObject['group_id'] == BX_DOL_PG_HIDDEN)
  420. return false;
  421. if(isAdmin() || $iViewerId == $aObject['owner_id'])
  422. return true;
  423. if(strncmp($aObject['group_id'], 'ml', 2) === 0) {
  424. $iLevel = (int)substr($aObject['group_id'], 2);
  425. return (bool)BxDolAcl::getInstance()->isMemberLevelInSet(array($iLevel), $iViewerId);
  426. }
  427. if($aObject['group_id'] < 0)
  428. return $this->checkSpace($aObject, $iViewerId);
  429. $aGroup = $this->_oDb->getGroupsBy(array('type' => 'id', 'id' => $aObject['group_id']));
  430. if(!empty($aGroup) && is_array($aGroup) && (int)$aGroup['active'] == 1 && !empty($aGroup['check'])) {
  431. $sCheckMethod = $this->getCheckMethod($aGroup['check']);
  432. if(method_exists($this, $sCheckMethod) && $this->$sCheckMethod((substr($sCheckMethod, -8) == 'ByObject' ? $aObject : $aObject['owner_id']), $iViewerId))
  433. return true;
  434. }
  435. return $this->isDynamicGroupMember($aObject['group_id'], $aObject['owner_id'], $iViewerId, $iObjectId);
  436. }
  437. public function checkSpace($aObject, $iViewerId)
  438. {
  439. $oProfile = BxDolProfile::getInstance(-$aObject['group_id']);
  440. if (!$oProfile)
  441. return false;
  442. return CHECK_ACTION_RESULT_ALLOWED === BxDolService::call($oProfile->getModule(), 'check_space_privacy', array($oProfile->getContentId()));
  443. }
  444. public function checkMeOnly($iOwnerId, $iViewerId)
  445. {
  446. return false;
  447. }
  448. public function checkPublic($iOwnerId, $iViewerId)
  449. {
  450. return true;
  451. }
  452. public function checkMembers($iOwnerId, $iViewerId)
  453. {
  454. return isMember();
  455. }
  456. public function checkFriends($iOwnerId, $iViewerId)
  457. {
  458. return BxDolConnection::getObjectInstance('sys_profiles_friends')->isConnected($iOwnerId, $iViewerId, true);
  459. }
  460. public function checkFriendsSelectedByObject($aObject, $iViewerId)
  461. {
  462. if(!$this->checkFriends($aObject['owner_id'], $iViewerId))
  463. return false;
  464. $aGroupCustom = $this->getGroupCustom(array(
  465. 'type' => 'pcog_ext',
  466. 'profile_id' => $aObject['owner_id'],
  467. 'content_id' => $aObject['id'],
  468. 'object' => $this->_sObject,
  469. 'group_id' => $aObject['group_id']
  470. ));
  471. return !empty($aGroupCustom['members']) && is_array($aGroupCustom['members']) && in_array($iViewerId, $aGroupCustom['members']);
  472. }
  473. public function checkRelations($iOwnerId, $iViewerId)
  474. {
  475. return BxDolConnection::getObjectInstance('sys_profiles_relations')->isConnected($aObject['owner_id'], $iViewerId, true);
  476. }
  477. public function checkRelationsSelectedByObject($aObject, $iViewerId)
  478. {
  479. if(!$this->checkRelations($aObject['owner_id'], $iViewerId))
  480. return false;
  481. $aGroupCustom = $this->getGroupCustom(array(
  482. 'type' => 'pcog_ext',
  483. 'profile_id' => $aObject['owner_id'],
  484. 'content_id' => $aObject['id'],
  485. 'object' => $this->_sObject,
  486. 'group_id' => $aObject['group_id']
  487. ));
  488. return !empty($aGroupCustom['members']) && is_array($aGroupCustom['members']) && in_array($iViewerId, $aGroupCustom['members']);
  489. }
  490. public function checkCustomByObject($aObject, $iViewerId)
  491. {
  492. return '';
  493. }
  494. public function setTableFieldAuthor($sValue)
  495. {
  496. $this->_aObject['table_field_author'] = $sValue;
  497. $this->_oDb->init($this->_aObject);
  498. }
  499. protected function getObjectInfo($sAction, $iObjectId)
  500. {
  501. return $this->_oDb->getObjectInfo($sAction, $iObjectId);
  502. }
  503. protected function getPrivacyGroupsForContentPublic($iProfileIdOwner = 0, $aCustomGroups = array())
  504. {
  505. $aGroups = array(BX_DOL_PG_ALL);
  506. if(isLogged()) {
  507. $iProfileIdLogged = bx_get_logged_profile_id();
  508. if($iProfileIdLogged == $iProfileIdOwner)
  509. return true;
  510. $aGroups[] = BX_DOL_PG_MEMBERS;
  511. if($iProfileIdOwner && $this->checkFriends($iProfileIdOwner, $iProfileIdLogged))
  512. $aGroups[] = BX_DOL_PG_FRIENDS;
  513. }
  514. return array_merge($aGroups, $aCustomGroups);
  515. }
  516. protected function getCheckMethod($s)
  517. {
  518. if(substr($s, 0, 1) != '@')
  519. return false;
  520. return bx_gen_method_name(str_replace('@', 'check_', $s));
  521. }
  522. protected function convertActionToField($sAction)
  523. {
  524. return 'allow_' . strtolower(str_replace(' ', '-', $sAction)) . '_to';
  525. }
  526. /**
  527. * Check whethere viewer is a member of dynamic group.
  528. *
  529. * @param mixed $mixedGroupId dynamic group ID.
  530. * @param integer $iObjectOwnerId object owner ID.
  531. * @param integer $iViewerId viewer ID.
  532. * @return boolean result of operation.
  533. */
  534. protected function isDynamicGroupMember($mixedGroupId, $iObjectOwnerId, $iViewerId, $iObjectId)
  535. {
  536. return false;
  537. }
  538. /**
  539. * get privacy groups for getGroupChooser
  540. */
  541. protected function getGroups()
  542. {
  543. $aValues = array();
  544. $aGroups = $this->_oDb->getGroupsBy(array('type' => 'active'));
  545. foreach($aGroups as $aGroup) {
  546. if((int)$aGroup['active'] == 0 || in_array($aGroup['id'], $this->_aGroupsExclude))
  547. continue;
  548. $aValues[] = array('key' => $aGroup['id'], 'value' => _t($aGroup['title']));
  549. }
  550. return $aValues;
  551. }
  552. /**
  553. * Check whethere custom group is allowed in current circumstances.
  554. * NOTE. Can be overwritten if it's needed.
  555. *
  556. * @param type $aParams an array of parameters.
  557. * @return boolean result of operation.
  558. */
  559. protected function isSelectGroupCustom($aParams)
  560. {
  561. return true;
  562. }
  563. }
  564. /** @} */