AntonLV před 10 roky
rodič
revize
54e66cc1cb

+ 9 - 0
inc/classes/BxDolAccount.php

@@ -227,6 +227,15 @@ class BxDolAccount extends BxDol
         return $aAccountInfo['email'];
     }
 
+    /**
+     * Is account online
+     */
+	public function isOnline($iAccountId = false)
+    {
+        $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
+        return $this->_oQuery->isOnline($iAccountId);
+    }
+
     /**
      * Validate account.
      * @param $s - account identifier (id or email)

+ 18 - 0
inc/classes/BxDolAccountQuery.php

@@ -108,6 +108,24 @@ class BxDolAccountQuery extends BxDolDb implements iBxDolSingleton
         return $this->_getFieldByField('password', 'id', (int)$iID);
     }
 
+	/**
+     * Is account online by id
+     * @param  int $iId account id 
+     * @return account online status
+     */
+    public function isOnline($iId)
+    {
+        $sSql = $this->prepare("SELECT 
+        		`ta`.`id` 
+        	FROM `sys_accounts` AS `ta` 
+        	INNER JOIN `sys_sessions` AS `ts` ON `ta`.`id`=`ts`.`user_id` 
+        	WHERE 
+        		`ta`.`id` = ? AND 
+        		`ts`.`date` > (UNIX_TIMESTAMP() - 60 * ?) 
+        	LIMIT 1", $iId, (int)getParam('sys_account_online_time'));
+        return (int)$this->getOne($sSql) > 0;
+    }
+
     /**
      * Update last logged in time
      * @param $sPasswordHash - password hash

+ 9 - 0
inc/classes/BxDolProfile.php

@@ -157,6 +157,15 @@ class BxDolProfile extends BxDol implements iBxDolProfile
         return BX_PROFILE_STATUS_ACTIVE == $this->getStatus($iProfileId);
     }
 
+	/**
+     * Is profile online
+     */
+	public function isOnline($iProfileId = false)
+    {
+        $iProfileId = (int)$iProfileId ? $iProfileId : $this->_iProfileID;
+        return $this->_oQuery->isOnline($iProfileId);
+    }
+
     /**
      * Get profile status
      */

+ 20 - 0
inc/classes/BxDolProfileQuery.php

@@ -178,6 +178,26 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
         return $this->_getDataByField('id', (int)$iID);
     }
 
+	/**
+     * Is profile online by id
+     * @param  int $iId profile id
+     * @return profile online status
+     */
+    public function isOnline($iId)
+    {
+        $sSql = $this->prepare("SELECT 
+        		`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 
+        		`tp`.`id` = ? AND 
+        		`ta`.`profile_id`=`tp`.`id` AND 
+        		`ts`.`date` > (UNIX_TIMESTAMP() - 60 * ?) 
+        	LIMIT 1", $iId, (int)getParam('sys_account_online_time'));
+        return (int)$this->getOne($sSql) > 0;
+    }
+
     /**
      * Get profile field by specified field name and value.
      * In most cases it is for internal usage only.