Explorar el Código

Ticket #4619 - Timeline/Notifications: Allow to override event data to be inserted in DB.

AntonLV hace 2 años
padre
commit
48b782562c

+ 19 - 1
modules/base/notifications/classes/BxBaseModNotificationsResponse.php

@@ -11,11 +11,14 @@
 
 class BxBaseModNotificationsResponse extends BxDolAlertsResponse
 {
+    protected $_sModule;
     protected $_oModule;
 
-    function __construct()
+    public function __construct()
     {
         parent::__construct();
+
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
     }
 
     /**
@@ -80,6 +83,21 @@ class BxBaseModNotificationsResponse extends BxDolAlertsResponse
 
         return 0;
     }
+
+    protected function _getEventUpdate(&$oAlert, &$aHandler)
+    {
+        $aHandlers = $this->_oModule->_oDb->getHandlers([
+            'type' => 'by_group_key_type', 
+            'group' => $aHandler['group']
+        ]);
+
+        return $this->_oModule->_oDb->getEvents([
+            'browse' => 'descriptor', 
+            'type' => $oAlert->sUnit, 
+            'action' => $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'],
+            'object_id' => $oAlert->iObject
+        ]);
+    }
 }
 
 /** @} */

+ 14 - 0
modules/boonex/notifications/classes/BxNtfsDb.php

@@ -163,6 +163,20 @@ class BxNtfsDb extends BxBaseModNotificationsDb
         list($sMethod, $sSelectClause, $sJoinClause, $sWhereClause, $sOrderClause, $sLimitClause) = parent::_getSqlPartsEvents($aParams);
 
         switch($aParams['browse']) {
+            case 'descriptor':
+                $sMethod = 'getRow';
+                $sWhereClause = "";
+
+                if(isset($aParams['type']))
+                    $sWhereClause .= $this->prepareAsString("AND `" . $this->_sTable . "`.`type`=? ", $aParams['type']);
+                if(isset($aParams['action']))
+                    $sWhereClause .= $this->prepareAsString("AND `" . $this->_sTable . "`.`action`=? ", $aParams['action']);
+                if(isset($aParams['object_id']))
+                    $sWhereClause .= $this->prepareAsString("AND `" . $this->_sTable . "`.`object_id`=? ", $aParams['object_id']);
+
+                $sLimitClause = "LIMIT 1";
+                break;
+
             case 'list':
                 if(!empty($aParams['count_only'])) {
                     $sMethod = 'getOne';

+ 23 - 7
modules/boonex/notifications/classes/BxNtfsResponse.php

@@ -13,9 +13,9 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
 {
     public function __construct()
     {
-        parent::__construct();
+        $this->_sModule = 'bx_notifications';
 
-        $this->_oModule = BxDolModule::getInstance('bx_notifications');
+        parent::__construct();
     }
 
     /**
@@ -50,8 +50,10 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
                     $sMethod = 'getInsertData';
 
                 $aDataItems = $this->$sMethod($oAlert, $aHandler);
-                if(BxDolRequest::serviceExists($oAlert->sUnit, 'get_notifications_insert_data')) 
-                    $aDataItems = bx_srv($oAlert->sUnit, 'get_notifications_insert_data', [$oAlert, $aHandler, $aDataItems]);
+
+                $sMethod = 'get_notifications_insert_data';
+                if(bx_is_srv($oAlert->sUnit, $sMethod)) 
+                    $aDataItems = bx_srv($oAlert->sUnit, $sMethod, [$oAlert, $aHandler, $aDataItems]);
 
                 foreach($aDataItems as $aDataItem) {
                     $iId = $this->_oModule->_oDb->insertEvent($aDataItem);
@@ -63,7 +65,19 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
                 break;
 
             case BX_BASE_MOD_NTFS_HANDLER_TYPE_UPDATE:
-                $this->_oModule->_oDb->updateEvent(array('object_privacy_view' => $iObjectPrivacyView), array('type' => $oAlert->sUnit, 'object_id' => $oAlert->iObject));
+                $aEvent = $this->_getEventUpdate($oAlert, $aHandler);
+                if(empty($aEvent) || !is_array($aEvent))
+                    break;
+
+                $aDataItem = [
+                    'object_privacy_view' => $iObjectPrivacyView
+                ];
+
+                $sMethod = 'get_notifications_update_data';
+                if(bx_is_srv($oAlert->sUnit, $sMethod)) 
+                    $aDataItem = bx_srv($oAlert->sUnit, $sMethod, [$oAlert, $aHandler, $aEvent, $aDataItem]);
+
+                $this->_oModule->_oDb->updateEvent($aDataItem, ['type' => $oAlert->sUnit, 'object_id' => $oAlert->iObject]);
                 break;
 
             case BX_BASE_MOD_NTFS_HANDLER_TYPE_DELETE:
@@ -79,8 +93,10 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
                     $sMethod = 'getDeleteData';
 
                 $aDataItems = $this->$sMethod($oAlert, $aHandler);
-                if(BxDolRequest::serviceExists($oAlert->sUnit, 'get_notifications_delete_data')) 
-                    $aDataItems = bx_srv($oAlert->sUnit, 'get_notifications_delete_data', [$oAlert, $aHandler, $aDataItems]);
+
+                $sMethod = 'get_notifications_delete_data';
+                if(bx_is_srv($oAlert->sUnit, $sMethod)) 
+                    $aDataItems = bx_srv($oAlert->sUnit, $sMethod, [$oAlert, $aHandler, $aDataItems]);
 
                 foreach($aDataItems as $aDataItem)
                     $this->_oModule->_oDb->deleteEvent($aDataItem);

+ 17 - 20
modules/boonex/timeline/classes/BxTimelineResponse.php

@@ -13,9 +13,9 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
 {
     public function __construct()
     {
-        parent::__construct();
+        $this->_sModule = 'bx_timeline';
 
-        $this->_oModule = BxDolModule::getInstance('bx_timeline');
+        parent::__construct();
     }
 
     /**
@@ -25,7 +25,7 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
      */
     public function response($oAlert)
     {
-        bx_alert($this->_oModule->getName(), 'before_register_alert', 0, 0, array(
+        bx_alert($this->_sModule, 'before_register_alert', 0, 0, array(
             'unit' => $oAlert->sUnit,
             'action' => $oAlert->sAction,
             'alert' => &$oAlert,
@@ -87,6 +87,10 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
                 if(method_exists($this, $sMethod))
                     $this->$sMethod($oAlert, $aEvent);
 
+                $sMethod = 'get_timeline_insert_data';
+                if(bx_is_srv($oAlert->sUnit, $sMethod)) 
+                    $aEvent = bx_srv($oAlert->sUnit, $sMethod, [$oAlert, $aHandler, $aEvent]);
+
                 $iId = $this->_oModule->_oDb->insertEvent($aEvent);
                 if(!empty($iId))
                     $this->_oModule->onPost($iId);
@@ -127,6 +131,10 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
                         'object_privacy_view' => $iObjectPrivacyView 
                     ]);
 
+                $sMethod = 'get_timeline_update_data';
+                if(bx_is_srv($oAlert->sUnit, $sMethod)) 
+                    list($aParamsSet, $aParamsSetBySource) = bx_srv($oAlert->sUnit, $sMethod, [$oAlert, $aHandler, $aEvent, [$aParamsSet, $aParamsSetBySource]]);
+
                 $this->_oModule->_oDb->updateEvent($aParamsSet, ['id' => $aEvent[$CNF['FIELD_ID']]]);
 
                 //--- Delete item cache.
@@ -172,6 +180,10 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
                 if(empty($aEvent) || !is_array($aEvent))
                     break;
 
+                $sMethod = 'get_timeline_delete_data';
+                if(bx_is_srv($oAlert->sUnit, $sMethod)) 
+                    $aEvent = bx_srv($oAlert->sUnit, $sMethod, [$oAlert, $aHandler, $aEvent]);
+
                 $this->_oModule->deleteEvent($aEvent);
                 break;
         }
@@ -185,21 +197,6 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
         ));
     }
 
-    protected function _getEventUpdate(&$oAlert, &$aHandler)
-    {
-        $aHandlers = $this->_oModule->_oDb->getHandlers([
-            'type' => 'by_group_key_type', 
-            'group' => $aHandler['group']
-        ]);
-
-        return $this->_oModule->_oDb->getEvents([
-            'browse' => 'descriptor', 
-            'type' => $oAlert->sUnit, 
-            'action' => $aHandlers[BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT]['alert_action'],
-            'object_id' => $oAlert->iObject
-        ]);
-    }
-
     protected function _getEventUpdateCommentEdited(&$oAlert, &$aHandler)
     {
         $aHandlers = $this->_oModule->_oDb->getHandlers([
@@ -359,7 +356,7 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
                 $this->_oModule->onFailed($iContentId);
 
                 if($bNotify)
-                    bx_alert($this->_oModule->getName(), 'publish_failed', $aContentInfo[$CNF['FIELD_ID']], $iSystemBotProfileId, array(
+                    bx_alert($this->_sModule, 'publish_failed', $aContentInfo[$CNF['FIELD_ID']], $iSystemBotProfileId, array(
                         'object_author_id' => $iAuthorProfileId,
                         'privacy_view' => BX_DOL_PG_ALL
                     ));
@@ -383,7 +380,7 @@ class BxTimelineResponse extends BxBaseModNotificationsResponse
         $this->_oModule->onPublished($iContentId);
 
         if($bNotify)
-            bx_alert($this->_oModule->getName(), 'publish_succeeded', $aContentInfo[$CNF['FIELD_ID']], $iSystemBotProfileId, array(
+            bx_alert($this->_sModule, 'publish_succeeded', $aContentInfo[$CNF['FIELD_ID']], $iSystemBotProfileId, array(
                 'object_author_id' => $iAuthorProfileId,
                 'privacy_view' => BX_DOL_PG_ALL
             ));