Просмотр исходного кода

Ticket #4148 - Build-in API support: Update Notifications counter.

AntonLV 3 лет назад
Родитель
Сommit
efa05bbb79
1 измененных файлов с 13 добавлено и 4 удалено
  1. 13 4
      modules/boonex/notifications/classes/BxNtfsModule.php

+ 13 - 4
modules/boonex/notifications/classes/BxNtfsModule.php

@@ -240,6 +240,8 @@ class BxNtfsModule extends BxBaseModNotificationsModule
                 $aParams['start'] = end($aContent)['id'];
             }
 
+            $this->markAsRead($iOwnerId, $aParams);
+
             return [bx_api_get_block('browse', [
                 'unit' => 'notifications',  
                 'request_url' => '/api.php?r=bx_notifications/get_data/&params[]=',
@@ -251,10 +253,7 @@ class BxNtfsModule extends BxBaseModNotificationsModule
 
         $sContent = $this->_oTemplate->getViewBlock($aParams);
 
-        $aParams['browse'] = 'first';
-    	$aEvent = $this->_oDb->getEvents($aParams);
-    	if(!empty($aEvent))
-            $this->_oDb->markAsRead($iOwnerId, $aEvent['id']);
+        $this->markAsRead($iOwnerId, $aParams);
 
         return ['content' => $sContent]; 
     }
@@ -661,6 +660,16 @@ class BxNtfsModule extends BxBaseModNotificationsModule
         }
     }
 
+    public function markAsRead($iOwnerId, $aParams)
+    {
+        $aParams['browse'] = 'first';
+    	$aEvent = $this->_oDb->getEvents($aParams);
+    	if(empty($aEvent) || !is_array($aEvent))
+            return false;
+
+        return $this->_oDb->markAsRead($iOwnerId, $aEvent['id']) !== false;
+    }
+
     /*
      * INTERNAL METHODS
      */