Browse Source

Ticket #940 - tasks №4 and #5

AntonLV 9 years ago
parent
commit
e9b08a97e3

+ 25 - 1
modules/boonex/notifications/classes/BxNtfsConfig.php

@@ -12,7 +12,10 @@
 bx_import('BxDolPrivacy');
 
 class BxNtfsConfig extends BxBaseModNotificationsConfig
-{  
+{
+    protected $_aHandlersHiddenEmail;
+    protected $_aHandlersHiddenPush;
+
     /**
      * Constructor
      */
@@ -34,6 +37,8 @@ class BxNtfsConfig extends BxBaseModNotificationsConfig
 
         $this->_aHandlerDescriptor = array('module_name' => '', 'module_method' => '', 'module_class' => '');
         $this->_sHandlersMethod = 'get_notifications_data';
+        $this->_aHandlersHiddenEmail = array();
+        $this->_aHandlersHiddenPush = array();
 
         $this->_aJsClasses = array(
             'main' => 'BxNtfsMain',
@@ -62,6 +67,25 @@ class BxNtfsConfig extends BxBaseModNotificationsConfig
     	$this->_aPerPage = array(
     		'default' => (int)getParam($sOptionPrefix . 'events_per_page')
     	);
+
+    	$aSettings = array(
+    	    'site' => '',
+    	    'email' => 'Email',
+    	    'push' => 'Push'
+    	);
+    	foreach($aSettings as $sSetting => $sVariable) {
+    	    $sHideTimeline = getParam($sOptionPrefix . 'events_hide_' . $sSetting);
+            if(!empty($sHideTimeline))
+                $this->{'_aHandlersHidden' . $sVariable} = explode(',', $sHideTimeline);
+    	}
+    }
+
+    public function getHandlersHidden($sType = '')
+    {
+        if(!in_array($sType, array('', 'email', 'push')))
+            return array();
+
+        return $this->{'_aHandlersHidden' . ucfirst($sType)};
     }
 
     /**

+ 45 - 0
modules/boonex/notifications/classes/BxNtfsResponse.php

@@ -42,6 +42,8 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
     				if(!empty($iId))
     					$this->_oModule->onPost($iId);
                 }
+
+                $this->sendNotifications($iId, $oAlert, $aHandler);
 				break;
 
             case BX_BASE_MOD_NTFS_HANDLER_TYPE_UPDATE:
@@ -193,6 +195,49 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
             )
         );
     }
+
+    protected function sendNotifications($iId, &$oAlert, &$aHandler)
+    {
+        $aHidden = $this->_oModule->_oConfig->getHandlersHidden('email');
+        if(in_array($aHandler['id'], $aHidden))
+            return;
+
+        $aEvent = $this->_oModule->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
+        if(empty($aEvent) || !is_array($aEvent))
+            return;
+
+        //--- Get event.
+        $sEvent = $this->_oModule->_oTemplate->getPostEt($aEvent);
+
+        //--- Get subscribers.
+        $oConnection = BxDolConnection::getObjectInstance($this->_oModule->_oConfig->getObject('conn_subscriptions'));
+        $aRecipients = $oConnection->getConnectedInitiators($aEvent['owner_id']);
+
+        //--- Get content owner.
+        if((int)$aEvent['owner_id'] != (int)$aEvent['object_owner_id'] && !in_array($aEvent['object_owner_id'], $aRecipients))
+            $aRecipients[] = $aEvent['object_owner_id'];
+
+        $oPrivacyInt = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->getObject('privacy_view'));
+        $oPrivacyExt = $this->_oModule->_oConfig->getPrivacyObject($aEvent['type'] . '_' . $aEvent['action']);
+        foreach($aRecipients as $iRecipient) {
+            $oProfile = BxDolProfile::getInstance($iRecipient);
+            if(!$oProfile)
+                continue;
+
+            if(!bx_srv($oProfile->getModule(), 'act_as_profile'))
+                continue;
+
+            if($oPrivacyExt !== false && !$oPrivacyExt->check($iId, $iRecipient)) 
+    		    continue;
+
+            if($oPrivacyInt !== false && !$oPrivacyInt->check($iId, $iRecipient))
+                continue;
+
+            sendMailTemplate('bx_notifications_new_event', $oProfile->getAccountId(), $oProfile->id(), array(
+                'content' => $sEvent
+            ));
+        }
+    }
 }
 
 /** @} */

+ 29 - 0
modules/boonex/notifications/classes/BxNtfsTemplate.php

@@ -132,6 +132,35 @@ class BxNtfsTemplate extends BxBaseModNotificationsTemplate
         ));
     }
 
+    public function getPostEt(&$aEvent, $aBrowseParams = array())
+    {
+        $oModule = $this->getModule();
+
+        $this->getPost($aEvent, $aBrowseParams);
+
+        list($sOwnerName, $sOwnerUrl, $sOwnerIcon) = $oModule->getUserInfo($aEvent['owner_id']);
+        $bAuthorIcon = !empty($sOwnerIcon);
+
+        $sContent = _t(!empty($aEvent['content']['lang_key']) ? $aEvent['content']['lang_key'] : $this->_getContentLangKey($aEvent));
+    	$sContent = $this->parseHtmlByContent($sContent, $aEvent['content'], array('{', '}'));
+
+        return $this->parseHtmlByName('et_new_event.html', array(
+        	'bx_if:show_icon' => array(
+                'condition' => $bAuthorIcon,
+                'content' => array(
+                    'icon_url' => $sOwnerIcon
+                )
+            ),
+            'bx_if:show_icon_empty' => array(
+                'condition' => !$bAuthorIcon,
+                'content' => array()
+            ),
+            'content_url' => $this->_getContentLink($aEvent),
+            'content' => $sContent,
+            'date' => bx_process_output($aEvent['date'], BX_DATA_DATETIME_TS),
+        ));
+    }
+
     public function getEmpty($bVisible = true)
     {
         return $this->parseHtmlByName('empty.html', array(

+ 11 - 1
modules/boonex/notifications/install/langs/en.xml

@@ -15,7 +15,9 @@
     <string name="_bx_ntfs_menu_item_title_notifications"><![CDATA[Notifications]]></string>
 
 	<string name="_bx_ntfs_option_events_per_page"><![CDATA[Number of items on a page]]></string>
-	<string name="_bx_ntfs_option_events_hide"><![CDATA[Show notifications to followers when user performs action]]></string>
+	<string name="_bx_ntfs_option_events_hide_site"><![CDATA[Onsite notifications]]></string>
+	<string name="_bx_ntfs_option_events_hide_email"><![CDATA[Email notifications]]></string>
+	<string name="_bx_ntfs_option_events_hide_push"><![CDATA[Push notifications]]></string>
 
 	<string name="_bx_ntfs_privacy_view"><![CDATA[View event]]></string>
 
@@ -31,4 +33,12 @@
 	<string name="_bx_ntfs_txt_msg_no_results"><![CDATA[Empty]]></string>
 	<string name="_bx_ntfs_txt_object_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> added a {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
 	<string name="_bx_ntfs_txt_subobject_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> added a {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
+
+	<string name="_bx_ntfs_email_new_event"><![CDATA[New notification]]></string>
+    <string name="_bx_ntfs_email_new_event_subject"><![CDATA[New notification on "{site_name}"]]></string>
+    <string name="_bx_ntfs_email_new_event_body"><![CDATA[{email_header}
+<p> </p>
+{content}
+<p> </p>
+{email_footer}]]></string>
 </resources>

+ 4 - 0
modules/boonex/notifications/install/sql/disable.sql

@@ -32,3 +32,7 @@ DELETE FROM `sys_objects_live_updates` WHERE `name` = @sName;
 SET @iHandlerId = (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = @sName LIMIT 1);
 DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandlerId;
 DELETE FROM `sys_alerts_handlers` WHERE `id` = @iHandlerId LIMIT 1;
+
+
+-- EMAIL TEMPLATES
+DELETE FROM `sys_email_templates` WHERE `Module` = @sName;

+ 8 - 1
modules/boonex/notifications/install/sql/enable.sql

@@ -43,7 +43,9 @@ SET @iCategId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_params`, `check_error`, `extra`, `order`) VALUES
 ('bx_notifications_events_per_page', '10', @iCategId, '_bx_ntfs_option_events_per_page', 'digit', '', '', '', '', 1),
-('bx_notifications_events_hide', '', @iCategId, '_bx_ntfs_option_events_hide', 'rlist', '', '', '', 'a:2:{s:6:"module";s:16:"bx_notifications";s:6:"method";s:21:"get_actions_checklist";}', 2);
+('bx_notifications_events_hide_site', '', @iCategId, '_bx_ntfs_option_events_hide_site', 'rlist', '', '', '', 'a:2:{s:6:"module";s:16:"bx_notifications";s:6:"method";s:21:"get_actions_checklist";}', 10),
+('bx_notifications_events_hide_email', '', @iCategId, '_bx_ntfs_option_events_hide_email', 'rlist', '', '', '', 'a:2:{s:6:"module";s:16:"bx_notifications";s:6:"method";s:21:"get_actions_checklist";}', 11),
+('bx_notifications_events_hide_push', '', @iCategId, '_bx_ntfs_option_events_hide_push', 'rlist', '', '', '', 'a:2:{s:6:"module";s:16:"bx_notifications";s:6:"method";s:21:"get_actions_checklist";}', 12);
 
 
 -- PRIVACY 
@@ -69,3 +71,8 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 
 ('sys_profiles_subscriptions', 'connection_added', @iHandler),
 ('sys_profiles_subscriptions', 'connection_removed', @iHandler);
+
+
+-- EMAIL TEMPLATES
+INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `Body`) VALUES
+(@sName, '_bx_ntfs_email_new_event', 'bx_notifications_new_event', '_bx_ntfs_email_new_event_subject', '_bx_ntfs_email_new_event_body');

+ 75 - 0
modules/boonex/notifications/template/et_new_event.html

@@ -0,0 +1,75 @@
+<style>
+    .et-item {
+        position: relative;
+        display: inline-block;
+    }
+    .et-item-cnt {
+        position: relative;
+        margin: 5px;
+    }
+    .et-item-img,
+    .et-item-img p,
+    .et-item-img img {
+        width: 48px;
+        height: 48px;
+        line-height: 48px;
+        border-radius: 80px;
+    }
+    .et-item-img {
+    	position: absolute;
+        top: 0px;
+        left: 0px;
+        background-clip: padding-box;
+        text-align: center;
+        overflow: hidden;
+    }
+	.et-item-img .sys-icon {
+	    display: block;
+        box-sizing: border-box;
+	    margin: 0px;
+        border: 0px solid #ccc;
+	    line-height: 46px;
+	    line-height: 2.9rem;
+	    font-size: 20px;
+	    font-size: 1.2rem;
+	    font-weight: 700;
+	    color: #d0d0d0;
+	}
+    .et-item-info {
+    	position: relative;
+        min-height: 48px;
+        margin-left: 58px;
+    }
+    .et-item-info-cnt {
+        padding: 5px 0px;
+        white-space: nowrap;
+        text-overflow: ellipsis;
+        overflow: hidden;
+    }
+    .et-item-info-cnt p {
+	   margin: 5px 0px 0px 0px;
+    }
+    .et-item-info-cnt p:first-child {
+       margin-top: 0px;
+    }
+</style>
+<div class="et-item">
+	<a href="__content_url__">
+		<div class="et-item-cnt">
+			<div class="et-item-img">
+				<bx_if:show_icon>
+				    <img src="__icon_url__" />
+				</bx_if:show_icon>
+				<bx_if:show_icon_empty>
+				    <i class="sys-icon user"></i>
+				</bx_if:show_icon_empty>
+			</div>
+			<div class="et-item-info">
+			    <div class="et-item-info-cnt">
+                    <p>__content__</p>
+                    <p>__date__</p>
+                </div>
+			</div>
+		</div>
+	</a>
+</div>

+ 11 - 1
modules/boonex/russian/data/langs/bx_notifications/ru.xml

@@ -15,7 +15,9 @@
     <string name="_bx_ntfs_menu_item_title_notifications"><![CDATA[Уведомления]]></string>
 
 	<string name="_bx_ntfs_option_events_per_page"><![CDATA[Количество элементов на странице]]></string>
-	<string name="_bx_ntfs_option_events_hide"><![CDATA[Показывать события для последователей, когда пользователь совершает действия]]></string>
+	<string name="_bx_ntfs_option_events_hide_site"><![CDATA[Уведомления на сайте]]></string>
+	<string name="_bx_ntfs_option_events_hide_email"><![CDATA[Уведомления через имейл]]></string>
+	<string name="_bx_ntfs_option_events_hide_push"><![CDATA[Push-уведомления]]></string>
 
 	<string name="_bx_ntfs_privacy_view"><![CDATA[Просматривать события]]></string>
 
@@ -31,4 +33,12 @@
 	<string name="_bx_ntfs_txt_msg_no_results"><![CDATA[Пусто]]></string>
 	<string name="_bx_ntfs_txt_object_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
 	<string name="_bx_ntfs_txt_subobject_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
+
+	<string name="_bx_ntfs_email_new_event"><![CDATA[Новое уведомление]]></string>
+    <string name="_bx_ntfs_email_new_event_subject"><![CDATA[Новое уведомление на сайте "{site_name}"]]></string>
+    <string name="_bx_ntfs_email_new_event_body"><![CDATA[{email_header}
+<p> </p>
+{content}
+<p> </p>
+{email_footer}]]></string>
 </resources>