BxBaseModGroupsAlertsResponse.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. $sMethod = '_process' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
  27. if(method_exists($this, $sMethod) && $this->$sMethod($oAlert) === true)
  28. return;
  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. if($this->_bUseIn) {
  45. $iInviter = bx_get_logged_profile_id();
  46. switch ($oAlert->sAction) {
  47. case 'join_invitation':
  48. $this->sendMailInvitation($oAlert, $oAlert->aExtras['profile'], $iInviter);
  49. break;
  50. case 'join_request':
  51. $this->sendMailJoinRequest($oAlert, $oAlert->aExtras['profile'], $iInviter);
  52. break;
  53. case 'join_request_accepted':
  54. $this->sendMailJoinRequestAccepted($oAlert, $oAlert->aExtras['profile'], $iInviter);
  55. break;
  56. }
  57. }
  58. }
  59. protected function sendMailInvitation ($oAlert, $iInvited, $iInviter = 0)
  60. {
  61. $CNF = &$this->_oModule->_oConfig->CNF;
  62. $oInviter = BxDolProfile::getInstanceMagic($iInviter);
  63. sendMailTemplate($CNF['EMAIL_INVITATION'], 0, $iInvited, [
  64. 'InviterUrl' => $oInviter->getUrl(),
  65. 'InviterDisplayName' => $oInviter->getDisplayName(),
  66. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  67. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  68. ], BX_EMAIL_NOTIFY);
  69. }
  70. protected function sendMailJoinRequest ($oAlert, $iProfileId, $iSender = 0)
  71. {
  72. $aAdmins = $this->_oModule->_oDb->getAdmins($oAlert->aExtras['group_profile']);
  73. foreach ($aAdmins as $iAdminProfileId) {
  74. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_JOIN_REQUEST'], 0, $iAdminProfileId, array(
  75. 'NewMemberUrl' => BxDolProfile::getInstance($iProfileId)->getUrl(),
  76. 'NewMemberDisplayName' => BxDolProfile::getInstance($iProfileId)->getDisplayName(),
  77. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  78. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  79. ), BX_EMAIL_NOTIFY);
  80. }
  81. }
  82. protected function sendMailJoinRequestAccepted ($oAlert, $iProfileId, $iSender = 0)
  83. {
  84. sendMailTemplate($this->_oModule->_oConfig->CNF['EMAIL_JOIN_CONFIRM'], 0, $iProfileId, array(
  85. 'EntryUrl' => $oAlert->aExtras['entry_url'],
  86. 'EntryTitle' => $oAlert->aExtras['entry_title'],
  87. ), BX_EMAIL_NOTIFY);
  88. }
  89. protected function processTimelineShare ($oAlert, $iGroupProfileId)
  90. {
  91. if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  92. return;
  93. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  94. if (!$oGroupProfile)
  95. return;
  96. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  97. $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
  98. 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']])) {
  99. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
  100. }
  101. else {
  102. $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
  103. $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
  104. }
  105. }
  106. protected function _processBxTimelineGetExternalPost($oAlert)
  107. {
  108. $aParams = $oAlert->aExtras['params'];
  109. if(!isset($aParams['event_index'], $aParams['events_count'], $aParams['extenals_every']))
  110. return true;
  111. $iStart = (int)$aParams['start'];
  112. $iIndex = (int)$aParams['event_index'];
  113. $iCount = (int)$aParams['events_count'];
  114. $iEvery = (int)$aParams['extenals_every'];
  115. if(($iIndex != 0 || ($iEvery >= $iCount && ($iStart == 0 || $iCount > 0))) && ($sCode = $this->_oModule->_oTemplate->getTimelineCardRecommendations($aParams)) != '')
  116. $oAlert->aExtras['override_result'] = $sCode;
  117. return true;
  118. }
  119. }
  120. /** @} */