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

Ticket #4942 - Timeline: Filters panel. Switch between any context.

AntonLV 1 год назад
Родитель
Сommit
1960c3b0dd

+ 24 - 0
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -503,6 +503,30 @@ class BxBaseModGeneralModule extends BxDolModule
     }
 
     // ====== SERVICE METHODS
+
+    /**
+     * Checkes whether a content is active by status (status_admin).
+     * 
+     * @param type $iContentId
+     * @return boolean
+     */
+    public function serviceIsActive($iContentId)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+        if(empty($aContentInfo))
+            return false;
+
+        if(($sKey = 'FIELD_STATUS') && isset($CNF[$sKey]) && $aContentInfo[$CNF[$sKey]] != 'active')
+            return false;
+
+        if(($sKey = 'FIELD_STATUS_ADMIN') && isset($CNF[$sKey]) && isset($aContentInfo[$CNF[$sKey]]) && $aContentInfo[$CNF[$sKey]] != 'active')
+            return false;
+
+        return true;
+    }
+
     public function serviceIsAllowedAddContentToContext($iContextPid)
     {
         $oContext = false;

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

@@ -78,6 +78,7 @@
     <string name="_bx_timeline_option_extenals_every_feed_preload"><![CDATA[Показывать внешнее событие как каждое N-е в ленте контекст (профиль) + подписки при включенной 'Бесконечной прокрутке']]></string>
     <string name="_bx_timeline_option_extenals_every_hot_preload"><![CDATA[Показывать внешнее событие как каждое N-е в hot timeline при включенной 'Бесконечной прокрутке']]></string>
     <string name="_bx_timeline_option_extenals_every_feed_and_hot_preload"><![CDATA[Показывать внешнее событие как каждое N-е в ленте 'Для тебя' при включенной 'Бесконечной прокрутке']]></string>
+    <string name="_bx_timeline_option_filters_contexts_hide"><![CDATA[Фильтры: По контекстам]]></string>
     <string name="_bx_timeline_option_for_you_sources"><![CDATA[Лента 'Для Вас' состоит из]]></string>
     <string name="_bx_timeline_option_for_you_sources_err"><![CDATA[Для фида должен быть включен хотя бы один источник.]]></string>
     <string name="_bx_timeline_option_for_you_sources_public"><![CDATA[Публичная лента]]></string>
@@ -157,8 +158,8 @@
     <string name="_bx_timeline_form_repost_input_sys_do_cancel"><![CDATA[Отмена]]></string>
     <string name="_bx_timeline_form_repost_input_do_cancel"><![CDATA[Отмена]]></string>
 
-    <string name="_bx_timeline_form_filters_input_by_hashtags"><![CDATA[Хэштеги:]]></string>
-    <string name="_bx_timeline_form_filters_input_by_hashtags_any"><![CDATA[Любой]]></string>
+    <string name="_bx_timeline_form_filters_input_by_contexts"><![CDATA[Контексты:]]></string>
+    <string name="_bx_timeline_form_filters_input_by_contexts_any"><![CDATA[Любой]]></string>
     <string name="_bx_timeline_form_filters_input_by_modules"><![CDATA[Содержимое:]]></string>
     <string name="_bx_timeline_form_filters_input_by_modules_all"><![CDATA[Всё]]></string>
     <string name="_bx_timeline_form_filters_input_by_modules_selected"><![CDATA[Выборочно]]></string>

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

@@ -34,6 +34,8 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
     protected $_iInfScrollPerPreload;
     protected $_iInfScrollAutoPreloads;
 
+    protected $_aFiltersContextsHide;
+
     protected $_iRssLength;
     protected $_iLiveUpdateLength;
     protected $_iCharsDisplayMinTitle;
@@ -488,7 +490,8 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         $this->_bInfScroll = getParam($sOptionPrefix . 'enable_infinite_scroll') == 'on';
         $this->_iInfScrollPerPreload = (int)getParam($sOptionPrefix . 'events_per_preload');
         $this->_iInfScrollAutoPreloads = (int)getParam($sOptionPrefix . 'auto_preloads');
-        
+
+        $this->_aFiltersContextsHide = ($sValue = getParam($sOptionPrefix . 'filters_contexts_hide')) ? explode(',', $sValue) : [];        
 
         $this->_iRssLength = (int)getParam($sOptionPrefix . 'rss_length');
         $this->_iLiveUpdateLength = (int)getParam($sOptionPrefix . 'live_updates_length');
@@ -852,6 +855,11 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         return $this->_iInfScrollAutoPreloads;
     }
 
+    public function getFiltersContextsHide()
+    {
+        return $this->_aFiltersContextsHide;
+    }
+
     public function getRssLength()
     {
         return $this->_iRssLength;

+ 31 - 0
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -3405,6 +3405,37 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         return 'BxTimelineFormCheckerHelper';
     }
 
+    /**
+     * @page service Service Calls
+     * @section bx_timeline Timeline
+     * @subsection bx_timeline-other Other
+     * @subsubsection bx_timeline-get_options_filters_contexts get_options_filters_contexts
+     * 
+     * @code bx_srv('bx_timeline', 'get_options_filters_contexts', [...]); @endcode
+     * 
+     * Get an array with available options for '' setting.
+     *
+     * @return an array with available options represented as key => value pairs.
+     * 
+     * @see BxTimelineModule::serviceGetOptionsFiltersContexts
+     */
+    /** 
+     * @ref bx_timeline-get_options_filters_contexts "get_options_filters_contexts"
+     */
+    public function serviceGetOptionsFiltersContexts()
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $aContexts = bx_srv('system', 'get_modules_by_type', ['context']);
+        
+        $aResult = array();
+        foreach($aContexts as $aContext)
+            if(($sContext = $aContext['name']) && BxDolModuleQuery::getInstance()->isEnabledByName($sContext))
+                $aResult[$aContext['name']] = ($sLk = '_' . $sContext) && ($_sLk = _t($sLk)) && strcmp($sLk, $_sLk) != 0 ? $_sLk : $aContext['title'];
+
+        return $aResult;
+    }
+
     /**
      * @page service Service Calls
      * @section bx_timeline Timeline

+ 34 - 18
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -312,32 +312,48 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         $sJsObject = $this->_oConfig->getJsObject('view_filters');
 
         $iProfile = bx_get_logged_profile_id();
+        $oModuleQuery = BxDolModuleQuery::getInstance();
 
         $aInputs = [];
 
-        //--- by Hashtag
+        //--- by Context
         if($aParams['name'] != BX_TIMELINE_NAME_VIEWS_DB) {
-            $oModuleQuery = BxDolModuleQuery::getInstance();
-
-            if(($sChannels = 'bx_channels') && $oModuleQuery->isEnabledByName($sChannels)) {
-                $aChannelsIds = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')->getConnectedContentByType($iProfile, [$sChannels]);
-                if(!empty($aChannelsIds) && is_array($aChannelsIds)) {
-                    $aInputs['by_hashtag'] = [
-                        'name' => 'by_hashtag',
-                        'type' => 'select',
-                        'caption' => _t('_bx_timeline_form_filters_input_by_hashtags'),
-                        'values' => [
-                            ['key' => 0, 'value' => _t('_bx_timeline_form_filters_input_by_hashtags_any')],
-                        ]
-                    ];
+            //--- by contexts including Hashtags (Channels)
+            $aContexts = bx_srv('system', 'get_modules_by_type', ['context', ['name_as_key' => true]]);
+            if(!empty($aContexts) || is_array($aContexts)) {
+                $aContextsHide = $this->_oConfig->getFiltersContextsHide();
+                $bShowGrouped = count(array_diff(array_keys($aContexts), $aContextsHide)) > 1;
+
+                $aInputs['by_context'] = [
+                    'name' => 'by_context',
+                    'type' => 'select',
+                    'caption' => _t('_bx_timeline_form_filters_input_by_contexts'),
+                    'values' => [
+                        ['key' => 0, 'value' => _t('_bx_timeline_form_filters_input_by_contexts_any')],
+                    ]
+                ];
+
+                foreach($aContexts as $sContext => $aContext) {
+                    if(in_array($sContext, $aContextsHide))
+                        continue;
 
-                    foreach($aChannelsIds as $iChannelId) {
-                        $oContext = BxDolProfile::getInstance($iChannelId);
-                        if(!$oContext)
+                    $aContextsIds = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')->getConnectedContentByType($iProfile, [$sContext]);
+                    if(empty($aContextsIds) || !is_array($aContextsIds))
+                        continue;
+
+                    if($bShowGrouped)
+                        $aInputs['by_context']['values'][] = ['type' => 'group_header', 'value' => ($sLk = '_' . $sContext) && ($_sLk = _t($sLk)) && strcmp($sLk, $_sLk) != 0 ? $_sLk : $aContext['title']];
+
+                    foreach($aContextsIds as $iContextId) {
+                        $oContext = BxDolProfile::getInstance($iContextId);
+                        if(!$oContext || !$oContext->isActive() || !bx_srv($sContext, 'is_active', [$oContext->getContentId()]))
                             continue;
 
-                        $aInputs['by_hashtag']['values'][] = ['key' => $iChannelId, 'value' => $oContext->getDisplayName()];
+                        $aInputs['by_context']['values'][] = ['key' => $sContext . '|' . $iContextId, 'value' => $oContext->getDisplayName()];
                     }
+
+                    if($bShowGrouped)
+                        $aInputs['by_context']['values'][] = ['type' => 'group_end'];
                 }
             }
         }

+ 3 - 2
modules/boonex/timeline/install/langs/en.xml

@@ -78,6 +78,7 @@
     <string name="_bx_timeline_option_extenals_every_feed_preload"><![CDATA[Show external event as every N-th in context (profile) + subscriptions timeline with Infinite Scroll enabled]]></string>
     <string name="_bx_timeline_option_extenals_every_hot_preload"><![CDATA[Show external event as every N-th in hot timeline with Infinite Scroll enabled]]></string>
     <string name="_bx_timeline_option_extenals_every_feed_and_hot_preload"><![CDATA[Show external event as every N-th in 'For You' timeline with Infinite Scroll enabled]]></string>
+    <string name="_bx_timeline_option_filters_contexts_hide"><![CDATA[Filters: By contexts]]></string>
     <string name="_bx_timeline_option_for_you_sources"><![CDATA['For You' feed consists of]]></string>
     <string name="_bx_timeline_option_for_you_sources_err"><![CDATA[At least one source should be enabled for the feed.]]></string>
     <string name="_bx_timeline_option_for_you_sources_public"><![CDATA[Public]]></string>
@@ -157,8 +158,8 @@
     <string name="_bx_timeline_form_repost_input_sys_do_cancel"><![CDATA[Cancel]]></string>
     <string name="_bx_timeline_form_repost_input_do_cancel"><![CDATA[Cancel]]></string>
 
-    <string name="_bx_timeline_form_filters_input_by_hashtags"><![CDATA[Hashtags:]]></string>
-    <string name="_bx_timeline_form_filters_input_by_hashtags_any"><![CDATA[Any]]></string>
+    <string name="_bx_timeline_form_filters_input_by_contexts"><![CDATA[Contexts:]]></string>
+    <string name="_bx_timeline_form_filters_input_by_contexts_any"><![CDATA[Any]]></string>
     <string name="_bx_timeline_form_filters_input_by_modules"><![CDATA[Content:]]></string>
     <string name="_bx_timeline_form_filters_input_by_modules_all"><![CDATA[All]]></string>
     <string name="_bx_timeline_form_filters_input_by_modules_selected"><![CDATA[Selected]]></string>

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

@@ -339,7 +339,9 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_timeline_extenals_every_owner_preload', '0', @iCategId, '_bx_timeline_option_extenals_every_owner_preload', 'digit', '', '', '', '', 46),
 ('bx_timeline_extenals_every_feed_preload', '0', @iCategId, '_bx_timeline_option_extenals_every_feed_preload', 'digit', '', '', '', '', 47),
 ('bx_timeline_extenals_every_hot_preload', '0', @iCategId, '_bx_timeline_option_extenals_every_hot_preload', 'digit', '', '', '', '', 48),
-('bx_timeline_extenals_every_feed_and_hot_preload', '0', @iCategId, '_bx_timeline_option_extenals_every_feed_and_hot_preload', 'digit', '', '', '', '', 49);
+('bx_timeline_extenals_every_feed_and_hot_preload', '0', @iCategId, '_bx_timeline_option_extenals_every_feed_and_hot_preload', 'digit', '', '', '', '', 49),
+
+('bx_timeline_filters_contexts_hide', '', @iCategId, '_bx_timeline_option_filters_contexts_hide', 'rlist', '', '', '', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:28:"get_options_filters_contexts";}', 70);
 
 
 -- Category: Card

+ 10 - 3
modules/boonex/timeline/js/view_filters.js

@@ -153,10 +153,17 @@ BxTimelineViewFilters.prototype.onFilterApply = function(oSource)
     var oFilters = $(oSource).parents('.bx-tl-view-filters:first');
 
     //--- Apply feed Types
-    var oContext = oFilters.find("select[name='by_hashtag']");
+    var oContext = oFilters.find("select[name='by_context']");
     if(oContext.length) {
-        var iContext = parseInt(oContext.val());
-        var sType = iContext ? 'bx_channels' : this._sType;
+        var sType = this._sType;
+        var iContext = 0;
+
+        var sContext = oContext.val();
+        if(sContext && sContext.indexOf('|') != -1) {
+            var aContext = sContext.split('|');
+            sType = aContext[0];
+            iContext = parseInt(aContext[1]);
+        }
 
         this._oRequestParams.type = sType;