BxBaseModGroupsAlertsResponse.php 6.0 KB

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