AntonLV 8 tahun lalu
induk
melakukan
ea54f48427

+ 89 - 2
modules/boonex/timeline/classes/BxTimelineCronHot.php

@@ -28,6 +28,78 @@ class BxTimelineCronHot extends BxDolCron
         if(!$this->_oModule->_oConfig->isHot())
             return;
 
+        $this->_oModule->_oDb->clearHot();
+
+        $this->_prepareTrackByDates();
+    }
+
+    protected function _prepareTrackByDates()
+    {
+        $iInterval = $this->_oModule->_oConfig->getHotInterval();
+        $sCommon = $this->_oModule->_oConfig->getPrefix('common_post') . 'post';
+
+        $aSystemsComments = BxDolCmts::getSystems();
+        $aSystemsVotes = BxDolVote::getSystems();
+        $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
+
+        $aModulesActive = array();
+        foreach($aModules as $aModule)
+            $aModulesActive[] = $aModule['name'];
+
+        $aTracksByDate = $this->_oModule->_oDb->getHotTrackByDate($iInterval);
+        $aTracksByDateComments = array();
+        $aTracksByDateVotes = array();
+
+        $aHandlers = $this->_oModule->_oConfig->getHandlers();
+        $aHandlersHidden = $this->_oModule->_oConfig->getHandlersHidden();
+        foreach($aHandlers as $sKey => $aHandler) {
+            if($aHandler['type'] != BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT || in_array($aHandler['id'], $aHandlersHidden))
+                continue;
+
+            $bCommon = $aHandler['alert_unit'] == $sCommon;
+            if(!$bCommon && !in_array($aHandler['alert_unit'], $aModulesActive))
+                continue;            
+
+            if(!$bCommon) {
+                $sModule = $aHandler['alert_unit'];
+                $oModule = BxDolModule::getInstance($sModule);
+                if(!$oModule)
+                    continue;
+
+                if(!empty($oModule->_oConfig->CNF['OBJECT_COMMENTS'])) {
+                    $sSystem = $oModule->_oConfig->CNF['OBJECT_COMMENTS'];
+                    if(isset($aSystemsComments[$sSystem]) && (int)$aSystemsComments[$sSystem]['is_on'] == 1)
+                        $aTracksByDateComments += $this->_oModule->_oDb->getHotTrackByCommentsDateModule($sModule, $aSystemsComments[$sSystem]['table'], $iInterval);
+                }
+
+                if(!empty($oModule->_oConfig->CNF['OBJECT_VOTES'])) {
+                    $sSystem = $oModule->_oConfig->CNF['OBJECT_VOTES'];
+                    if(isset($aSystemsVotes[$sSystem]) && (int)$aSystemsVotes[$sSystem]['is_on'] == 1)
+                        $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDateModule($sModule, $aSystemsVotes[$sSystem]['table_track'], $iInterval);
+                }
+            }
+            else {
+                $sSystem = $this->_oModule->_oConfig->getObject('comment');
+                if(isset($aSystemsComments[$sSystem]) && (int)$aSystemsComments[$sSystem]['is_on'] == 1)
+                    $aTracksByDateComments += $this->_oModule->_oDb->getHotTrackByCommentsDate($sCommon, $aSystemsComments[$sSystem]['table'], $iInterval);
+
+                $sSystem = $this->_oModule->_oConfig->getObject('vote');
+                if(isset($aSystemsVotes[$sSystem]) && (int)$aSystemsVotes[$sSystem]['is_on'] == 1)
+                    $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDate($sCommon, $aSystemsVotes[$sSystem]['table_track'], $iInterval);
+            }
+        }
+
+        $aTracks = array();
+        $aTracks = $this->_combineArrays($aTracks, $aTracksByDate);
+        $aTracks = $this->_combineArrays($aTracks, $aTracksByDateComments);
+        $aTracks = $this->_combineArrays($aTracks, $aTracksByDateVotes);
+
+        foreach($aTracks as $iId => $iDate)
+            $this->_oModule->_oDb->updateHotTrack(array('event_id' => $iId, 'value' => $iDate));
+    }
+
+    protected function _prepareTrackByVotesSum()
+    {
         $iInterval = $this->_oModule->_oConfig->getHotInterval();
         $sCommon = $this->_oModule->_oConfig->getPrefix('common_post') . 'post';
 
@@ -53,12 +125,12 @@ class BxTimelineCronHot extends BxDolCron
                 if(empty($oModule->_oConfig->CNF['OBJECT_VOTES']))
                     continue;
 
-                $sMethod = 'getHotTrackModule';
+                $sMethod = 'getHotTrackByVotesSumModule';
                 $sModule = $oModule->getName();
                 $sSystem = $oModule->_oConfig->CNF['OBJECT_VOTES'];
             }
             else {
-                $sMethod = 'getHotTrack';
+                $sMethod = 'getHotTrackByVotesSum';
                 $sModule = $sCommon;
                 $sSystem = $this->_oModule->_oConfig->getObject('vote');
             }
@@ -74,6 +146,21 @@ class BxTimelineCronHot extends BxDolCron
                 $this->_oModule->_oDb->updateHotTrack($aTrack);
         }
     }
+
+    protected function _combineArrays($a1, $a2)
+    {
+        foreach($a2 as $iId => $iDate) {
+            if(!isset($a1[$iId])) {
+                $a1[$iId] = $iDate;
+                continue;
+            }
+
+            if((int)$iDate > (int)$a1[$iId])
+                $a1[$iId] = $iDate;
+        }
+
+        return $a1;
+    }
 }
 
 /** @} */

+ 82 - 6
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -282,7 +282,78 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         return $this->getColumn("SELECT `event_id` FROM `" . $this->_sTableHotTrack . "`");
     }
 
-    public function getHotTrack($sModule, $sTableTrack, $iInterval = 24)
+    public function clearHot()
+    {
+        return $this->query("TRUNCATE TABLE `" . $this->_sTableHotTrack . "`");
+    }
+
+    public function getHotTrackByDate($iInterval = 24)
+    {
+        $sQuery = "SELECT 
+                `te`.`id` AS `event_id`,
+    			`te`.`date` AS `value`
+    		FROM `" . $this->_sTable . "` AS `te`
+    		WHERE `te`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+
+        return $this->getPairs($sQuery, 'event_id', 'value', array('interval' => $iInterval));
+    }
+
+    public function getHotTrackByCommentsDate($sModule, $sTableTrack, $iInterval = 24)
+    {
+        $sQuery = "SELECT 
+    			`te`.`id` as `event_id`,
+    			MAX(`tt`.`cmt_time`) AS `value`
+    		FROM `" . $this->_sTable . "` AS `te`
+    		INNER JOIN `" . $sTableTrack . "` AS `tt` ON `te`.`id`=`tt`.`cmt_object_id` AND `te`.`type`=:module 
+    		WHERE `tt`.`cmt_time` > (UNIX_TIMESTAMP() - 3600 * :interval) 
+    		GROUP BY `te`.`id`";
+
+        return $this->getPairs($sQuery, 'event_id', 'value', array('module' => $sModule, 'interval' => $iInterval));
+    }
+
+    public function getHotTrackByCommentsDateModule($sModule, $sTableTrack, $iInterval = 24)
+    {
+        $sQuery = "SELECT 
+    			`te`.`id` as `event_id`,
+    			MAX(`tt`.`cmt_time`) AS `value`
+    		FROM `" . $this->_sTable . "` AS `te`
+    		INNER JOIN `" . $sTableTrack . "` AS `tt` ON `te`.`object_id`=`tt`.`cmt_object_id` AND `te`.`type`=:module 
+    		WHERE `tt`.`cmt_time` > (UNIX_TIMESTAMP() - 3600 * :interval) 
+    		GROUP BY `te`.`object_id`";
+
+        return $this->getPairs($sQuery, 'event_id', 'value', array('module' => $sModule, 'interval' => $iInterval));
+    }
+
+    public function getHotTrackByVotesDate($sModule, $sTableTrack, $iInterval = 24)
+    {
+        $sQuery = "SELECT 
+    			`te`.`id` as `event_id`,
+    			MAX(`tt`.`date`) AS `value`
+    		FROM `" . $this->_sTable . "` AS `te`
+    		INNER JOIN `" . $sTableTrack . "` AS `tt` ON `te`.`id`=`tt`.`object_id` AND `te`.`type`=:module 
+    		WHERE `tt`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval) 
+    		GROUP BY `te`.`id`";
+
+        return $this->getPairs($sQuery, 'event_id', 'value', array('module' => $sModule, 'interval' => $iInterval));
+    }
+
+    public function getHotTrackByVotesDateModule($sModule, $sTableTrack, $iInterval = 24)
+    {
+        $sQuery = "SELECT 
+    			`te`.`id` as `event_id`,
+    			MAX(`tt`.`date`) AS `value`
+    		FROM `" . $this->_sTable . "` AS `te`
+    		INNER JOIN `" . $sTableTrack . "` AS `tt` ON `te`.`object_id`=`tt`.`object_id` AND `te`.`type`=:module 
+    		WHERE `tt`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval) 
+    		GROUP BY `te`.`object_id`";
+
+        return $this->getPairs($sQuery, 'event_id', 'value', array('module' => $sModule, 'interval' => $iInterval));
+    }
+
+    /**
+     * Hot Track by Sum of Votes during specified Period is currently disabled.
+     */
+    public function getHotTrackByVotesSum($sModule, $sTableTrack, $iInterval = 24)
     {
         $sQuery = "SELECT 
     			`te`.`id` as `event_id`,
@@ -295,7 +366,10 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         return $this->getAll($sQuery, array('module' => $sModule, 'interval' => $iInterval));
     }
 
-    public function getHotTrackModule($sModule, $sTableTrack, $iInterval = 24)
+    /**
+     * Hot Track by Sum of Votes during specified Period is currently disabled.
+     */
+    public function getHotTrackByVotesSumModule($sModule, $sTableTrack, $iInterval = 24)
     {
         $sQuery = "SELECT 
     			`te`.`id` as `event_id`,
@@ -395,19 +469,21 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
 			switch($aParams['type']) {
 				case BX_TIMELINE_TYPE_HOT:
+                    $sOrderClause = "`{$this->_sTableHotTrack}`.`value` DESC, ";
+                    break;
+
 				case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
 				case BX_BASE_MOD_NTFS_TYPE_CONNECTIONS:
 				case BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS:
-					$sOrderClause = "`{$this->_sTable}`.`sticked` DESC";
+					$sOrderClause = "`{$this->_sTable}`.`sticked` DESC, ";
 					break;
 
 				case BX_BASE_MOD_NTFS_TYPE_OWNER:
-					$sOrderClause = "`{$this->_sTable}`.`pinned` DESC";
+					$sOrderClause = "`{$this->_sTable}`.`pinned` DESC, ";
 					break;
 			}
 
-			if(!empty($sOrderClause))
-				$sOrderClause = "ORDER BY " . $sOrderClause . ", `{$this->_sTable}`.`date` DESC";
+            $sOrderClause = "ORDER BY " . $sOrderClause . "`{$this->_sTable}`.`date` DESC";
 		}
 
         if(isset($aParams['count']) && $aParams['count'] === true) {

+ 1 - 1
modules/boonex/timeline/install/sql/install.sql

@@ -257,7 +257,7 @@ CREATE TABLE IF NOT EXISTS `bx_timeline_reports_track` (
 CREATE TABLE IF NOT EXISTS `bx_timeline_hot_track` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `event_id` int(11) NOT NULL default '0',
-  `value` tinyint(4) NOT NULL default '0',
+  `value` int(11) NOT NULL default '0',
   PRIMARY KEY (`id`),
   UNIQUE KEY `event_id` (`event_id`)
 );