BxBaseModGroupsPrivacyPost.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_PARTICIPANTS', 'p');
  12. define('BX_BASE_MOD_GROUPS_PG_FOLLOWERS', 'f');
  13. class BxBaseModGroupsPrivacyPost extends BxBaseModProfilePrivacyPost
  14. {
  15. public function __construct($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct($aOptions, $oTemplate);
  18. $this->_aGroupsExclude = array(BX_DOL_PG_FRIENDS, BX_DOL_PG_RELATIONS);
  19. }
  20. /**
  21. * Check whethere viewer is a member of dynamic group.
  22. *
  23. * @param mixed $mixedGroupId dynamic group ID.
  24. * @param integer $iObjectOwnerId object owner ID.
  25. * @param integer $iViewerId viewer ID.
  26. * @return boolean result of operation.
  27. */
  28. public function isDynamicGroupMember($mixedGroupId, $iObjectOwnerId, $iViewerId, $iObjectId)
  29. {
  30. if($mixedGroupId == BX_BASE_MOD_GROUPS_PG_PARTICIPANTS)
  31. return $this->isParticipantAccess($iObjectOwnerId, $iViewerId, $iObjectId);
  32. if($mixedGroupId == BX_BASE_MOD_GROUPS_PG_FOLLOWERS)
  33. return $this->isFollowersAccess($iObjectOwnerId, $iViewerId, $iObjectId);
  34. return false;
  35. }
  36. public function isParticipantAccess ($iObjectOwnerId, $iViewerId, $iObjectId)
  37. {
  38. $oConnection = BxDolConnection::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS']);
  39. if(!$oConnection)
  40. return false;
  41. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iObjectId, $this->_sModule);
  42. return $oConnection->isConnected($iViewerId, $oGroupProfile->id(), true);
  43. }
  44. public function isFollowersAccess ($iObjectOwnerId, $iViewerId, $iObjectId)
  45. {
  46. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  47. if(!$oConnection)
  48. return false;
  49. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iObjectId, $this->_sModule);
  50. return $oConnection->isConnected($iViewerId, $oGroupProfile->id());
  51. }
  52. static function getGroupChooser ($sObject, $iOwnerId = 0, $aParams = array())
  53. {
  54. $oPrivacy = BxDolPrivacy::getObjectInstance($sObject);
  55. if(empty($oPrivacy))
  56. return array();
  57. $CNF = &$oPrivacy->_oModule->_oConfig->CNF;
  58. if (!$iOwnerId)
  59. $iOwnerId = bx_get_logged_profile_id();
  60. $aParams['dynamic_groups'] = array(
  61. array ('key' => '', 'value' => '----'),
  62. array ('key' => BX_BASE_MOD_GROUPS_PG_PARTICIPANTS, 'value' => _t(!empty($CNF['T']['txt_group_participants']) ? $CNF['T']['txt_group_participants'] : '_sys_ps_group_title_participants')),
  63. array ('key' => BX_BASE_MOD_GROUPS_PG_FOLLOWERS, 'value' => _t(!empty($CNF['T']['txt_group_followers']) ? $CNF['T']['txt_group_followers'] : '_sys_ps_group_title_followers'))
  64. );
  65. return parent::getGroupChooser($sObject, $iOwnerId, $aParams);
  66. }
  67. protected function getObjectInfo($sAction, $iObjectId)
  68. {
  69. return BxDolPrivacy::getObjectInfo($sAction, $iObjectId);
  70. }
  71. }
  72. /** @} */