BxBaseModGroupsPrivacy.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_BASE_MOD_GROUPS_PG_CLOSED', 'c');
  12. define('BX_BASE_MOD_GROUPS_PG_SECRET', 's');
  13. class BxBaseModGroupsPrivacy extends BxBaseModProfilePrivacy
  14. {
  15. public function __construct($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct($aOptions, $oTemplate);
  18. $this->_aGroupsExclude = array(BX_DOL_PG_FRIENDS);
  19. $this->_aPrivacyParticallyVisible = array('c');
  20. }
  21. /**
  22. * Check whethere viewer is a member of dynamic group.
  23. *
  24. * @param mixed $mixedGroupId dynamic group ID.
  25. * @param integer $iObjectOwnerId object owner ID.
  26. * @param integer $iViewerId viewer ID.
  27. * @return boolean result of operation.
  28. */
  29. public function isDynamicGroupMember($mixedGroupId, $iObjectOwnerId, $iViewerId, $iObjectId)
  30. {
  31. if ($mixedGroupId == BX_BASE_MOD_GROUPS_PG_CLOSED)
  32. return $this->isClosedGroupAccess($iObjectOwnerId, $iViewerId, $iObjectId);
  33. if ($mixedGroupId == BX_BASE_MOD_GROUPS_PG_SECRET)
  34. return $this->isSecretGroupAccess($iObjectOwnerId, $iViewerId, $iObjectId);
  35. return false;
  36. }
  37. public function isClosedGroupAccess ($iObjectOwnerId, $iViewerId, $iObjectId)
  38. {
  39. if (!($oConnection = BxDolConnection::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS'])))
  40. return false;
  41. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iObjectId, $this->MODULE);
  42. return $oConnection->isConnected($iViewerId, $oGroupProfile->id(), true);
  43. }
  44. public function isSecretGroupAccess ($iObjectOwnerId, $iViewerId, $iObjectId)
  45. {
  46. return $this->isClosedGroupAccess($iObjectOwnerId, $iViewerId, $iObjectId);
  47. }
  48. static function getGroupChooser ($sObject, $iOwnerId = 0, $aParams = array())
  49. {
  50. if (!$iOwnerId)
  51. $iOwnerId = bx_get_logged_profile_id();
  52. $aParams['dynamic_groups'] = array(
  53. array ('key' => '', 'value' => '----'),
  54. array ('key' => BX_BASE_MOD_GROUPS_PG_CLOSED, 'value' => _t('_sys_ps_group_title_closed')),
  55. array ('key' => BX_BASE_MOD_GROUPS_PG_SECRET, 'value' => _t('_sys_ps_group_title_secret')),
  56. );
  57. return parent::getGroupChooser($sObject, $iOwnerId, $aParams);
  58. }
  59. protected function getObjectInfo($sAction, $iObjectId)
  60. {
  61. return BxDolPrivacy::getObjectInfo($sAction, $iObjectId);
  62. }
  63. }
  64. /** @} */