1
0

BxBaseModGroupsAlertsResponse.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. if ($this->_oModule->_oDb->getInviteByInvited($iProfileId, $oAlert->iSender) == 0){
  56. $oKeys = BxDolKey::getInstance();
  57. $iKeyLifetime = $CNF["INVITES_KEYS_LIFETIME"];
  58. $sKey = $oKeys->getNewKey(false, $iKeyLifetime);
  59. $this->_oModule->_oDb->insertInvite($sKey, $oAlert->iSender, $iSender, $iProfileId);
  60. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $oAlert->iObject . "&key=" . $sKey);
  61. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_INVITATION'], 0, $iProfileId, array(
  62. 'InviterUrl' => BxDolProfile::getInstance($iSender)->getUrl(),
  63. 'InviterDisplayName' => BxDolProfile::getInstance($iSender)->getDisplayName(),
  64. 'EntryUrl' => $sEntryUrl,
  65. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  66. ), BX_EMAIL_NOTIFY);
  67. }
  68. }
  69. }
  70. else{
  71. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_INVITATION'], 0, $iProfileId, array(
  72. 'InviterUrl' => BxDolProfile::getInstance($iSender)->getUrl(),
  73. 'InviterDisplayName' => BxDolProfile::getInstance($iSender)->getDisplayName(),
  74. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  75. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  76. ), BX_EMAIL_NOTIFY);
  77. }
  78. }
  79. protected function sendMailJoinRequest ($oAlert, $iProfileId, $iSender = 0)
  80. {
  81. $aAdmins = $this->_oModule->_oDb->getAdmins($oAlert->aExtras['group_profile']);
  82. foreach ($aAdmins as $iAdminProfileId) {
  83. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_JOIN_REQUEST'], 0, $iAdminProfileId, array(
  84. 'NewMemberUrl' => BxDolProfile::getInstance($iProfileId)->getUrl(),
  85. 'NewMemberDisplayName' => BxDolProfile::getInstance($iProfileId)->getDisplayName(),
  86. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  87. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  88. ), BX_EMAIL_NOTIFY);
  89. }
  90. }
  91. protected function sendMailJoinRequestAccepted ($oAlert, $iProfileId, $iSender = 0)
  92. {
  93. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_JOIN_CONFIRM'], 0, $iProfileId, array(
  94. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  95. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  96. ), BX_EMAIL_NOTIFY);
  97. }
  98. protected function processTimelineShare ($oAlert, $iGroupProfileId)
  99. {
  100. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  101. return;
  102. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  103. if (!$oGroupProfile)
  104. return;
  105. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  106. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  107. 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']])) {
  108. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  109. }
  110. else {
  111. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  112. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  113. }
  114. }
  115. }
  116. /** @} */