BxBaseModGroupsPrivacy.php 2.3 KB

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