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

Ticket #255 - Clean up: Online pages in Profile based modules.

AntonLV 10 лет назад
Родитель
Сommit
e786ae790f

+ 10 - 8
inc/classes/BxDolSession.php

@@ -90,14 +90,16 @@ class BxDolSession extends BxDol implements iBxDolSingleton
         if(empty($sId) && isset($_COOKIE[BX_DOL_SESSION_COOKIE]))
             $sId = bx_process_input($_COOKIE[BX_DOL_SESSION_COOKIE]);
 
-        $mixedSession = array();
-        if(($mixedSession = $this->oDb->exists($sId)) !== false) {
-            $this->sId = $mixedSession['id'];
-            $this->iUserId = (int)$mixedSession['user_id'];
-            $this->aData = unserialize($mixedSession['data']);
-            return true;
-        } else
-            return false;
+        $mixedSession = $this->oDb->exists($sId);
+        if($mixedSession === false) 
+        	return false;
+
+		$this->sId = $mixedSession['id'];
+		$this->iUserId = (int)$mixedSession['user_id'];
+		$this->aData = unserialize($mixedSession['data']);
+
+		$this->oDb->update($this->sId);
+		return true;
     }
 
     function getId()

+ 8 - 6
inc/classes/BxDolSessionQuery.php

@@ -32,13 +32,15 @@ class BxDolSessionQuery extends BxDolDb
     }
     function save($sId, $aSet)
     {
-        $sSetClause = "`id`=:id";
-        foreach($aSet as $sKey => $sValue)
-            $sSetClause .= ", `" . $sKey . "`=:" . $sKey;
-        $sSetClause .= ", `date`=UNIX_TIMESTAMP()";
+    	$aSet['id'] = $sId;
+        return (int)$this->query("REPLACE INTO `" . $this->sTable . "` SET " . $this->arrayToSQL($aSet) . ", `date`=UNIX_TIMESTAMP()") > 0;
+    }
+	function update($sId, $aSet = array())
+    {
+    	$sSet = !empty($aSet) ? $this->arrayToSQL($aSet) . ", " : "";
+    	$sSet .= "`date`=UNIX_TIMESTAMP()";
 
-        $sSql = $this->prepare("REPLACE INTO `" . $this->sTable . "` SET " . $sSetClause);
-        return (int)$this->query($sSql, array_merge(array('id' => $sId), $aSet)) > 0;
+        return (int)$this->query("UPDATE `" . $this->sTable . "` SET " . $sSet . " WHERE `id`=:id", array('id' => $sId)) > 0;
     }
     function delete($sId)
     {

+ 2 - 0
install/sql/system.sql

@@ -387,6 +387,7 @@ INSERT INTO `sys_options_categories`(`type_id`, `name`, `caption`, `hidden`, `or
 SET @iCategoryId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
+(@iCategoryId, 'sys_account_online_time', '_adm_stg_cpt_option_sys_account_online_time', '1', 'digit', '', 'Avail', '_adm_stg_err_option_sys_account_online_time', 1),
 (@iCategoryId, 'sys_account_autoapproval', '_adm_stg_cpt_option_sys_account_autoapproval', 'on', 'checkbox', '', '', '', 10);
 
 
@@ -660,6 +661,7 @@ CREATE TABLE IF NOT EXISTS `sys_sessions` (
   `data` text collate utf8_unicode_ci,
   `date` int(10) unsigned NOT NULL default '0',
   PRIMARY KEY (`id`),
+  UNIQUE KEY `session` (`id`, `user_id`),
   KEY `user_id` (`user_id`),
   KEY `date` (`date`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

+ 2 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1146,6 +1146,8 @@
 	<string name="_adm_stg_cpt_option_site_email_notify"><![CDATA[Email to send site messages from]]></string>
 	<string name="_adm_stg_cpt_option_site_title"><![CDATA[Site title]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_autoapproval"><![CDATA[Automatic account activation after creation]]></string>
+	<string name="_adm_stg_cpt_option_sys_account_online_time"><![CDATA[Online status timeframe (minutes)]]></string>
+	<string name="_adm_stg_err_option_sys_account_online_time"><![CDATA[You need to enter a value greater then zero.]]></string>
 	<string name="_adm_stg_cpt_option_sys_acl_expire_notification_days"><![CDATA[Number of days before membership expiration to notify members (-1 = after expiration)]]></string>
 	<string name="_adm_stg_cpt_option_sys_acl_expire_notify_once"><![CDATA[Notify members about membership expiration only once (every day otherwise)]]></string>
 	<string name="_adm_stg_cpt_option_sys_add_nofollow"><![CDATA[Add "nofollow" attribute for external links]]></string>

+ 19 - 6
modules/boonex/organizations/classes/BxOrgsSearchResult.php

@@ -29,6 +29,7 @@ class BxOrgsSearchResult extends BxBaseModProfileSearchResult
                 'perofileStatus' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
                 'perofileType' => array('value' => 'bx_organizations', 'field' => 'type', 'operator' => '='),
                 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_organizations_data'),
+        		'online' => array('value' => '', 'field' => 'date', 'operator' => '>', 'table' => 'sys_sessions'),
             ),
             'join' => array (
                 'profile' => array(
@@ -45,6 +46,13 @@ class BxOrgsSearchResult extends BxBaseModProfileSearchResult
                     'onField' => 'id',
                     'joinFields' => array(),
                 ),
+                'session' => array(
+                    'type' => 'INNER',
+                    'table' => 'sys_sessions',
+                    'mainField' => 'account_id',
+                    'onField' => 'user_id',
+                    'joinFields' => array('date'),
+                ),
             ),
             'paginate' => array('perPage' => 20, 'start' => 0),
             'sorting' => 'none',
@@ -101,7 +109,8 @@ class BxOrgsSearchResult extends BxBaseModProfileSearchResult
 			case 'online':
                 $this->aCurrent['rss']['link'] = 'modules/?r=orgs/rss/' . $sMode;
                 $this->aCurrent['title'] = _t('_bx_orgs_page_title_browse_online');
-                $this->aCurrent['sorting'] = 'active';
+                $this->aCurrent['restriction']['online']['value'] = time() - 60 * (int)getParam('sys_account_online_time');
+                $this->aCurrent['sorting'] = 'online';
                 $this->sBrowseUrl = 'page.php?i=organizations-online';
                 break;
 
@@ -122,11 +131,15 @@ class BxOrgsSearchResult extends BxBaseModProfileSearchResult
     function getAlterOrder()
     {
         switch ($this->aCurrent['sorting']) {
-        case 'none':
-            return array('order' => ' ORDER BY `sys_accounts`.`logged` DESC ');
-        case 'last':
-        default:                        
-            return array('order' => ' ORDER BY `bx_organizations_data`.`added` DESC ');
+	        case 'none':
+	            return array('order' => ' ORDER BY `sys_accounts`.`logged` DESC ');
+			case 'active':
+	            return array('order' => ' ORDER BY `sys_accounts`.`logged` DESC ');
+			case 'online':
+	            return array('order' => ' ORDER BY `sys_sessions`.`date` DESC ');
+	        case 'last':
+	        default:                        
+	            return array('order' => ' ORDER BY `bx_organizations_data`.`added` DESC ');
         }
     }
 

+ 19 - 8
modules/boonex/persons/classes/BxPersonsSearchResult.php

@@ -29,6 +29,7 @@ class BxPersonsSearchResult extends BxBaseModProfileSearchResult
                 'perofileStatus' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
                 'perofileType' => array('value' => 'bx_persons', 'field' => 'type', 'operator' => '='),
                 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_persons_data'),
+        		'online' => array('value' => '', 'field' => 'date', 'operator' => '>', 'table' => 'sys_sessions'),
             ),
             'join' => array (
                 'profile' => array(
@@ -45,6 +46,13 @@ class BxPersonsSearchResult extends BxBaseModProfileSearchResult
                     'onField' => 'id',
                     'joinFields' => array(),
                 ),
+                'session' => array(
+                    'type' => 'INNER',
+                    'table' => 'sys_sessions',
+                    'mainField' => 'account_id',
+                    'onField' => 'user_id',
+                    'joinFields' => array('date'),
+                ),
             ),
             'paginate' => array('perPage' => 20, 'start' => 0),
             'sorting' => 'none',
@@ -101,7 +109,8 @@ class BxPersonsSearchResult extends BxBaseModProfileSearchResult
 			case 'online':
                 $this->aCurrent['rss']['link'] = 'modules/?r=persons/rss/' . $sMode;
                 $this->aCurrent['title'] = _t('_bx_persons_page_title_browse_online');
-                $this->aCurrent['sorting'] = 'active';
+                $this->aCurrent['restriction']['online']['value'] = time() - 60 * (int)getParam('sys_account_online_time');
+                $this->aCurrent['sorting'] = 'online';
                 $this->sBrowseUrl = 'page.php?i=persons-online';
                 break;
 
@@ -122,13 +131,15 @@ class BxPersonsSearchResult extends BxBaseModProfileSearchResult
     function getAlterOrder()
     {
         switch ($this->aCurrent['sorting']) {
-        case 'none':
-            return array();
-        case 'active':
-            return array('order' => ' ORDER BY `sys_accounts`.`logged` DESC ');
-        case 'last':
-        default:
-            return array('order' => ' ORDER BY `bx_persons_data`.`added` DESC ');
+	        case 'none':
+	            return array();
+	        case 'active':
+	            return array('order' => ' ORDER BY `sys_accounts`.`logged` DESC ');
+			case 'online':
+	            return array('order' => ' ORDER BY `sys_sessions`.`date` DESC ');
+	        case 'last':
+	        default:
+	            return array('order' => ' ORDER BY `bx_persons_data`.`added` DESC ');
         }
     }
 

+ 2 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -1146,6 +1146,8 @@
 	<string name="_adm_stg_cpt_option_site_email_notify"><![CDATA[Имейл, с которого будут посылаться сообщения от сайта]]></string>
 	<string name="_adm_stg_cpt_option_site_title"><![CDATA[Название сайта]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_autoapproval"><![CDATA[Автоматическая активация аккаунта после создания]]></string>
+	<string name="_adm_stg_cpt_option_sys_account_online_time"><![CDATA[Временные рамки статуса "онлайн" (минуты)]]></string>
+	<string name="_adm_stg_err_option_sys_account_online_time"><![CDATA[Вам необходимо ввести значение больше нуля.]]></string>
 	<string name="_adm_stg_cpt_option_sys_acl_expire_notification_days"><![CDATA[За сколько дней до окончания членства оповестить пользователя об окончании (-1 = после окончания)]]></string>
 	<string name="_adm_stg_cpt_option_sys_acl_expire_notify_once"><![CDATA[Оповещать пользователей об окончании членства только одинажды (каждый день в противном случае)]]></string>
 	<string name="_adm_stg_cpt_option_sys_add_nofollow"><![CDATA[Добавить атрибут "nofollow" для внешних ссылок]]></string>