AntonLV 9 лет назад
Родитель
Сommit
101f74f810
2 измененных файлов с 38 добавлено и 0 удалено
  1. 9 0
      install/sql/system.sql
  2. 29 0
      template/scripts/BxBaseServiceConnections.php

+ 9 - 0
install/sql/system.sql

@@ -1209,6 +1209,15 @@ SET @iHandler = LAST_INSERT_ID();
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('system', 'save_setting', @iHandler);
 
+
+INSERT INTO `sys_alerts_handlers` (`name`, `service_call`) VALUES 
+('sys_connections', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:26:"alert_response_connections";s:5:"class";s:23:"TemplServiceConnections";}');
+SET @iHandler = LAST_INSERT_ID();
+
+INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
+('sys_profiles_friends', 'connection_added', @iHandler),
+('sys_profiles_friends', 'connection_removed', @iHandler);
+
 -- --------------------------------------------------------
 
 

+ 29 - 0
template/scripts/BxBaseServiceConnections.php

@@ -208,6 +208,35 @@ class BxBaseServiceConnections extends BxDol
 			'lang_key' => '_sys_profile_friendship_added',
 		);
     }
+    
+    public function serviceAlertResponseConnections($oAlert)
+    {
+        $sMethod = 'process' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
+        if(!method_exists($this, $sMethod))
+            return;
+            
+        $this->$sMethod($oAlert);
+    }
+
+    protected function processSysProfilesFriendsConnectionAdded(&$oAlert)
+    {
+        if((int)$oAlert->aExtras['mutual'] != 1)
+            return;
+
+        $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
+        $oConnection->addConnection((int)$oAlert->aExtras['initiator'], (int)$oAlert->aExtras['content']);
+        $oConnection->addConnection((int)$oAlert->aExtras['content'], (int)$oAlert->aExtras['initiator']);
+    }
+
+    protected function processSysProfilesFriendsConnectionRemoved(&$oAlert)
+    {
+        if((int)$oAlert->aExtras['mutual'] != 1)
+            return;
+
+        $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
+        $oConnection->removeConnection((int)$oAlert->aExtras['initiator'], (int)$oAlert->aExtras['content']);
+        $oConnection->removeConnection((int)$oAlert->aExtras['content'], (int)$oAlert->aExtras['initiator']);
+    }
 }
 
 /** @} */