Browse Source

Ticket #623 - New friend notification.

AntonLV 9 năm trước cách đây
mục cha
commit
d2723f99ab

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -2196,6 +2196,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_pre_lists_report_types_nude"><![CDATA[nude]]></string>
 	<string name="_sys_pre_lists_report_types_other"><![CDATA[other]]></string>
 	<string name="_sys_profile_sample_single"><![CDATA[profile]]></string>
+	<string name="_sys_profile_friendship_added"><![CDATA[<a class="bx-ntfs-content-profile" href="{owner_link}">{owner_name}</a> is now friends with <a href="{entry_url}">{entry_caption}</a>]]></string>
 	<string name="_sys_profile_subscription_added"><![CDATA[<a class="bx-ntfs-content-profile" href="{owner_link}">{owner_name}</a> subscribed to <a href="{entry_url}">{entry_caption}</a> {entry_sample}]]></string>
 	<string name="_sys_private"><![CDATA[Private]]></string>
     <string name="_sys_pruning_db"><![CDATA[<h3>Database pruning:</h3>

+ 128 - 35
modules/boonex/notifications/classes/BxNtfsResponse.php

@@ -36,11 +36,12 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
             	if(!method_exists($this, $sMethod))
             		$sMethod = 'getInsertData';
 
-                $iId = $this->_oModule->_oDb->insertEvent($this->$sMethod($oAlert));
- 
-				if(!empty($iId))
-					$this->_oModule->onPost($iId);
-
+                $aDataItems = $this->$sMethod($oAlert, $aHandler);
+                foreach($aDataItems as $aDataItem) {
+                    $iId = $this->_oModule->_oDb->insertEvent($aDataItem);
+    				if(!empty($iId))
+    					$this->_oModule->onPost($iId);
+                }
 				break;
 
             case BX_BASE_MOD_NTFS_HANDLER_TYPE_UPDATE:
@@ -53,51 +54,143 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
 					break;
             	}
 
-            	$aHandlers = $this->_oModule->_oDb->getHandlers(array('type' => 'by_group_key_type', 'group' => $aHandler['group']));
-                $this->_oModule->_oDb->deleteEvent(array(
-                	'type' => $oAlert->sUnit, 
-                	'action' => $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'], 
-                	'object_id' => $oAlert->iObject,
-                	'subobject_id' => $this->_getSubObjectId($oAlert->aExtras)
-                ));
+            	$sMethod = 'getDeleteData' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);           	
+            	if(!method_exists($this, $sMethod))
+            		$sMethod = 'getDeleteData';
+
+                $aDataItems = $this->$sMethod($oAlert, $aHandler);
+                foreach($aDataItems as $aDataItem)
+                    $this->_oModule->_oDb->deleteEvent($aDataItem);
                 break;
         }
     }
 
-    protected function getInsertData(&$oAlert)
+    protected function getInsertData(&$oAlert, &$aHandler)
+    {
+    	return array(
+    	    array(
+    			'owner_id' => $oAlert->iSender,
+    			'type' => $oAlert->sUnit,
+    			'action' => $oAlert->sAction,
+    			'object_id' => $oAlert->iObject,
+    			'object_owner_id' => $this->_getObjectOwnerId($oAlert->aExtras),
+    			'object_privacy_view' => $this->_getObjectPrivacyView($oAlert->aExtras),
+    			'subobject_id' => $this->_getSubObjectId($oAlert->aExtras),
+    			'content' => '',
+        		'allow_view_event_to' => $this->_oModule->_oConfig->getPrivacyViewDefault('event'),
+    			'processed' => 0
+    	    )
+		);
+    }
+    
+    protected function getDeleteData(&$oAlert, &$aHandler)
+    {
+        $aHandlers = $this->_oModule->_oDb->getHandlers(array('type' => 'by_group_key_type', 'group' => $aHandler['group']));
+
+    	return array(
+    	    array(
+            	'type' => $oAlert->sUnit, 
+            	'action' => $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'], 
+            	'object_id' => $oAlert->iObject,
+            	'subobject_id' => $this->_getSubObjectId($oAlert->aExtras)
+            )
+        );
+    }
+
+	/**
+     * Custom insert data getter for sys_profiles_friends -> connection_added and connection_removed alerts. 
+     */
+    protected function getInsertDataSysProfilesFriendsConnectionAdded(&$oAlert, &$aHandler)
     {
+        if(empty($oAlert->aExtras['mutual']))
+            return array();
+
+        $iObjectPrivacyView = $this->_getObjectPrivacyView($oAlert->aExtras);
+        $iPrivacyView = $this->_oModule->_oConfig->getPrivacyViewDefault('event');
+
     	return array(
-			'owner_id' => $oAlert->iSender,
-			'type' => $oAlert->sUnit,
-			'action' => $oAlert->sAction,
-			'object_id' => $oAlert->iObject,
-			'object_owner_id' => $this->_getObjectOwnerId($oAlert->aExtras),
-			'object_privacy_view' => $this->_getObjectPrivacyView($oAlert->aExtras),
-			'subobject_id' => $this->_getSubObjectId($oAlert->aExtras),
-			'content' => '',
-    		'allow_view_event_to' => $this->_oModule->_oConfig->getPrivacyViewDefault('event'),
-			'processed' => 0
+    	    array(
+    			'owner_id' => $oAlert->aExtras['initiator'],
+    			'type' => $oAlert->sUnit,
+    			'action' => $oAlert->sAction,
+    			'object_id' => $oAlert->aExtras['content'],
+    			'object_owner_id' => $oAlert->aExtras['content'],
+    			'object_privacy_view' => $iObjectPrivacyView,
+    			'subobject_id' => 0,
+    			'content' => '',
+        		'allow_view_event_to' => $iPrivacyView,
+    			'processed' => 0
+    	    ),
+    	    array(
+    			'owner_id' => $oAlert->aExtras['content'],
+    			'type' => $oAlert->sUnit,
+    			'action' => $oAlert->sAction,
+    			'object_id' => $oAlert->aExtras['initiator'],
+    			'object_owner_id' => $oAlert->aExtras['initiator'],
+    			'object_privacy_view' => $iObjectPrivacyView,
+    			'subobject_id' => 0,
+    			'content' => '',
+        		'allow_view_event_to' => $iPrivacyView,
+    			'processed' => 0
+    	    ),
 		);
     }
+    
+    protected function getDeleteDataSysProfilesFriendsConnectionRemoved(&$oAlert, &$aHandler)
+    {
+        $aHandlers = $this->_oModule->_oDb->getHandlers(array('type' => 'by_group_key_type', 'group' => $aHandler['group']));
+
+        $sAction = $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'];
+    	return array(
+    	    array(
+    	        'owner_id' => $oAlert->aExtras['initiator'],
+            	'type' => $oAlert->sUnit, 
+            	'action' => $sAction, 
+            	'object_id' => $oAlert->aExtras['content']
+            ),
+            array(
+            	'owner_id' => $oAlert->aExtras['content'],
+            	'type' => $oAlert->sUnit, 
+            	'action' => $sAction, 
+            	'object_id' => $oAlert->aExtras['initiator']
+            )
+        );
+    }
 
     /**
-     * Custom insert data getter for sys_profiles_subscriptions -> connection_added alert. 
+     * Custom insert data getter for sys_profiles_subscriptions -> connection_added and connection_removed alerts. 
      */
-    protected function getInsertDataSysProfilesSubscriptionsConnectionAdded(&$oAlert)
+    protected function getInsertDataSysProfilesSubscriptionsConnectionAdded(&$oAlert, &$aHandler)
     {
     	return array(
-			'owner_id' => $oAlert->iSender,
-			'type' => $oAlert->sUnit,
-			'action' => $oAlert->sAction,
-			'object_id' => $oAlert->aExtras['content'],
-			'object_owner_id' => $oAlert->aExtras['content'],
-			'object_privacy_view' => $this->_getObjectPrivacyView($oAlert->aExtras),
-			'subobject_id' => 0,
-			'content' => '',
-    		'allow_view_event_to' => $this->_oModule->_oConfig->getPrivacyViewDefault('event'),
-			'processed' => 0
+    	    array(
+    			'owner_id' => $oAlert->aExtras['initiator'],
+    			'type' => $oAlert->sUnit,
+    			'action' => $oAlert->sAction,
+    			'object_id' => $oAlert->aExtras['content'],
+    			'object_owner_id' => $oAlert->aExtras['content'],
+    			'object_privacy_view' => $this->_getObjectPrivacyView($oAlert->aExtras),
+    			'subobject_id' => 0,
+    			'content' => '',
+        		'allow_view_event_to' => $this->_oModule->_oConfig->getPrivacyViewDefault('event'),
+    			'processed' => 0
+    	    )
 		);
     }
+
+    protected function getDeleteDataSysProfilesSubscriptionsConnectionRemoved(&$oAlert, &$aHandler)
+    {
+        $aHandlers = $this->_oModule->_oDb->getHandlers(array('type' => 'by_group_key_type', 'group' => $aHandler['group']));
+
+    	return array(
+    	    array(
+    	        'owner_id' => $oAlert->aExtras['initiator'],
+            	'type' => $oAlert->sUnit, 
+            	'action' => $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'], 
+            	'object_id' => $oAlert->aExtras['content']
+            )
+        );
+    }
 }
 
 /** @} */

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

@@ -24,6 +24,7 @@
 	<string name="_bx_ntfs_alert_action_timeline_post_common"><![CDATA[post to timeline]]></string> 
 
 	<string name="_bx_ntfs_alert_module_sys_profiles_subscriptions"><![CDATA[Profiles Subscriptions]]></string>
+	<string name="_bx_ntfs_alert_module_sys_profiles_friends"><![CDATA[Profiles Friends]]></string>
 	<string name="_bx_ntfs_alert_action_connection_added"><![CDATA[add connection]]></string>
 
 	<string name="_bx_ntfs_txt_msg_no_results"><![CDATA[Empty]]></string>

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

@@ -52,5 +52,9 @@ SET @iHandler := LAST_INSERT_ID();
 
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('profile', 'delete', @iHandler),
+
+('sys_profiles_friends', 'connection_added', @iHandler),
+('sys_profiles_friends', 'connection_removed', @iHandler),
+
 ('sys_profiles_subscriptions', 'connection_added', @iHandler),
 ('sys_profiles_subscriptions', 'connection_removed', @iHandler);

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

@@ -41,6 +41,10 @@ CREATE TABLE IF NOT EXISTS `bx_notifications_handlers` (
 
 INSERT INTO `bx_notifications_handlers`(`group`, `type`, `alert_unit`, `alert_action`, `content`) VALUES
 ('profile', 'delete', 'profile', 'delete', ''),
+
+('friendship', 'insert', 'sys_profiles_friends', 'connection_added', 'a:3:{s:11:"module_name";s:6:"system";s:13:"module_method";s:33:"get_notifications_post_friendship";s:12:"module_class";s:23:"TemplServiceConnections";}'),
+('friendship', 'delete', 'sys_profiles_friends', 'connection_removed', ''),
+
 ('subscription', 'insert', 'sys_profiles_subscriptions', 'connection_added', 'a:3:{s:11:"module_name";s:6:"system";s:13:"module_method";s:22:"get_notifications_post";s:12:"module_class";s:23:"TemplServiceConnections";}'),
 ('subscription', 'delete', 'sys_profiles_subscriptions', 'connection_removed', '');
 

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

@@ -24,6 +24,7 @@
 	<string name="_bx_ntfs_alert_action_timeline_post_common"><![CDATA[сообщение на линейке]]></string>
 
 	<string name="_bx_ntfs_alert_module_sys_profiles_subscriptions"><![CDATA[Подписки профайлов]]></string>
+	<string name="_bx_ntfs_alert_module_sys_profiles_friends"><![CDATA[Друзья профайлов]]></string>
 	<string name="_bx_ntfs_alert_action_connection_added"><![CDATA[добавить связь]]></string>	
 
 	<string name="_bx_ntfs_txt_msg_no_results"><![CDATA[Пусто]]></string>

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -2194,6 +2194,7 @@
 	<string name="_sys_pre_lists_report_types_nude"><![CDATA[обнаженность]]></string>
 	<string name="_sys_pre_lists_report_types_other"><![CDATA[другое]]></string>
 	<string name="_sys_profile_sample_single"><![CDATA[профиль]]></string>
+	<string name="_sys_profile_friendship_added"><![CDATA[<a class="bx-ntfs-content-profile" href="{owner_link}">{owner_name}</a> подружился с <a href="{entry_url}">{entry_caption}</a>]]></string>
 	<string name="_sys_profile_subscription_added"><![CDATA[<a class="bx-ntfs-content-profile" href="{owner_link}">{owner_name}</a> подписался на <a href="{entry_url}">{entry_caption}</a> {entry_sample}]]></string>
 	<string name="_sys_private"><![CDATA[Приватные]]></string>
     <string name="_sys_pruning_db"><![CDATA[<h3>Очистка Базы Данных:</h3>

+ 20 - 1
template/scripts/BxBaseServiceConnections.php

@@ -148,7 +148,7 @@ class BxBaseServiceConnections extends BxDol
     }
 
     /*
-     * Get notification data for Notifications module. 
+     * Get notification data for Notifications module - action Subscribe. 
      */
 	public function serviceGetNotificationsPost($aEvent)
     {
@@ -165,6 +165,25 @@ class BxBaseServiceConnections extends BxDol
 			'lang_key' => '_sys_profile_subscription_added',
 		);
     }
+
+    /*
+     * Get notification data for Notifications module - action Friend. 
+     */
+	public function serviceGetNotificationsPostFriendship($aEvent)
+    {
+    	$iProfile = (int)$aEvent['object_id'];
+    	$oProfile = BxDolProfile::getInstance($iProfile);
+        if(!$oProfile)
+			return array();
+
+		return array(
+			'entry_sample' => '_sys_profile_sample_single',
+			'entry_url' => $oProfile->getUrl(),
+			'entry_caption' => $oProfile->getDisplayName(),
+			'entry_author' => $oProfile->id(),
+			'lang_key' => '_sys_profile_friendship_added',
+		);
+    }
 }
 
 /** @} */