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

Ticket #4691 - Timeline: Improve events grouping.

AntonLV 2 лет назад
Родитель
Сommit
4efda4304d

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

@@ -28,7 +28,7 @@
     <string name="_bx_timeline_option_events_per_preload"><![CDATA[Бесконечная прокрутка: Количество элементов, получаемых при авто-подгрузке]]></string>
     <string name="_bx_timeline_option_auto_preloads"><![CDATA[Бесконечная прокрутка: Количество авто-подгрузок]]></string>
     <string name="_bx_timeline_option_rss_length"><![CDATA[Количество элементов в RSS-ленте]]></string>
-    <string name="_bx_timeline_option_live_updates_length"><![CDATA[Количество элементов в выборке авто обновления]]></string>
+    <string name="_bx_timeline_option_live_updates_length"><![CDATA[Длина выборки "Aвто обновления" (оставьте 0 для автоматического значения)]]></string>
     <string name="_bx_timeline_option_events_hide"><![CDATA[Показывать события]]></string>
     <string name="_bx_timeline_option_searchable_fields"><![CDATA[Поля для поиска по ключевому слову]]></string>
     <string name="_bx_timeline_option_enable_brief_cards"><![CDATA[Включить лаконичные карточки]]></string>

+ 2 - 3
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -772,12 +772,11 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         if($bCount)
             return array_sum($aSqlParts);
 
-        /*
-         * TODO: Should be updated when GROUP BY `source` will be used in sub selects.
-         */
         $sSqlMaskUnion = '(' . implode(') UNION (', $aSqlParts) . ')';
         if($bValidate)
             $sSqlMaskUnion = 'SELECT MAX(`tu`.`id`) AS `id` FROM (' . $sSqlMaskUnion . ') AS `tu` GROUP BY `tu`.`source`';
+        else
+            $sSqlMaskUnion = 'SELECT *, GROUP_CONCAT(`owner_id`) AS `owner_id_grouped` FROM (' . $sSqlMaskUnion . ') AS `tu` GROUP BY `tu`.`source`';
         $sSqlMaskUnion .= ' {order} {limit}';
 
         $sSql = bx_replace_markers($sSqlMaskUnion, [

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

@@ -3447,10 +3447,10 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             return false;
 
         $aParams = $this->_prepareParams($aBrowseParams);
-        $aParams = array_merge($aParams, [
-            'per_page' => $this->_oConfig->getLiveUpdateLength(),
-            'filter' => BX_TIMELINE_FILTER_OTHER_VIEWER
-        ]);
+        $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
+        if(($iLiveUpdateLength = $this->_oConfig->getLiveUpdateLength()) != 0)
+            $aParams['per_page'] = $iLiveUpdateLength;
+
         $aEvents = $this->_oDb->getEvents($aParams);
         if(empty($aEvents) || !is_array($aEvents))
             return false;
@@ -3471,10 +3471,9 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         if($iValueNew == $iValue)
             return false;
 
-        if(bx_is_api()){
+        if($this->_bIsApi)
             return $iValueNew;
-        }
-        
+
         if((int)$iInit != 0)
             return array('count' => $iValueNew);
 

+ 13 - 46
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -838,53 +838,11 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         $sContent .= $this->getSizer($aParams);
 
         $iFirst = 0;
+        $iEventIndex = 0;
         $iEvents = count($aEvents);
-        if($iEvents > 0)
-            $iFirst = $this->_getFirst($aEvents, $aParams);
-
-        //--- Check for Visual Grouping
-        $aGroups = array();
-        foreach($aEvents as $iIndex => $aEvent) {
-            $aContent = unserialize($aEvent['content']);
-            if(!isset($aContent['timeline_group']))
-                continue;
-
-            $aGroup = $aContent['timeline_group'];
-            $sGroup = $aGroup['by'];
-            if(!isset($aGroups[$sGroup]))
-               $aGroups[$sGroup] = array('field' => $aGroup['field'], 'indexes' => array(), 'processed' => false);
-
-            $aGroups[$sGroup]['indexes'][] = $iIndex;
-        }
-
-        //--- Perform Visual Grouping
-        foreach($aGroups as $sGroup => $aGroup) {
-            if(empty($aGroup['field']) || empty($aGroup['indexes']))
-                continue;
-
-            switch($aGroup['field']) {
-                case 'owner_id':
-                    $aOwnerIds = array();
-                    foreach($aGroup['indexes'] as $iIndex)
-                        if(!in_array($aEvents[$iIndex]['owner_id'], $aOwnerIds))
-                            $aOwnerIds[] = $aEvents[$iIndex]['owner_id'];
-
-                    $iGroupIndex = (int)array_shift($aGroup['indexes']);
-                    if(is_null($iGroupIndex))
-                        break;
-
-                    foreach($aGroup['indexes'] as $iIndex)
-                        unset($aEvents[$iIndex]);
-
-                    $aEvents[$iGroupIndex]['owner_id_grouped'] = $aOwnerIds;
-                    break;
-            }
-        }
-
         $iExtenalsEvery = $this->_oConfig->getExtenalsEvery($aParams['type']);
 
-        $iEventIndex = 0;
-        $mixedEvents = $bReturnArray ? array() : '';
+        $mixedEvents = $bReturnArray ? [] : '';
         foreach($aEvents as $aEvent) {
             $iEvent = (int)$aEvent['id'];
             $aEvent['index'] = $iEventIndex + 1;
@@ -893,6 +851,9 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
             if(empty($sEvent))
                 continue;
 
+            if(!$iFirst)
+                $iFirst = $aEvent['id'];
+
             if($bReturnArray)
                 $mixedEvents[] = $aEvent;
             else
@@ -2347,10 +2308,16 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         $oConnection = BxDolConnection::getObjectInstance($sConnection);
         $sConnectionTitle = _t('_sys_menu_item_title_sm_subscribe');
 
+        $aOwnerIds = [];
         $sKeyOwnerId = isset($aEvent['owner_id_grouped']) ? 'owner_id_grouped' : 'owner_id';
-        $aOwnerIds = is_array($aEvent[$sKeyOwnerId]) ? $aEvent[$sKeyOwnerId] : array($aEvent[$sKeyOwnerId]);
+        if(is_string($aEvent[$sKeyOwnerId]) && strpos($aEvent[$sKeyOwnerId], ',') !== false)
+            $aOwnerIds = explode(',', $aEvent[$sKeyOwnerId]);
+        else if(is_array($aEvent[$sKeyOwnerId]))
+            $aOwnerIds = $aEvent[$sKeyOwnerId];
+        else
+            $aOwnerIds = [$aEvent[$sKeyOwnerId]];
 
-        $aTmplVarsOwners = array();
+        $aTmplVarsOwners = [];
         foreach($aOwnerIds as $iOwnerId) {
             $iOwnerId = (int)$iOwnerId;
             $iObjectOwner = (int)$aEvent['object_owner_id'];

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

@@ -28,7 +28,7 @@
     <string name="_bx_timeline_option_events_per_preload"><![CDATA[Infinite Scroll: Number of items per preload]]></string>
     <string name="_bx_timeline_option_auto_preloads"><![CDATA[Infinite Scroll: Number of auto preloads]]></string>
     <string name="_bx_timeline_option_rss_length"><![CDATA[The length of RSS feed]]></string>
-    <string name="_bx_timeline_option_live_updates_length"><![CDATA[The length of Live Updates selection]]></string>
+    <string name="_bx_timeline_option_live_updates_length"><![CDATA[The length of Live Updates sample (leave 0 for automatic value)]]></string>
     <string name="_bx_timeline_option_events_hide"><![CDATA[Show events]]></string>
     <string name="_bx_timeline_option_searchable_fields"><![CDATA[Searchable fields for keyword search]]></string>
     <string name="_bx_timeline_option_enable_brief_cards"><![CDATA[Enable brief cards]]></string>

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

@@ -324,7 +324,7 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_timeline_events_per_page_home', '24', @iCategId, '_bx_timeline_option_events_per_page_home', 'digit', '', '', '', '', 12),
 ('bx_timeline_events_per_page', '24', @iCategId, '_bx_timeline_option_events_per_page', 'digit', '', '', '', '', 13),
 ('bx_timeline_rss_length', '5', @iCategId, '_bx_timeline_option_rss_length', 'digit', '', '', '', '', 14),
-('bx_timeline_live_updates_length', '5', @iCategId, '_bx_timeline_option_live_updates_length', 'digit', '', '', '', '', 15),
+('bx_timeline_live_updates_length', '0', @iCategId, '_bx_timeline_option_live_updates_length', 'digit', '', '', '', '', 15),
 
 ('bx_timeline_enable_infinite_scroll', '', @iCategId, '_bx_timeline_option_enable_infinite_scroll', 'checkbox', '', '', '', '', 20),
 ('bx_timeline_events_per_preload', '5', @iCategId, '_bx_timeline_option_events_per_preload', 'digit', '', '', '', '', 21),