|
|
@@ -46,12 +46,10 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
|
|
|
$aDataItems = $this->$sMethod($oAlert, $aHandler);
|
|
|
foreach($aDataItems as $aDataItem) {
|
|
|
$iId = $this->_oModule->_oDb->insertEvent($aDataItem);
|
|
|
- if(!empty($iId)) {
|
|
|
- if($iSilentMode != BX_NTFS_SLTMODE_SITE)
|
|
|
- $this->sendNotifications($iId, $oAlert, $aHandler);
|
|
|
+ if(empty($iId))
|
|
|
+ continue;
|
|
|
|
|
|
- $this->_oModule->onPost($iId);
|
|
|
- }
|
|
|
+ $this->_oModule->onPost($iId);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
@@ -100,7 +98,7 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
|
|
|
'object_owner_id' => $this->_getObjectOwnerId($oAlert->aExtras),
|
|
|
'object_privacy_view' => $iObjectPrivacyView,
|
|
|
'subobject_id' => $iSubobjectId,
|
|
|
- 'content' => '',
|
|
|
+ 'content' => $this->_getContent($oAlert->aExtras),
|
|
|
'allow_view_event_to' => $this->_oModule->_oConfig->getPrivacyViewDefault('event'),
|
|
|
'processed' => 0
|
|
|
);
|
|
|
@@ -148,10 +146,6 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
|
|
|
$iObjectPrivacyView = $this->_getObjectPrivacyView($oAlert->aExtras);
|
|
|
$iPrivacyView = $this->_oModule->_oConfig->getPrivacyViewDefault('event');
|
|
|
|
|
|
- $aContent = array(
|
|
|
- 'request' => empty($oAlert->aExtras['mutual']) ? 1 : 0
|
|
|
- );
|
|
|
-
|
|
|
return array(
|
|
|
array(
|
|
|
'owner_id' => $oAlert->aExtras['initiator'],
|
|
|
@@ -161,7 +155,9 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
|
|
|
'object_owner_id' => $oAlert->aExtras['content'],
|
|
|
'object_privacy_view' => $iObjectPrivacyView,
|
|
|
'subobject_id' => 0,
|
|
|
- 'content' => serialize($aContent),
|
|
|
+ 'content' => $this->_getContent($oAlert->aExtras, array(
|
|
|
+ 'request' => empty($oAlert->aExtras['mutual']) ? 1 : 0
|
|
|
+ )),
|
|
|
'allow_view_event_to' => $iPrivacyView,
|
|
|
'processed' => 0
|
|
|
)
|
|
|
@@ -203,7 +199,7 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
|
|
|
'object_owner_id' => $oAlert->aExtras['content'],
|
|
|
'object_privacy_view' => $this->_getObjectPrivacyView($oAlert->aExtras),
|
|
|
'subobject_id' => 0,
|
|
|
- 'content' => '',
|
|
|
+ 'content' => $this->_getContent($oAlert->aExtras),
|
|
|
'allow_view_event_to' => $this->_oModule->_oConfig->getPrivacyViewDefault('event'),
|
|
|
'processed' => 0
|
|
|
)
|
|
|
@@ -224,123 +220,6 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- protected function sendNotifications($iId, &$oAlert, &$aHandler)
|
|
|
- {
|
|
|
- $aDeliveryTypes = array();
|
|
|
-
|
|
|
- $iSilentMode = $this->_getSilentMode($oAlert->aExtras);
|
|
|
- switch($iSilentMode) {
|
|
|
- case BX_NTFS_SLTMODE_ABSOLUTE:
|
|
|
- case BX_NTFS_SLTMODE_SITE:
|
|
|
- return;
|
|
|
-
|
|
|
- case BX_NTFS_SLTMODE_SITE_EMAIL:
|
|
|
- $aDeliveryTypes[] = BX_BASE_MOD_NTFS_DTYPE_EMAIL;
|
|
|
- break;
|
|
|
-
|
|
|
- case BX_NTFS_SLTMODE_SITE_PUSH:
|
|
|
- $aDeliveryTypes[] = BX_BASE_MOD_NTFS_DTYPE_PUSH;
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- $aDeliveryTypes = array(BX_BASE_MOD_NTFS_DTYPE_EMAIL, BX_BASE_MOD_NTFS_DTYPE_PUSH);
|
|
|
- }
|
|
|
-
|
|
|
- $aEvent = $this->_oModule->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
|
|
|
- if(empty($aEvent) || !is_array($aEvent))
|
|
|
- return;
|
|
|
-
|
|
|
- $aSendUsing = array();
|
|
|
- foreach($aDeliveryTypes as $sDeliveryType) {
|
|
|
- $aHidden = $this->_oModule->_oConfig->getHandlersHidden($sDeliveryType);
|
|
|
- if(in_array($aHandler['id'], $aHidden))
|
|
|
- continue;
|
|
|
-
|
|
|
- $sMethodPostfix = bx_gen_method_name($sDeliveryType);
|
|
|
- $sMethodGet = 'getNotification' . $sMethodPostfix;
|
|
|
- $sMethodSend = 'sendNotification' . $sMethodPostfix;
|
|
|
- if(!$this->_oModule->_oTemplate->isMethodExists($sMethodGet) || !method_exists($this->_oModule, $sMethodSend))
|
|
|
- continue;
|
|
|
-
|
|
|
- $mixedNotification = $this->_oModule->_oTemplate->$sMethodGet($aEvent);
|
|
|
- if($mixedNotification === false)
|
|
|
- continue;
|
|
|
-
|
|
|
- $aSendUsing[$sDeliveryType] = array(
|
|
|
- 'method' => $sMethodSend,
|
|
|
- 'notification' => $mixedNotification
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- if(empty($aSendUsing) || !is_array($aSendUsing))
|
|
|
- return;
|
|
|
-
|
|
|
- $iOwner = (int)$aEvent['owner_id'];
|
|
|
- $aRecipients = array();
|
|
|
-
|
|
|
- //--- Get recipients: Subscribers.
|
|
|
- $oConnection = BxDolConnection::getObjectInstance($this->_oModule->_oConfig->getObject('conn_subscriptions'));
|
|
|
- $aSubscribers = $oConnection->getConnectedInitiators($iOwner);
|
|
|
- if(!empty($aSubscribers) && is_array($aSubscribers)) {
|
|
|
- $oOwner = BxDolProfile::getInstance($iOwner);
|
|
|
- $sSettingType = bx_srv($oOwner->getModule(), 'act_as_profile') ? BX_NTFS_STYPE_FOLLOW_MEMBER : BX_NTFS_STYPE_FOLLOW_CONTEXT;
|
|
|
-
|
|
|
- foreach($aSubscribers as $iSubscriber)
|
|
|
- $this->_addRecipient($iSubscriber, $sSettingType, $aRecipients);
|
|
|
- }
|
|
|
-
|
|
|
- //--- Get recipients: Content owner.
|
|
|
- $iObjectOwner = (int)$aEvent['object_owner_id'];
|
|
|
- if($iOwner != $iObjectOwner)
|
|
|
- $this->_addRecipient($iObjectOwner, BX_NTFS_STYPE_PERSONAL, $aRecipients);
|
|
|
-
|
|
|
- $bDeliveryTimeout = $this->_oModule->_oConfig->getDeliveryTimeout() > 0;
|
|
|
-
|
|
|
- //--- Check recipients and send notifications.
|
|
|
- $oPrivacyInt = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->getObject('privacy_view'));
|
|
|
- $oPrivacyExt = $this->_oModule->_oConfig->getPrivacyObject($aEvent['type'] . '_' . $aEvent['action']);
|
|
|
- foreach($aRecipients as $iRecipient => $aSettingTypes) {
|
|
|
- $oProfile = BxDolProfile::getInstance($iRecipient);
|
|
|
- if(!$oProfile)
|
|
|
- continue;
|
|
|
-
|
|
|
- if(!bx_srv($oProfile->getModule(), 'act_as_profile'))
|
|
|
- continue;
|
|
|
-
|
|
|
- if($oPrivacyExt !== false && !$oPrivacyExt->check($aEvent['id'], $iRecipient))
|
|
|
- continue;
|
|
|
-
|
|
|
- if($oPrivacyInt !== false && !$oPrivacyInt->check($aEvent['id'], $iRecipient))
|
|
|
- continue;
|
|
|
-
|
|
|
- foreach($aSendUsing as $sDeliveryType => $aDeliveryType)
|
|
|
- foreach($aSettingTypes as $sSettingType) {
|
|
|
- $aSetting = $this->_oModule->_oDb->getSetting(array('by' => 'tsu_allowed', 'handler_id' => $aHandler['id'], 'delivery' => $sDeliveryType, 'type' => $sSettingType, 'user_id' => $iRecipient));
|
|
|
- if(empty($aSetting) || !is_array($aSetting))
|
|
|
- continue;
|
|
|
-
|
|
|
- if((int)$aSetting['active_adm'] == 0 || (int)$aSetting['active_pnl'] == 0)
|
|
|
- continue;
|
|
|
-
|
|
|
- /**
|
|
|
- * 'break' is essential in the next two conditions to avoid
|
|
|
- * duplicate sending to the same recipient.
|
|
|
- */
|
|
|
- if($bDeliveryTimeout && $this->_oModule->_oDb->queueAdd(array(
|
|
|
- 'profile_id' => $iRecipient,
|
|
|
- 'event_id' => $aEvent['id'],
|
|
|
- 'delivery' => $sDeliveryType,
|
|
|
- 'content' => serialize($aDeliveryType['notification']),
|
|
|
- 'date' => time()
|
|
|
- )) !== false)
|
|
|
- break;
|
|
|
-
|
|
|
- if($this->_oModule->{$aDeliveryType['method']}($oProfile, $aDeliveryType['notification']) !== false)
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
protected function _getObjectOwnerId($aExtras)
|
|
|
{
|
|
|
$iResult = parent::_getObjectOwnerId($aExtras);
|
|
|
@@ -353,20 +232,26 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- protected function _getSilentMode($aExtras)
|
|
|
+ protected function _getContent($aExtras, $aAdd = array())
|
|
|
{
|
|
|
- if(isset($aExtras['silent_mode']))
|
|
|
- return (int)$aExtras['silent_mode'];
|
|
|
+ $aResult = array();
|
|
|
|
|
|
- return BX_NTFS_SLTMODE_DISABLED;
|
|
|
+ $iSilentMode = $this->_getSilentMode($aExtras);
|
|
|
+ if($iSilentMode != BX_NTFS_SLTMODE_DISABLED)
|
|
|
+ $aResult['silent_mode'] = $iSilentMode;
|
|
|
+
|
|
|
+ if(!empty($aAdd) && is_array($aAdd))
|
|
|
+ $aResult = array_merge($aResult, $aAdd);
|
|
|
+
|
|
|
+ return !empty($aResult) && is_array($aResult) ? serialize($aResult) : '';
|
|
|
}
|
|
|
|
|
|
- protected function _addRecipient($iUser, $sSettingType, &$aRecipients)
|
|
|
+ protected function _getSilentMode($aExtras)
|
|
|
{
|
|
|
- if(!isset($aRecipients[$iUser]))
|
|
|
- $aRecipients[$iUser] = array();
|
|
|
+ if(isset($aExtras['silent_mode']))
|
|
|
+ return (int)$aExtras['silent_mode'];
|
|
|
|
|
|
- $aRecipients[$iUser][] = $sSettingType;
|
|
|
+ return BX_NTFS_SLTMODE_DISABLED;
|
|
|
}
|
|
|
}
|
|
|
|