RomanL 8 lat temu
rodzic
commit
ec3b3f0dc2

+ 38 - 21
modules/boonex/charts/classes/BxChartsCron.php

@@ -37,36 +37,53 @@ class BxChartsCron extends BxDolCron
         $this->_oModule->_oDb->clearTopByLikes();
         foreach($aModules as $sModule){
             $oModule = BxDolModule::getInstance($sModule);
-            $sSystem = $oModule->_oConfig->CNF['OBJECT_VOTES'];
-            if(empty($sSystem))
-                continue;
-            $this->_oModule->_oDb->saveTopByLikes($sModule, $aSystems[$sSystem]['table_main']);
+            if(isset($oModule->_oConfig->CNF['OBJECT_VOTES'])){
+                $sSystem = $oModule->_oConfig->CNF['OBJECT_VOTES'];
+                if(empty($sSystem))
+                    continue;
+                $this->_oModule->_oDb->saveTopByLikes($sModule, $aSystems[$sSystem]['table_main']);
+            }
         }
     }
     
     function processingMostActiveProfiles()
     {
         $this->_oModule->_oDb->clearMostActiveProfiles();
-        $sContentModule = getParam('bx_charts_chart_most_active_profiles_posts_for_module');
-        $oContentModule = BxDolModule::getInstance($sContentModule);
-        if ($oContentModule){
-            $sContentTable = $oContentModule->_oConfig->CNF['TABLE_ENTRIES'];
-            $sColumnAuthor = $oContentModule->_oConfig->CNF['FIELD_AUTHOR'];
-            if (!empty($sContentTable) && !empty($sColumnAuthor)){
-                $aSystems = BxDolView::getSystems();
-                $aModules = array_keys($this->_oModule->serviceGetProfileModules());
-                $sModulesDisabled = explode(',', getParam('bx_charts_chart_most_active_profiles_modules_disabled'));
-                $aModules = array_diff($aModules, $sModulesDisabled);
-                foreach($aModules as $sModule){
-                    $oModule = BxDolModule::getInstance($sModule);
-                    $sSystem = $oModule->_oConfig->CNF['OBJECT_VIEWS'];
-                    if(empty($sSystem))
-                        continue;
-                    $this->_oModule->_oDb->saveMostActiveProfiles_View($sModule, $aSystems[$sSystem]['table_track']);
-                    $this->_oModule->_oDb->saveMostActiveProfiles_Create($sModule, $sContentTable, $sColumnAuthor);
+        $aContentModules = array_keys($this->_oModule->serviceGetTextModules());
+        $sContentModulesDisabled = explode(',', getParam('bx_charts_chart_most_active_profiles_posts_for_module_disabled'));
+        $aContentModules = array_diff($aContentModules, $sContentModulesDisabled);
+        foreach($aContentModules as $sContentModule){
+            $oContentModule = BxDolModule::getInstance($sContentModule);
+            if ($oContentModule && isset($oContentModule->_oConfig->CNF['TABLE_ENTRIES']) && isset($oContentModule->_oConfig->CNF['FIELD_AUTHOR'])){
+                $sContentTable = $oContentModule->_oConfig->CNF['TABLE_ENTRIES'];
+                $sColumnAuthor = $oContentModule->_oConfig->CNF['FIELD_AUTHOR'];
+                if (!empty($sContentTable) && !empty($sColumnAuthor)){
+                    $aSystems = BxDolView::getSystems();
+                    $aModules = array_keys($this->_oModule->serviceGetProfileModules());
+                    $sModulesDisabled = explode(',', getParam('bx_charts_chart_most_active_profiles_modules_disabled'));
+                    $aModules = array_diff($aModules, $sModulesDisabled);
+                    foreach($aModules as $sProfileModule){
+                        $oModule = BxDolModule::getInstance($sProfileModule);
+                        if(isset($oModule->_oConfig->CNF['OBJECT_VIEWS'])){
+                            $sSystem = $oModule->_oConfig->CNF['OBJECT_VIEWS'];
+                            if(empty($sSystem))
+                                continue;
+                            $this->_oModule->_oDb->saveMostActiveProfiles_Create($sProfileModule, $sContentModule, $sContentTable, $sColumnAuthor);
+                        }
+                    }
                 }
             }
         }
+        
+        foreach($aModules as $sProfileModule){
+            $oModule = BxDolModule::getInstance($sProfileModule);
+            if(isset($oModule->_oConfig->CNF['OBJECT_VIEWS'])){
+                $sSystem = $oModule->_oConfig->CNF['OBJECT_VIEWS'];
+                if(empty($sSystem))
+                    continue;
+                $this->_oModule->_oDb->saveMostActiveProfiles_View($sProfileModule, $aSystems[$sSystem]['table_track']);
+            }
+        }
     }
 }
 

+ 8 - 8
modules/boonex/charts/classes/BxChartsDb.php

@@ -25,7 +25,7 @@ class BxChartsDb extends BxBaseModGeneralDb
     
     public function saveTopByLikes($sModuleName, $sTableName)
     {
-        $sQuery = "INSERT INTO `" . $this->_sTableTopByLikes . "` (`object_id`, `module`, `value`) SELECT `object_id`,'" . $sModuleName . "',`sum` FROM `" . $sTableName . "`";
+        $sQuery = "INSERT INTO `" . $this->_sTableTopByLikes . "` (`object_id`, `module`, `value`) SELECT `object_id`,'" . $sModuleName . "',`count` FROM `" . $sTableName . "` ORDER BY `count` DESC LIMIT 0, " . intval(getParam('bx_charts_chart_top_contents_by_likes_count')) . "";
         $this->query($sQuery);
     }
     
@@ -40,17 +40,17 @@ class BxChartsDb extends BxBaseModGeneralDb
         return $this->getAll("SELECT * FROM  `" . $this->_sTableTopByLikes . "` ORDER BY `value` DESC LIMIT 0," . intval(getParam('bx_charts_chart_top_contents_by_likes_count')));
     }
     
-    public function saveMostActiveProfiles_View($sModuleName, $sTableName)
+    public function saveMostActiveProfiles_View($sProfileModuleName, $sTableName)
     {
-        $sQuery = "INSERT INTO `" . $this->_sTableMostActiveProfiles . "` (`object_id`, `module`, `views_count`) SELECT `object_id`,'" . $sModuleName . "', COUNT(`date`) AS views FROM `" . $sTableName . "` 
-GROUP BY `object_id`";
+        $sQuery = "INSERT INTO `" . $this->_sTableMostActiveProfiles . "` (`object_id`, `profile_module`, `views_count`) SELECT `object_id`,'" . $sProfileModuleName . "', COUNT(`date`) AS views FROM `" . $sTableName . "` 
+ WHERE `object_id` IN (SELECT `object_id` FROM `" . $this->_sTableMostActiveProfiles . "` WHERE `profile_module` = '" . $sProfileModuleName . "' ) GROUP BY `object_id`";
         $this->query($sQuery);
     }
     
-    public function saveMostActiveProfiles_Create($sModuleName, $sTableName, $sColumnAuthor)
+    public function saveMostActiveProfiles_Create($sProfileModuleName, $sContentModuleName, $sTableName, $sColumnAuthor)
     {
-        $sQuery = "INSERT INTO `" . $this->_sTableMostActiveProfiles . "` (`object_id`, `module`, `create_count`)  SELECT `sys_profiles`.`content_id`, `sys_profiles`.`type`, COUNT(`" . $sTableName . "`.`id`) FROM `" . $sTableName . "`
-  INNER JOIN `sys_profiles`  ON `sys_profiles`.`id` = `" . $sTableName . "`.`" . $sColumnAuthor . "` WHERE sys_profiles.type='" . $sModuleName . "' GROUP BY `sys_profiles`.`content_id`, `sys_profiles`.`type`";
+        $sQuery = "INSERT INTO `" . $this->_sTableMostActiveProfiles . "` (`object_id`, `profile_module`, `content_module`, `create_count`)  SELECT `sys_profiles`.`content_id`, `sys_profiles`.`type`, '" . $sContentModuleName . "' , COUNT(`" . $sTableName . "`.`id`) FROM `" . $sTableName . "`
+  INNER JOIN `sys_profiles`  ON `sys_profiles`.`id` = `" . $sTableName . "`.`" . $sColumnAuthor . "` WHERE sys_profiles.type='" . $sProfileModuleName . "' GROUP BY `sys_profiles`.`content_id`, `sys_profiles`.`type` ORDER BY COUNT(`" . $sTableName . "`.`id`) DESC LIMIT 0," . intval(getParam('bx_charts_chart_most_active_profiles_count'));
         $this->query($sQuery);
     }
     
@@ -62,7 +62,7 @@ GROUP BY `object_id`";
     
     public function getMostActiveProfiles()
     {
-        return $this->getAll("SELECT SUM(`views_count`) AS views_count, SUM(`create_count`) AS create_count, `object_id`, `module` FROM `bx_charts_most_active_profiles` GROUP BY `object_id`, `module` ORDER BY SUM(`create_count`) DESC, SUM(`views_count`) DESC LIMIT 0," . intval(getParam('bx_charts_chart_most_active_profiles_count')));
+        return $this->getAll("SELECT SUM(`views_count`) AS views_count, SUM(`create_count`) AS create_count, `object_id`, `profile_module` as `module` FROM `bx_charts_most_active_profiles` GROUP BY `object_id`, `module` ORDER BY SUM(`create_count`) DESC, SUM(`views_count`) DESC LIMIT 0," . intval(getParam('bx_charts_chart_most_active_profiles_count')));
     }
 }
 

+ 14 - 2
modules/boonex/charts/classes/BxChartsModule.php

@@ -136,7 +136,7 @@ class BxChartsModule extends BxDolModule
             $aData = $this->_oDb->getTopByLikes();
             foreach ($aData as $aValue) {
                 $oModule = BxDolModule::getInstance($aValue['module']);
-                array_push($aValues['labels'], $oModule->serviceGetTitle($aValue['object_id']) . ' ' . $oModule->_aModule['title']);
+                array_push($aValues['labels'], $this->getItemName($oModule->serviceGetTitle($aValue['object_id'])) . ' (' . $oModule->_aModule['title'].')');
                 array_push($aValues['values'], $aValue['value']);
                 array_push($aValues['links'], $oModule->serviceGetLink($aValue['object_id']));
               
@@ -150,7 +150,7 @@ class BxChartsModule extends BxDolModule
             $aData = $this->_oDb->getMostActiveProfiles();
             foreach ($aData as $aValue) {
                 $oModule = BxDolModule::getInstance($aValue['module']);
-                array_push($aValues['labels'], $oModule->serviceGetTitle($aValue['object_id']) . ' ' . $oModule->_aModule['title']);
+                array_push($aValues['labels'], $this->getItemName($oModule->serviceGetTitle($aValue['object_id'])) . ' (' . $oModule->_aModule['title'].')');
                 array_push($aValues['values1'], $aValue['create_count']);
                 array_push($aValues['values2'], $aValue['views_count']);
                 array_push($aValues['links'], $oModule->serviceGetLink($aValue['object_id']));
@@ -159,6 +159,18 @@ class BxChartsModule extends BxDolModule
             echo  '{"type":"bar",  "data": {"labels":' . json_encode($aValues['labels']) . ',"datasets": [{"label": "' . _t('_bx_charts_most_active_profiles_legend_posts') . '","backgroundColor": "' . $this->aColors[0] . '","borderColor": "' . $this->aColors[0] . '","borderWidth": 1,"data": ' . json_encode($aValues['values1']) . '}, {"label": "' . _t('_bx_charts_most_active_profiles_legend_views') . '","backgroundColor": "' . $this->aColors[1] . '","borderColor":"' . $this->aColors[1] . '","borderWidth": 1,"data": ' . json_encode($aValues['values2']) . '}]},"links": ' . json_encode($aValues['links']) . '}';
         }
     }
+    
+    private function getItemName($sString)
+    {
+        $sString = strip_tags($sString);
+        if ($sString == ''){
+            $sString = _t('_bx_charts_txt_empty_title_item');
+        }
+        else{
+            $sString = strmaxtextlen($sString, 10, '...');
+        }
+        return $sString;
+    }
 }
 
 /** @} */

+ 0 - 1
modules/boonex/charts/classes/BxChartsTemplate.php

@@ -30,7 +30,6 @@ class BxChartsTemplate extends BxBaseModGeneralTemplate
         $aParams = array_merge(array(
             'sChartName' => $aParams['chartName'],
         ), $aParams);
-        
         return parent::getJsCode($sType, $aParams, $bWrap);
     }
 }

+ 3 - 3
modules/boonex/charts/install/langs/en.xml

@@ -7,14 +7,14 @@
 	<string name="_bx_charts_adm_stg_cpt_category_chart_most_active_profiles"><![CDATA[Most active profiles]]></string>
   <string name="_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_modules_enabled"><![CDATA[Enabled for modules]]></string>
   <string name="_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_count"><![CDATA[Count]]></string>
-  <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_modules_enabled"><![CDATA[Enabled for modules]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_modules_enabled"><![CDATA[Enabled for profiles from]]></string>
   <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_count"><![CDATA[Count]]></string>
-  <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_posts_for_module"><![CDATA[For module]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_posts_for_module"><![CDATA[For modules]]></string>
   <string name="_bx_charts_page_block_title_system_chart_top_contents_by_likes"><![CDATA[Top contents by likes]]></string>
   <string name="_bx_charts_page_block_title_chart_top_contents_by_likes"><![CDATA[Top contents by likes]]></string>
   <string name="_bx_charts_page_block_title_system_chart_most_active_profiles"><![CDATA[Most active profiles]]></string>
   <string name="_bx_charts_page_block_title_chart_most_active_profiles"><![CDATA[Most active profiles]]></string>
   <string name="_bx_charts_most_active_profiles_legend_posts"><![CDATA[Posted items]]></string>
   <string name="_bx_charts_most_active_profiles_legend_views"><![CDATA[Profile views]]></string>
-  
+  <string name="_bx_charts_txt_empty_title_item"><![CDATA[Item]]></string>
 </resources>

+ 2 - 2
modules/boonex/charts/install/sql/enable.sql

@@ -20,7 +20,7 @@ SET @iCategoryId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options` (`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_params`, `check_error`, `order`) VALUES
 (@iCategoryId, 'bx_charts_chart_most_active_profiles_modules_disabled', '_bx_charts_adm_stg_cpt_chart_most_active_profiles_modules_enabled', '', 'rlist', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:19:"get_profile_modules";}', '', '', '', 1),
-(@iCategoryId, 'bx_charts_chart_most_active_profiles_posts_for_module', '_bx_charts_adm_stg_cpt_chart_most_active_profiles_posts_for_module', 'bx_posts', 'select', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:16:"get_text_modules";}', '', '', '', 2),
+(@iCategoryId, 'bx_charts_chart_most_active_profiles_posts_for_module_disabled', '_bx_charts_adm_stg_cpt_chart_most_active_profiles_posts_for_module', '', 'rlist', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:16:"get_text_modules";}', '', '', '', 2),
 (@iCategoryId, 'bx_charts_chart_most_active_profiles_count', '_bx_charts_adm_stg_cpt_chart_most_active_profiles_count', '5', 'digit', '', '', '', '', 3);
 
 -- PAGES: add page block on dashboard
@@ -33,4 +33,4 @@ INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `
 
 -- CRON
 INSERT INTO `sys_cron_jobs` (`name`, `time`, `class`, `file`, `service_call`) VALUES
-('bx_charts_cron', '0 * * * *', 'BxChartsCron', 'modules/boonex/charts/classes/BxChartsCron.php', '');
+('bx_charts_cron', '0 1 * * *', 'BxChartsCron', 'modules/boonex/charts/classes/BxChartsCron.php', '');

+ 9 - 3
modules/boonex/charts/install/sql/install.sql

@@ -4,16 +4,22 @@ CREATE TABLE IF NOT EXISTS `bx_charts_top_by_likes` (
   `object_id` int(11) NOT NULL default '0',
   `module` varchar(255) NOT NULL,
   `value` int(11) NOT NULL default '0',
-  PRIMARY KEY (`id`)
+  PRIMARY KEY (`id`),
+  INDEX `value` (`value`)
 );
 
 CREATE TABLE IF NOT EXISTS `bx_charts_most_active_profiles` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `object_id` int(11) NOT NULL default '0',
-  `module` varchar(255) NOT NULL,
+  `profile_module` varchar(255) NOT NULL,
+  `content_module` varchar(255) NOT NULL,
   `views_count` int(11) NOT NULL default '0',
   `create_count` int(11) NOT NULL default '0',
-  PRIMARY KEY (`id`)
+  PRIMARY KEY (`id`),
+  INDEX `views_count` (`views_count`),
+  INDEX `create_count` (`create_count`),
+  INDEX `object_id` (`object_id`),
+  INDEX `profile_module` (`profile_module`)
 );
 
 -- STUDIO: page & widget

+ 1 - 1
modules/boonex/charts/install/sql/uninstall.sql

@@ -1,6 +1,6 @@
 SET @sName = 'bx_charts';;
 
-DROP TABLE IF EXISTS `bx_charts_top_by_likes`, `bx_charts_most_active_profiles`
+DROP TABLE IF EXISTS `bx_charts_top_by_likes`, `bx_charts_most_active_profiles`;
 
 -- STUDIO WIDGET
 DELETE FROM `tp`, `tw`, `tpw`

+ 1 - 1
modules/boonex/charts/js/chart.js

@@ -29,7 +29,7 @@ BxCharts.prototype.loadData = function () {
     bx_loading(oGraphWrp, true);
 
     $.get(
-    	this._sActionsUri + 'GetChartData/' + $this._sChartName + '/',
+    	this._sActionsUri + 'get_chart_data/' + $this._sChartName + '/',
     	{
     	},
     	function (oData) {

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

@@ -6,13 +6,14 @@
 	<string name="_bx_charts_adm_stg_cpt_category_chart_most_active_profiles"><![CDATA[Наиболее активные профили]]></string>
 	<string name="_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_modules_enabled"><![CDATA[Доступно для модулей]]></string>
 	<string name="_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_count"><![CDATA[Количество]]></string>
-	<string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_modules_enabled"><![CDATA[Доступно для модулей]]></string>
+	<string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_modules_enabled"><![CDATA[Доступно для профайлов из]]></string>
 	<string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_count"><![CDATA[Количество]]></string>
-	<string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_posts_for_module"><![CDATA[Для модуля]]></string>
+	<string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_posts_for_module"><![CDATA[Для модулей]]></string>
 	<string name="_bx_charts_page_block_title_system_chart_top_contents_by_likes"><![CDATA[Популярный контент по лайкам]]></string>
 	<string name="_bx_charts_page_block_title_chart_top_contents_by_likes"><![CDATA[Популярный контент по лайкам]]></string>
 	<string name="_bx_charts_page_block_title_system_chart_most_active_profiles"><![CDATA[Наиболее активные профили]]></string>
 	<string name="_bx_charts_page_block_title_chart_most_active_profiles"><![CDATA[Наиболее активные профили]]></string>
 	<string name="_bx_charts_most_active_profiles_legend_posts"><![CDATA[Опубликовано]]></string>
 	<string name="_bx_charts_most_active_profiles_legend_views"><![CDATA[Просмотров]]></string>
+  <string name="_bx_charts_txt_empty_title_item"><![CDATA[Элемент]]></string>
 </resources>