1
0
Эх сурвалжийг харах

#1959 Add service method which returns number of online users

RomanL 7 жил өмнө
parent
commit
2a1e802361

+ 18 - 0
inc/classes/BxDolProfileQuery.php

@@ -250,6 +250,24 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
         	LIMIT 1", $iId, (int)getParam('sys_account_online_time'));
         return (int)$this->getOne($sSql) > 0;
     }
+    
+    /**
+     * Get online profiles count 
+     * @return online profiles count 
+     */
+    public function getOnlineCount()
+    {
+        $sSql = $this->prepare("SELECT 
+        		COUNT(`tp`.`id`) 
+        	FROM `sys_profiles` AS `tp` 
+        	INNER JOIN `sys_accounts` AS `ta` ON `tp`.`account_id`=`ta`.`id` 
+        	INNER JOIN `sys_sessions` AS `ts` ON `tp`.`account_id`=`ts`.`user_id` 
+        	WHERE 
+        		`ta`.`profile_id`=`tp`.`id` AND 
+        		`ts`.`date` > (UNIX_TIMESTAMP() - 60 * ?) 
+        	LIMIT 1", (int)getParam('sys_account_online_time'));
+        return (int)$this->getOne($sSql);
+    }
 
     /**
      * Get profile field by specified field name and value.

+ 6 - 0
template/scripts/BxBaseServiceProfiles.php

@@ -110,6 +110,12 @@ class BxBaseServiceProfiles extends BxDol
         return $iNum;
     }
 
+    public function serviceGetCountOnlineProfiles ()
+    {
+        $oProfilesQuery = BxDolProfileQuery::getInstance();
+        return $oProfilesQuery->getOnlineCount();
+    }
+    
     public function serviceGetProfilesModules ()
     {
         if (getParam('sys_db_cache_enable')) { // get list of profiles  modules from db cache, cache is invalidated when new module is installed