BxBaseModGroupsPrivacy.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. }
  56. protected function getGroups()
  57. {
  58. $a = parent::getGroups();
  59. foreach ($a as $i => $r) {
  60. if (BX_DOL_PG_FRIENDS == $r['key']) {
  61. unset($a[$i]);
  62. break;
  63. }
  64. }
  65. return $a;
  66. }
  67. protected function getObjectInfo($sAction, $iObjectId)
  68. {
  69. return BxDolPrivacy::getObjectInfo($sAction, $iObjectId);
  70. }
  71. }
  72. /** @} */