Parcourir la source

Merge branch 'master' of https://github.com/unaio/una

AntonLV il y a 7 ans
Parent
commit
e44f998a00
2 fichiers modifiés avec 48 ajouts et 11 suppressions
  1. 47 2
      inc/classes/BxDolPush.php
  2. 1 9
      modules/boonex/nexus/classes/BxNexusModule.php

+ 47 - 2
inc/classes/BxDolPush.php

@@ -43,6 +43,49 @@ class BxDolPush extends BxDolFactory implements iBxDolSingleton
         return $GLOBALS['bxDolClasses'][__CLASS__];
     }
     
+    /**
+     * @param $a - array to fill with notification counter per module
+     * @return total number of notifications
+     */
+    public static function getNotificationsCount($iProfileId = 0, &$aBubbles = null)
+    {    
+        $iMemberIdCookie = null;
+        $bLoggedMemberGlobals = null;
+        if ($iProfileId) {
+            if (!empty($_COOKIE['memberID']))
+                $iMemberIdCookie = $_COOKIE['memberID'];
+            if (!empty($GLOBALS['logged']['member']))
+                $bLoggedMemberGlobals = $GLOBALS['logged']['member'];
+            $_COOKIE['memberID'] = $iProfileId;
+            $GLOBALS['logged']['member'] = true;
+        }
+
+        $oMenu = BxDolMenu::getObjectInstance('sys_account_notifications'); // sys_toolbar_member
+        $a = $oMenu->getMenuItems();
+        $iBubbles = 0;
+        foreach ($a as $r) {
+            if (!$r['bx_if:addon']['condition'])
+                continue;
+            if (null !== $aBubbles)
+                $aBubbles[$r['name']] = $r['bx_if:addon']['content']['addon'];
+            $iBubbles += $r['bx_if:addon']['content']['addon'];
+        }
+
+        if ($iProfileId) {
+            if (null === $iMemberIdCookie)
+                unset($_COOKIE['memberID']);
+            else
+                $_COOKIE['memberID'] = $iMemberIdCookie;
+
+            if (null === $bLoggedMemberGlobals)
+                unset($GLOBALS['logged']['member']);
+            else
+                $GLOBALS['logged']['member'] = $bLoggedMemberGlobals;
+        }
+
+        return $iBubbles;
+    }
+
     public function send($iProfileId, $aMessage, $bAddToQueue = false)
     {
         if(empty($this->_sAppId) || empty($this->_sRestApi))
@@ -51,6 +94,8 @@ class BxDolPush extends BxDolFactory implements iBxDolSingleton
         if($bAddToQueue && BxDolQueuePush::getInstance()->add($iProfileId, $aMessage))
             return true;
 
+        $iBadgeCount = $this->getNotificationsCount($iProfileId);
+    
 		$aFields = array(
 			'app_id' => $this->_sAppId,
 			'filters' => array(
@@ -61,8 +106,8 @@ class BxDolPush extends BxDolFactory implements iBxDolSingleton
             'web_url' => !empty($aMessage['url']) ? $aMessage['url'] : '',
             'data' => array('url' => !empty($aMessage['url']) ? $aMessage['url'] : ''),
             'chrome_web_icon' => !empty($aMessage['icon']) ? $aMessage['icon'] : '',
-            'ios_badgeType' => 'Increase',
-            'ios_badgeCount' => 1,
+            'ios_badgeType' => 'SetTo',
+            'ios_badgeCount' => $iBadgeCount,
 		);
 
 		$oChannel = curl_init();

+ 1 - 9
modules/boonex/nexus/classes/BxNexusModule.php

@@ -40,16 +40,8 @@ class BxNexusModule extends BxDolModule
 
         $this->redirects();
 
-        $oMenu = BxDolMenu::getObjectInstance('sys_account_notifications'); // sys_toolbar_member
-        $a = $oMenu->getMenuItems();
-        $iBubbles = 0;
         $aBubbles = array();
-        foreach ($a as $r) {
-            if (!$r['bx_if:addon']['condition'])
-                continue;
-            $aBubbles[$r['name']] = $r['bx_if:addon']['content']['addon'];
-            $iBubbles += $r['bx_if:addon']['content']['addon'];
-        }
+        $iBubbles = BxDolPush::getNotificationsCount(0, $aBubbles);
 
         $s = $this->_oTemplate->parseHtmlByName('styles.html', array());
         if ($sCustomStyles = getParam('bx_nexus_option_styles'))