Parcourir la source

Ticket #3717 - Timeline: Maximum age of post that can be included in HOT feed.

AntonLV il y a 4 ans
Parent
commit
35d3cf9efb

+ 1 - 0
modules/boonex/russian/data/langs/bx_timeline/ru.xml

@@ -44,6 +44,7 @@
     <string name="_bx_timeline_option_hot_sources_content"><![CDATA[Добавление контента]]></string>
     <string name="_bx_timeline_option_hot_sources_comment"><![CDATA[Добавление комментария]]></string>
     <string name="_bx_timeline_option_hot_sources_vote"><![CDATA[Добавление голоса]]></string>
+    <string name="_bx_timeline_option_hot_threshold_age"><![CDATA[Максимальный возраст поста, который включается в 'горячую' хронику (в днях, 0 - без ограничений)]]></string>
     <string name="_bx_timeline_option_hot_threshold_comment"><![CDATA[Минимальное количество комментариев, необходимое для появления контента в 'горячей' хронике]]></string>
     <string name="_bx_timeline_option_hot_threshold_vote"><![CDATA[Минимальное количество голосов, необходимое для появления контента в 'горячей' хронике]]></string>
     <string name="_bx_timeline_option_hot_interval"><![CDATA[Интервал времени (в часах) для получения 'горячих' событий]]></string>

+ 3 - 1
modules/boonex/timeline/classes/BxTimelineConfig.php

@@ -45,6 +45,7 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
 
     protected $_bHot;
     protected $_iHotInterval;
+    protected $_iHotThresholdContent;
     protected $_iHotThresholdComment;
     protected $_iHotThresholdVote;
     protected $_aHotSources;
@@ -416,6 +417,7 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         $this->_sAttachmentsLayout = getParam($sOptionPrefix . 'attachments_layout');
 
         $this->_bHot = getParam($sOptionPrefix . 'enable_hot') == 'on';
+        $this->_iHotThresholdContent = (int)getParam($sOptionPrefix . 'hot_threshold_age');
         $this->_iHotThresholdComment = (int)getParam($sOptionPrefix . 'hot_threshold_comment');
         $this->_iHotThresholdVote = (int)getParam($sOptionPrefix . 'hot_threshold_vote');
         $this->_iHotInterval = (int)getParam($sOptionPrefix . 'hot_interval');
@@ -546,7 +548,7 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
 
     public function getHotThreshold($sSource)
     {
-        if(!in_array($sSource, [BX_TIMELINE_HFS_COMMENT, BX_TIMELINE_HFS_VOTE]))
+        if(!in_array($sSource, [BX_TIMELINE_HFS_CONTENT, BX_TIMELINE_HFS_COMMENT, BX_TIMELINE_HFS_VOTE]))
             return false;
 
         return $this->{'_iHotThreshold' . ucfirst($sSource)};

+ 7 - 6
modules/boonex/timeline/classes/BxTimelineCronHot.php

@@ -55,6 +55,7 @@ class BxTimelineCronHot extends BxDolCron
         $bHfsComment = $this->_oModule->_oConfig->isHotSource(BX_TIMELINE_HFS_COMMENT);
         $bHfsVote = $this->_oModule->_oConfig->isHotSource(BX_TIMELINE_HFS_VOTE);
 
+        $iHftContent = $this->_oModule->_oConfig->getHotThreshold(BX_TIMELINE_HFS_CONTENT);
         $iHftComments = $this->_oModule->_oConfig->getHotThreshold(BX_TIMELINE_HFS_COMMENT);
         $iHftVotes = $this->_oModule->_oConfig->getHotThreshold(BX_TIMELINE_HFS_VOTE);
 
@@ -77,20 +78,20 @@ class BxTimelineCronHot extends BxDolCron
                 if($bHfsComment && !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, $iHftComments);
+                        $aTracksByDateComments += $this->_oModule->_oDb->getHotTrackByCommentsDateModule($sModule, $aSystemsComments[$sSystem]['table'], $iInterval, $iHftContent, $iHftComments);
                 }
 
                 if($bHfsVote) {
                     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, $iHftVotes);
+                            $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDateModule($sModule, $aSystemsVotes[$sSystem]['table_track'], $iInterval, $iHftContent, $iHftVotes);
                     }
 
                     if(!empty($oModule->_oConfig->CNF['OBJECT_REACTIONS'])) {
                         $sSystem = $oModule->_oConfig->CNF['OBJECT_REACTIONS'];
                         if(isset($aSystemsVotes[$sSystem]) && (int)$aSystemsVotes[$sSystem]['is_on'] == 1)
-                            $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDateModule($sModule, $aSystemsVotes[$sSystem]['table_track'], $iInterval, $iHftVotes);
+                            $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDateModule($sModule, $aSystemsVotes[$sSystem]['table_track'], $iInterval, $iHftContent, $iHftVotes);
                     }
                 }
             }
@@ -98,17 +99,17 @@ class BxTimelineCronHot extends BxDolCron
                 if($bHfsComment) {
                     $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, $iHftComments);
+                        $aTracksByDateComments += $this->_oModule->_oDb->getHotTrackByCommentsDate($sCommon, $aSystemsComments[$sSystem]['table'], $iInterval, $iHftContent, $iHftComments);
                 }
 
                 if($bHfsVote) {
                     $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, $iHftVotes);
+                        $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDate($sCommon, $aSystemsVotes[$sSystem]['table_track'], $iInterval, $iHftContent, $iHftVotes);
 
                     $sSystem = $this->_oModule->_oConfig->getObject('reaction');
                     if(isset($aSystemsVotes[$sSystem]) && (int)$aSystemsVotes[$sSystem]['is_on'] == 1)
-                        $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDate($sCommon, $aSystemsVotes[$sSystem]['table_track'], $iInterval, $iHftVotes);
+                        $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDate($sCommon, $aSystemsVotes[$sSystem]['table_track'], $iInterval, $iHftContent, $iHftVotes);
                 }
             }
         }

+ 52 - 20
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -383,18 +383,26 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         return $this->getPairs($sQuery, 'event_id', 'value', $aBindings);
     }
 
-    public function getHotTrackByCommentsDate($sModule, $sTableTrack, $iInterval = 24, $iThreshold = 0)
+    public function getHotTrackByCommentsDate($sModule, $sTableTrack, $iInterval = 24, $iThresholdAge = 0, $iThresholdCount = 0)
     {
         $aBindings = [
             'module' => $sModule, 
             'interval' => $iInterval
         ];
 
+        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`cmt_time` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+
+        if($iThresholdAge != 0) {
+            $aBindings['threshold_age'] = $iThresholdAge;
+
+            $sQueryWhere .= " AND (UNIX_TIMESTAMP() - `te`.`date`) / 86400 <= :threshold_age";
+        }
+
         $sQueryGroup = "`te`.`id`";
-        if($iThreshold != 0) {
-            $aBindings['threshold'] = $iThreshold;
+        if($iThresholdCount != 0) {
+            $aBindings['threshold_count'] = $iThresholdCount;
 
-            $sQueryGroup .= " HAVING COUNT(DISTINCT `tt`.`cmt_author_id`) >= :threshold";
+            $sQueryGroup .= " HAVING COUNT(DISTINCT `tt`.`cmt_author_id`) >= :threshold_count";
         }
 
         $sQuery = "SELECT 
@@ -402,24 +410,32 @@ class BxTimelineDb extends BxBaseModNotificationsDb
                 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`.`object_owner_id`<>`tt`.`cmt_author_id` AND `te`.`type`=:module 
-            WHERE (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`cmt_time` > (UNIX_TIMESTAMP() - 3600 * :interval) 
+            WHERE 1 " . $sQueryWhere . " 
             GROUP BY " . $sQueryGroup;
 
         return $this->getPairs($sQuery, 'event_id', 'value', $aBindings);
     }
 
-    public function getHotTrackByCommentsDateModule($sModule, $sTableTrack, $iInterval = 24, $iThreshold = 0)
+    public function getHotTrackByCommentsDateModule($sModule, $sTableTrack, $iInterval = 24, $iThresholdAge = 0, $iThresholdCount = 0)
     {
         $aBindings = [
             'module' => $sModule, 
             'interval' => $iInterval
         ];
 
+        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`cmt_time` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+
+        if($iThresholdAge != 0) {
+            $aBindings['threshold_age'] = $iThresholdAge;
+
+            $sQueryWhere .= " AND (UNIX_TIMESTAMP() - `te`.`date`) / 86400 <= :threshold_age";
+        }
+
         $sQueryGroup = "`te`.`object_id`";
-        if($iThreshold != 0) {
-            $aBindings['threshold'] = $iThreshold;
+        if($iThresholdCount != 0) {
+            $aBindings['threshold_count'] = $iThresholdCount;
 
-            $sQueryGroup .= " HAVING COUNT(DISTINCT `tt`.`cmt_author_id`) >= :threshold";
+            $sQueryGroup .= " HAVING COUNT(DISTINCT `tt`.`cmt_author_id`) >= :threshold_count";
         }
 
         $sQuery = "SELECT 
@@ -427,24 +443,32 @@ class BxTimelineDb extends BxBaseModNotificationsDb
                 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`.`object_owner_id`<>`tt`.`cmt_author_id` AND `te`.`type`=:module
-            WHERE (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`cmt_time` > (UNIX_TIMESTAMP() - 3600 * :interval) 
+            WHERE 1 " . $sQueryWhere . " 
             GROUP BY " . $sQueryGroup;
 
         return $this->getPairs($sQuery, 'event_id', 'value', $aBindings);
     }
 
-    public function getHotTrackByVotesDate($sModule, $sTableTrack, $iInterval = 24, $iThreshold = 0)
+    public function getHotTrackByVotesDate($sModule, $sTableTrack, $iInterval = 24, $iThresholdAge = 0, $iThresholdCount = 0)
     {
         $aBindings = [
             'module' => $sModule, 
             'interval' => $iInterval
         ];
 
+        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+
+        if($iThresholdAge != 0) {
+            $aBindings['threshold_age'] = $iThresholdAge;
+
+            $sQueryWhere .= " AND (UNIX_TIMESTAMP() - `te`.`date`) / 86400 <= :threshold_age";
+        }
+
         $sQueryGroup = "`te`.`id`";
-        if($iThreshold != 0) {
-            $aBindings['threshold'] = $iThreshold;
+        if($iThresholdCount != 0) {
+            $aBindings['threshold_count'] = $iThresholdCount;
 
-            $sQueryGroup .= " HAVING COUNT(DISTINCT `tt`.`author_id`) >= :threshold";
+            $sQueryGroup .= " HAVING COUNT(DISTINCT `tt`.`author_id`) >= :threshold_count";
         }
 
         $sQuery = "SELECT 
@@ -452,24 +476,32 @@ class BxTimelineDb extends BxBaseModNotificationsDb
                 MAX(`tt`.`date`) AS `value`
             FROM `" . $this->_sTable . "` AS `te`
             INNER JOIN `" . $sTableTrack . "` AS `tt` ON `te`.`id`=`tt`.`object_id` AND `te`.`object_owner_id`<>`tt`.`author_id` AND `te`.`type`=:module 
-            WHERE (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval) 
+            WHERE 1 " . $sQueryWhere . " 
             GROUP BY " . $sQueryGroup;
 
         return $this->getPairs($sQuery, 'event_id', 'value', $aBindings);
     }
 
-    public function getHotTrackByVotesDateModule($sModule, $sTableTrack, $iInterval = 24, $iThreshold = 0)
+    public function getHotTrackByVotesDateModule($sModule, $sTableTrack, $iInterval = 24, $iThresholdAge = 0, $iThresholdCount = 0)
     {
         $aBindings = [
             'module' => $sModule, 
             'interval' => $iInterval
         ];
 
+        $sQueryWhere = " AND (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval)";
+
+        if($iThresholdAge != 0) {
+            $aBindings['threshold_age'] = $iThresholdAge;
+
+            $sQueryWhere .= " AND (UNIX_TIMESTAMP() - `te`.`date`) / 86400 <= :threshold_age";
+        }
+
         $sQueryGroup = "`te`.`object_id`";
-        if($iThreshold != 0) {
-            $aBindings['threshold'] = $iThreshold;
+        if($iThresholdCount != 0) {
+            $aBindings['threshold_count'] = $iThresholdCount;
 
-            $sQueryGroup .= " HAVING COUNT(DISTINCT `tt`.`author_id`) >= :threshold";
+            $sQueryGroup .= " HAVING COUNT(DISTINCT `tt`.`author_id`) >= :threshold_count";
         }
 
         $sQuery = "SELECT 
@@ -477,7 +509,7 @@ class BxTimelineDb extends BxBaseModNotificationsDb
                 MAX(`tt`.`date`) AS `value`
             FROM `" . $this->_sTable . "` AS `te`
             INNER JOIN `" . $sTableTrack . "` AS `tt` ON `te`.`object_id`=`tt`.`object_id` AND `te`.`object_owner_id`<>`tt`.`author_id` AND `te`.`type`=:module 
-            WHERE (`te`.`system` <> 0 OR `te`.`owner_id` = 0) AND `tt`.`date` > (UNIX_TIMESTAMP() - 3600 * :interval) 
+            WHERE 1 " . $sQueryWhere . " 
             GROUP BY " . $sQueryGroup;
 
         return $this->getPairs($sQuery, 'event_id', 'value', $aBindings);

+ 1 - 0
modules/boonex/timeline/install/langs/en.xml

@@ -44,6 +44,7 @@
     <string name="_bx_timeline_option_hot_sources_content"><![CDATA[Add content]]></string>
     <string name="_bx_timeline_option_hot_sources_comment"><![CDATA[Add comment]]></string>
     <string name="_bx_timeline_option_hot_sources_vote"><![CDATA[Add vote]]></string>
+    <string name="_bx_timeline_option_hot_threshold_age"><![CDATA[Maximum age of post that gets included in Hot feed (in days, 0 - no limit)]]></string>
     <string name="_bx_timeline_option_hot_threshold_comment"><![CDATA[Minimum number of comments for content to appear in Hot feed]]></string>
     <string name="_bx_timeline_option_hot_threshold_vote"><![CDATA[Minimum number of votes for content to appear in Hot feed]]></string>
     <string name="_bx_timeline_option_hot_interval"><![CDATA[Interval of time (in hours) to get Hot events]]></string>

+ 4 - 3
modules/boonex/timeline/install/sql/enable.sql

@@ -311,9 +311,10 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 
 ('bx_timeline_enable_hot', 'on', @iCategId, '_bx_timeline_option_enable_hot', 'checkbox', '', '', '', '', 30),
 ('bx_timeline_hot_sources', 'content,comment,vote', @iCategId, '_bx_timeline_option_hot_sources', 'list', '', '', '', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:25:"get_hot_sources_checklist";}', 31),
-('bx_timeline_hot_threshold_comment', '1', @iCategId, '_bx_timeline_option_hot_threshold_comment', 'digit', '', '', '', '', 32),
-('bx_timeline_hot_threshold_vote', '2', @iCategId, '_bx_timeline_option_hot_threshold_vote', 'digit', '', '', '', '', 33),
-('bx_timeline_hot_interval', '48', @iCategId, '_bx_timeline_option_hot_interval', 'digit', '', '', '', '', 34);
+('bx_timeline_hot_threshold_age', '0', @iCategId, '_bx_timeline_option_hot_threshold_age', 'digit', '', '', '', '', 32),
+('bx_timeline_hot_threshold_comment', '1', @iCategId, '_bx_timeline_option_hot_threshold_comment', 'digit', '', '', '', '', 33),
+('bx_timeline_hot_threshold_vote', '2', @iCategId, '_bx_timeline_option_hot_threshold_vote', 'digit', '', '', '', '', 34),
+('bx_timeline_hot_interval', '48', @iCategId, '_bx_timeline_option_hot_interval', 'digit', '', '', '', '', 35);
 
 -- Category: Card
 INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order`)