BxBaseModGroupsPrivacy.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. $this->_aPrivacyParticallyVisible = array_merge($this->_aPrivacyParticallyVisible, array('c', BX_DOL_PG_FRIENDS));
  17. }
  18. /**
  19. * Check whethere viewer is a member of dynamic group.
  20. *
  21. * @param mixed $mixedGroupId dynamic group ID.
  22. * @param integer $iObjectOwnerId object owner ID.
  23. * @param integer $iViewerId viewer ID.
  24. * @return boolean result of operation.
  25. */
  26. public function isDynamicGroupMember($mixedGroupId, $iObjectOwnerId, $iViewerId, $iObjectId)
  27. {
  28. if ('c' == $mixedGroupId)
  29. return $this->isClosedGroupAccess($iObjectOwnerId, $iViewerId, $iObjectId);
  30. if ('s' == $mixedGroupId)
  31. return $this->isSecretGroupAccess($iObjectOwnerId, $iViewerId, $iObjectId);
  32. return false;
  33. }
  34. public function isClosedGroupAccess ($iObjectOwnerId, $iViewerId, $iObjectId)
  35. {
  36. if (!($oConnection = BxDolConnection::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS'])))
  37. return false;
  38. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iObjectId, $this->MODULE);
  39. return $oConnection->isConnected($iViewerId, $oGroupProfile->id(), true);
  40. }
  41. public function isSecretGroupAccess ($iObjectOwnerId, $iViewerId, $iObjectId)
  42. {
  43. return $this->isClosedGroupAccess($iObjectOwnerId, $iViewerId, $iObjectId);
  44. }
  45. static function getGroupChooser ($sObject, $iOwnerId = 0, $aParams = array())
  46. {
  47. if (!$iOwnerId)
  48. $iOwnerId = bx_get_logged_profile_id();
  49. $aParams['dynamic_groups'] = array(
  50. array ('key' => '', 'value' => '----'),
  51. array ('key' => 'c', 'value' => _t('_sys_ps_group_title_closed')),
  52. array ('key' => 's', 'value' => _t('_sys_ps_group_title_secret')),
  53. );
  54. return parent::getGroupChooser($sObject, $iOwnerId, $aParams);
  55. return $a;
  56. }
  57. protected function getGroups()
  58. {
  59. $a = parent::getGroups();
  60. foreach ($a as $i => $r) {
  61. if (BX_DOL_PG_FRIENDS == $r['key']) {
  62. unset($a[$i]);
  63. break;
  64. }
  65. }
  66. return $a;
  67. }
  68. protected function getObjectInfo($sAction, $iObjectId)
  69. {
  70. return BxDolPrivacy::getObjectInfo($sAction, $iObjectId);
  71. }
  72. }
  73. /** @} */