BxBaseModGroupsAlertsResponse.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 BxBaseModGroupsAlertsResponse extends BxBaseModProfileAlertsResponse
  12. {
  13. /*
  14. * Use Internal Notifications.
  15. */
  16. protected $_bUseIn;
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. $CNF = &$this->_oModule->_oConfig->CNF;
  21. $this->_bUseIn = true;
  22. if(isset($CNF['PARAM_USE_IN']))
  23. $this->_bUseIn = getParam($CNF['PARAM_USE_IN']) == 'on';
  24. }
  25. public function response($oAlert)
  26. {
  27. parent::response($oAlert);
  28. $CNF = &$this->_oModule->_oConfig->CNF;
  29. // connection events
  30. if (isset($CNF['OBJECT_CONNECTIONS']) && $CNF['OBJECT_CONNECTIONS'] == $oAlert->sUnit && 'connection_added' == $oAlert->sAction) {
  31. $this->_oModule->serviceAddMutualConnection($oAlert->aExtras['content'], $oAlert->aExtras['initiator']);
  32. }
  33. elseif (isset($CNF['OBJECT_CONNECTIONS']) && $CNF['OBJECT_CONNECTIONS'] == $oAlert->sUnit && 'connection_removed' == $oAlert->sAction) {
  34. $this->_oModule->serviceOnRemoveConnection($oAlert->aExtras['content'], $oAlert->aExtras['initiator']);
  35. }
  36. // profile delete event
  37. if ('profile' == $oAlert->sUnit && 'delete' == $oAlert->sAction) {
  38. $this->_oModule->serviceDeleteProfileFromFansAndAdmins($oAlert->iObject);
  39. $this->_oModule->serviceReassignEntitiesByAuthor($oAlert->iObject);
  40. }
  41. if ($this->MODULE != $oAlert->sUnit)
  42. return;
  43. // join group events
  44. switch ($oAlert->sAction) {
  45. case 'join_invitation':
  46. $this->sendMailInvitation($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  47. break;
  48. case 'join_request':
  49. if($this->_bUseIn)
  50. $this->sendMailJoinRequest($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  51. break;
  52. case 'join_request_accepted':
  53. if($this->_bUseIn)
  54. $this->sendMailJoinRequestAccepted($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
  55. break;
  56. }
  57. }
  58. protected function sendMailInvitation ($oAlert, $iInvited, $iInviter = 0)
  59. {
  60. $CNF = &$this->_oModule->_oConfig->CNF;
  61. $bTrackInvites = isset($CNF["TABLE_INVITES"]) && isset($CNF['OBJECT_CONNECTIONS']);
  62. if(!$this->_bUseIn && !$bTrackInvites)
  63. return;
  64. $sEntryUrl = $oAlert->aExtras['entry_url'];
  65. if($bTrackInvites) {
  66. if(!($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  67. return;
  68. if(!$oConnection->isConnected($iInviter, $oAlert->iSender))
  69. return;
  70. if($this->_oModule->_oDb->getInviteByInvited($iInvited, $oAlert->iSender) != 0)
  71. return;
  72. $sKey = BxDolKey::getInstance()->getNewKey(false, $CNF["INVITES_KEYS_LIFETIME"]);
  73. $this->_oModule->_oDb->insertInvite($sKey, $oAlert->iSender, $iInviter, $iInvited);
  74. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $oAlert->iObject . "&key=" . $sKey);
  75. }
  76. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_INVITATION'], 0, $iInvited, array(
  77. 'InviterUrl' => BxDolProfile::getInstance($iInviter)->getUrl(),
  78. 'InviterDisplayName' => BxDolProfile::getInstance($iInviter)->getDisplayName(),
  79. 'EntryUrl' => $sEntryUrl,
  80. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  81. ), BX_EMAIL_NOTIFY);
  82. }
  83. protected function sendMailJoinRequest ($oAlert, $iProfileId, $iSender = 0)
  84. {
  85. $aAdmins = $this->_oModule->_oDb->getAdmins($oAlert->aExtras['group_profile']);
  86. foreach ($aAdmins as $iAdminProfileId) {
  87. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_JOIN_REQUEST'], 0, $iAdminProfileId, array(
  88. 'NewMemberUrl' => BxDolProfile::getInstance($iProfileId)->getUrl(),
  89. 'NewMemberDisplayName' => BxDolProfile::getInstance($iProfileId)->getDisplayName(),
  90. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  91. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  92. ), BX_EMAIL_NOTIFY);
  93. }
  94. }
  95. protected function sendMailJoinRequestAccepted ($oAlert, $iProfileId, $iSender = 0)
  96. {
  97. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_JOIN_CONFIRM'], 0, $iProfileId, array(
  98. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  99. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  100. ), BX_EMAIL_NOTIFY);
  101. }
  102. protected function processTimelineShare ($oAlert, $iGroupProfileId)
  103. {
  104. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  105. return;
  106. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  107. if (!$oGroupProfile)
  108. return;
  109. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  110. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  111. if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] || (BX_DOL_PG_MEMBERS == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] && isLogged()) || $oPrivacy->isPartiallyVisible($aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']])) {
  112. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  113. }
  114. else {
  115. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  116. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  117. }
  118. }
  119. }
  120. /** @} */