BxBaseModGroupsAlertsResponse.php 5.0 KB

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