RomanL 8 سال پیش
والد
کامیت
9dd5cc40af

+ 26 - 0
modules/boonex/charts/classes/BxChartsAlertsResponse.php

@@ -0,0 +1,26 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Charts Charts
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxChartsAlertsResponse extends BxDolAlertsResponse
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+    
+    public function response($oAlert)
+    {
+        $oModule = BxDolModule::getInstance('bx_charts');
+        BxDolCronQuery::getInstance()->addTransientJobClass('bx_charts_cron_transient', 'BxChartsCron', "modules/" . $oModule->_oConfig->getDirectory() . 'classes/' . $oModule->_oConfig->getClassPrefix() . 'Cron.php');
+    }
+}
+
+/** @} */

+ 11 - 1
modules/boonex/charts/classes/BxChartsCron.php

@@ -26,6 +26,7 @@ class BxChartsCron extends BxDolCron
     {
     {
         $this->processingTopByLikes();
         $this->processingTopByLikes();
         $this->processingMostActiveProfiles();
         $this->processingMostActiveProfiles();
+        $this->processingMostFollowedProfiles();
     }
     }
     
     
     function processingTopByLikes()
     function processingTopByLikes()
@@ -41,7 +42,7 @@ class BxChartsCron extends BxDolCron
                 $sSystem = $oModule->_oConfig->CNF['OBJECT_VOTES'];
                 $sSystem = $oModule->_oConfig->CNF['OBJECT_VOTES'];
                 if(empty($sSystem))
                 if(empty($sSystem))
                     continue;
                     continue;
-                $this->_oModule->_oDb->saveTopByLikes($sModule, $aSystems[$sSystem]['table_main']);
+                $this->_oModule->_oDb->saveTopByLikes($sModule, $aSystems[$sSystem]['table_track']);
             }
             }
         }
         }
     }
     }
@@ -85,6 +86,15 @@ class BxChartsCron extends BxDolCron
             }
             }
         }
         }
     }
     }
+    
+    function processingMostFollowedProfiles()
+    {
+        $this->_oModule->_oDb->clearMostFollowedProfiles();
+        $aModules = array_keys($this->_oModule->serviceGetProfileModules());
+        foreach($aModules as $sProfileModule){
+            $this->_oModule->_oDb->saveMostFollowedProfiles($sProfileModule);
+        }
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 65 - 5
modules/boonex/charts/classes/BxChartsDb.php

@@ -21,11 +21,13 @@ class BxChartsDb extends BxBaseModGeneralDb
         parent::__construct($oConfig);
         parent::__construct($oConfig);
         $this->_sTableTopByLikes = $this->_sPrefix . 'top_by_likes';
         $this->_sTableTopByLikes = $this->_sPrefix . 'top_by_likes';
         $this->_sTableMostActiveProfiles = $this->_sPrefix . 'most_active_profiles';
         $this->_sTableMostActiveProfiles = $this->_sPrefix . 'most_active_profiles';
+        $this->_sTableMostFollowedProfiles = $this->_sPrefix . 'most_followed_profiles';
     }
     }
-    
+    /* TopByLikes part */
     public function saveTopByLikes($sModuleName, $sTableName)
     public function saveTopByLikes($sModuleName, $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')) . "";
+        $iInterval = intval(getParam('bx_charts_chart_top_contents_by_likes_interval_day'));
+        $sQuery = "INSERT INTO `" . $this->_sTableTopByLikes . "` (`object_id`, `module`, `value`) SELECT `object_id`,'" . $sModuleName . "', COUNT(`id`) FROM `" . $sTableName . "` WHERE `date` > " . ($iInterval > 0 ? $this->getTimeFromDaysBefore($iInterval) : 0) . " GROUP BY `object_id` ORDER BY  COUNT(`id`) DESC LIMIT 0, " . intval(getParam('bx_charts_chart_top_contents_by_likes_count')) . "";
         $this->query($sQuery);
         $this->query($sQuery);
     }
     }
     
     
@@ -40,17 +42,21 @@ 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')));
         return $this->getAll("SELECT * FROM  `" . $this->_sTableTopByLikes . "` ORDER BY `value` DESC LIMIT 0," . intval(getParam('bx_charts_chart_top_contents_by_likes_count')));
     }
     }
     
     
+    /* MostActiveProfiles part */
     public function saveMostActiveProfiles_View($sProfileModuleName, $sTableName)
     public function saveMostActiveProfiles_View($sProfileModuleName, $sTableName)
     {
     {
+        $iInterval = intval(getParam('bx_charts_chart_most_active_profiles_interval_day'));
         $sQuery = "INSERT INTO `" . $this->_sTableMostActiveProfiles . "` (`object_id`, `profile_module`, `views_count`) SELECT `object_id`,'" . $sProfileModuleName . "', COUNT(`date`) AS views FROM `" . $sTableName . "` 
         $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`";
+ WHERE `object_id` IN (SELECT `object_id` FROM `" . $this->_sTableMostActiveProfiles . "` WHERE `profile_module` = '" . $sProfileModuleName . "' ) AND `date` > " . ($iInterval > 0 ? $this->getTimeFromDaysBefore($iInterval) : 0) . " GROUP BY `object_id`";
+       
         $this->query($sQuery);
         $this->query($sQuery);
     }
     }
     
     
     public function saveMostActiveProfiles_Create($sProfileModuleName, $sContentModuleName, $sTableName, $sColumnAuthor)
     public function saveMostActiveProfiles_Create($sProfileModuleName, $sContentModuleName, $sTableName, $sColumnAuthor)
     {
     {
+        $iInterval = intval(getParam('bx_charts_chart_most_active_profiles_interval_day'));
         $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 . "`
         $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'));
+  INNER JOIN `sys_profiles`  ON `sys_profiles`.`id` = `" . $sTableName . "`.`" . $sColumnAuthor . "` WHERE sys_profiles.type='" . $sProfileModuleName . "' AND  `" . $sTableName . "`.`added` > " . ($iInterval > 0 ? $this->getTimeFromDaysBefore($iInterval) : 0) . " 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);
         $this->query($sQuery);
     }
     }
     
     
@@ -62,7 +68,61 @@ class BxChartsDb extends BxBaseModGeneralDb
     
     
     public function getMostActiveProfiles()
     public function getMostActiveProfiles()
     {
     {
-        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')));
+        return $this->getAll("SELECT SUM(`views_count`) AS views_count, SUM(`create_count`) AS create_count, `object_id`, `profile_module` as `module` FROM `" . $this->_sTableMostActiveProfiles . "` 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')));
+    }
+   
+    /* MostFollowedProfiles part */
+    public function saveMostFollowedProfiles($sProfileModuleName)
+    {
+        $iInterval = intval(getParam('bx_charts_chart_most_followed_profiles_interval_day'));
+        $sQuery = "INSERT INTO `" . $this->_sTableMostFollowedProfiles . "` (`object_id`, `profile_module`, `followers_count`)  SELECT `sys_profiles`.`content_id`, `sys_profiles`.`type` , COUNT(`sys_profiles_conn_subscriptions`.`id`) FROM `sys_profiles_conn_subscriptions`
+  INNER JOIN `sys_profiles`  ON `sys_profiles`.`id` = `sys_profiles_conn_subscriptions`.`content` WHERE sys_profiles.type='" . $sProfileModuleName . "' AND  `sys_profiles_conn_subscriptions`.`added` > " . ($iInterval > 0 ? $this->getTimeFromDaysBefore($iInterval) : 0) . " GROUP BY `sys_profiles`.`content_id`, `sys_profiles`.`type` ORDER BY COUNT(`sys_profiles_conn_subscriptions`.`id`) DESC LIMIT 0," . intval(getParam('bx_charts_chart_most_followed_profiles_count'));
+        echo  $sQuery.'<hr>';
+        $this->query($sQuery);
+    }
+    
+    public function clearMostFollowedProfiles()
+    {
+        $sQuery = "TRUNCATE TABLE `" . $this->_sTableMostFollowedProfiles . "`";
+        $this->query($sQuery);
+    }
+    
+    public function getMostFollowedProfiles()
+    {
+        return $this->getAll("SELECT SUM(`followers_count`) AS followers_count, `object_id`, `profile_module` as `module` FROM `" . $this->_sTableMostFollowedProfiles . "` GROUP BY `object_id`, `module` ORDER BY SUM(`followers_count`) DESC LIMIT 0," . intval(getParam('bx_charts_chart_most_followed_profiles_count')));
+    }
+    
+    /* Content part */
+    public function getStatistic()
+    {
+        return $this->getAll("SELECT * FROM `sys_statistics` WHERE 1 ORDER BY `order`");
+    }
+
+    /* Growth part */
+    public function getGrowth($sTableName)
+    {
+        $iInterval = intval(getParam('bx_charts_chart_growth_interval_day'));
+        $sQuery =  "SELECT " . getParam('bx_charts_chart_growth_group_by') . "(FROM_UNIXTIME(`added`))  AS `period`, YEAR(FROM_UNIXTIME(`added`))  AS `year`,  COUNT(*) AS `count` FROM " . $sTableName . " WHERE `added` > " . ($iInterval > 0 ? $this->getTimeFromDaysBefore($iInterval) : 0) . " GROUP BY `period` ORDER BY `period` ASC";
+        return $this->getAll($sQuery);
+    }
+    
+    public function getGrowthInitValue($sTableName)
+    {
+        $iInterval = intval(getParam('bx_charts_chart_growth_interval_day'));
+        $mixedStartDate = $this->getTimeFromDaysBefore($iInterval);
+        
+        $sQuery =  "SELECT  COUNT(*) AS `count` FROM " . $sTableName . " WHERE `added` < " . ($iInterval > 0 ? $mixedStartDate : 0) . "";
+        $mixedStartValue = $this->getOne($sQuery);
+      
+        if ($iInterval == 0){
+            $sQuery =  "SELECT  MIN(`added`) as `mindata` FROM " . $sTableName;
+            $mixedStartDate = $this->getOne($sQuery);
+        }
+        return array($mixedStartValue,$mixedStartDate);
+    }
+    
+    private function getTimeFromDaysBefore($iDay){
+        return time() - $iDay * 86400;
     }
     }
 }
 }
 
 

+ 213 - 10
modules/boonex/charts/classes/BxChartsModule.php

@@ -30,7 +30,7 @@ class BxChartsModule extends BxDolModule
      * 
      * 
      * @code bx_srv('bx_charts', 'get_profile_modules', [...]); @endcode
      * @code bx_srv('bx_charts', 'get_profile_modules', [...]); @endcode
      * 
      * 
-     * Get list of avaliable prifile modules
+     * Get list of avaliable profile modules
      * 
      * 
      * @return an array with avaliable modules. 
      * @return an array with avaliable modules. 
      * 
      * 
@@ -83,6 +83,55 @@ class BxChartsModule extends BxDolModule
         return $aResult;
         return $aResult;
     }
     }
     
     
+    /**
+     * @page service Service Calls
+     * @section bx_charts Charts
+     * @subsection bx_charts-other Other
+     * @subsubsection bx_charts get_modules
+     * 
+     * @code bx_srv('bx_charts', 'get_modules', [...]); @endcode
+     * 
+     * Get list of avaliable modules
+     * 
+     * @return an array with avaliable modules. 
+     * 
+     * @see BxChartsModule::serviceGeModules
+     */
+    /** 
+     * @ref bx_charts-get_modules "get_modules"
+     */
+    public function serviceGetModules()
+    {
+        $aResult = array();
+        $aItems = $this->_oDb->getStatistic();
+        foreach($aItems as $aItem) {
+            $aResult[$aItem['name']] = _t($aItem['title']);
+        }
+        return $aResult;
+    }
+    
+    /**
+     * @page service Service Calls
+     * @section bx_charts Charts
+     * @subsection bx_charts-other Other
+     * @subsubsection bx_charts get_growth_group_by
+     * 
+     * @code bx_srv('bx_charts', 'get_growth_group_by', [...]); @endcode
+     * 
+     * Get list of avaliable grouping mode(day/week/month)
+     * 
+     * @return an array with avaliable grouping mode(day/week/month). 
+     * 
+     * @see BxChartsModule::serviceGetGrowthGroupBy
+     */
+    /** 
+     * @ref bx_charts-get_growth_group_by "get_growth_group_by"
+     */
+    public function serviceGetGrowthGroupBy()
+    {
+        return array('date' => _t('_bx_charts_txt_growth_group_by_day'),'week' => _t('_bx_charts_txt_growth_group_by_week'),'month' => _t('_bx_charts_txt_growth_group_by_month'));
+    }
+    
     /**
     /**
      * @page service Service Calls
      * @page service Service Calls
      * @section bx_charts Charts
      * @section bx_charts Charts
@@ -93,16 +142,16 @@ class BxChartsModule extends BxDolModule
      * 
      * 
      * Get Chart Top Contents By Likes
      * Get Chart Top Contents By Likes
      * 
      * 
-     * @return an html for chart1. 
+     * @return an html for chart. 
      * 
      * 
      * @see BxChartsModule::serviceGetChartTopContentsByLikes
      * @see BxChartsModule::serviceGetChartTopContentsByLikes
      */
      */
     /** 
     /** 
-     * @ref bx_charts-get_text_modules "get_chart_top_contents_by_likes"
+     * @ref bx_charts-get_chart_top_contents_by_likes "get_chart_top_contents_by_likes"
      */
      */
     public function serviceGetChartTopContentsByLikes()
     public function serviceGetChartTopContentsByLikes()
     {
     {
-        return $this->_oTemplate->getChart('TopContentsByLikes', 400);
+        return $this->_oTemplate->getChart('TopContentsByLikes', 100);
     }
     }
     
     
     /**
     /**
@@ -115,16 +164,84 @@ class BxChartsModule extends BxDolModule
      * 
      * 
      * Get Chart Most Active Profiles
      * Get Chart Most Active Profiles
      * 
      * 
-     * @return an html for chart1. 
+     * @return an html for chart. 
      * 
      * 
      * @see BxChartsModule::serviceGetChartMostActiveProfiles
      * @see BxChartsModule::serviceGetChartMostActiveProfiles
      */
      */
     /** 
     /** 
-     * @ref bx_charts-get_text_modules "get_chart_most_active_profiles"
+     * @ref bx_charts-get_chart_most_active_profiles "get_chart_most_active_profiles"
      */
      */
     public function serviceGetChartMostActiveProfiles()
     public function serviceGetChartMostActiveProfiles()
     {
     {
-        return $this->_oTemplate->getChart('MostActiveProfiles', 500);
+        return $this->_oTemplate->getChart('MostActiveProfiles', 80);
+    }
+    
+    /**
+     * @page service Service Calls
+     * @section bx_charts Charts
+     * @subsection bx_charts-other Other
+     * @subsubsection bx_charts-on-profile get_chart_most_followed_profiles
+     * 
+     * @code bx_srv('bx_charts', 'get_chart_most_followed_profiles', [...]); @endcode
+     * 
+     * Get Chart Most Followed Profiles
+     * 
+     * @return an html for chart. 
+     * 
+     * @see BxChartsModule::serviceGetChartMostFollowedProfiles
+     */
+    /** 
+     * @ref bx_charts-get_chart_most_followed_profiles "get_chart_most_followed_profiles"
+     */
+    public function serviceGetChartMostFollowedProfiles()
+    {
+        return $this->_oTemplate->getChart('MostFollowedProfiles', 40);
+    }
+    
+     /**
+     * @page service Service Calls
+     * @section bx_charts Charts
+     * @subsection bx_charts-other Other
+     * @subsubsection bx_charts-on-profile get_chart_content_by_modules
+     * 
+     * @code bx_srv('bx_charts', 'get_chart_content_by_modules', [...]); @endcode
+     * 
+     * Get Chart Content By Modules
+     * 
+     * @return an html for chart. 
+     * 
+     * @see BxChartsModule::serviceGetChartContentByModules
+     */
+    /** 
+     * @ref bx_charts-get_chart_content_by_modules "get_chart_content_by_modules"
+     */
+
+    public function serviceGetChartContentByModules()
+    {
+        return $this->_oTemplate->getChart('ContentByModules', 100);
+    }
+    
+    /**
+     * @page service Service Calls
+     * @section bx_charts Charts
+     * @subsection bx_charts-other Other
+     * @subsubsection bx_charts-on-profile get_chart_growth_by_modules
+     * 
+     * @code bx_srv('bx_charts', 'get_chart_growth_by_modules', [...]); @endcode
+     * 
+     * Get Chart Growth By Modules
+     * 
+     * @return an html for chart. 
+     * 
+     * @see BxChartsModule::serviceGetChartGrowthByModules
+     */
+    /** 
+     * @ref bx_charts-get_chart_growth_by_modules "get_chart_growth_by_modules"
+     */
+
+    public function serviceGetChartGrowthByModules()
+    {
+        return $this->_oTemplate->getChartGrowth('GrowthByModules', 75);
     }
     }
     
     
     public function actionGetChartData($Id = 0)
     public function actionGetChartData($Id = 0)
@@ -135,10 +252,9 @@ class BxChartsModule extends BxDolModule
             $aData = $this->_oDb->getTopByLikes();
             $aData = $this->_oDb->getTopByLikes();
             foreach ($aData as $aValue) {
             foreach ($aData as $aValue) {
                 $oModule = BxDolModule::getInstance($aValue['module']);
                 $oModule = BxDolModule::getInstance($aValue['module']);
-                array_push($aValues['labels'], $this->getItemName($oModule->serviceGetTitle($aValue['object_id'])) . ' (' . $oModule->_aModule['title'].')');
+                array_push($aValues['labels'], $this->getItemName($oModule->serviceGetTitle($aValue['object_id'])) . ' (' . $oModule->_aModule['title'].')'. ' - ' . $aValue['value']);
                 array_push($aValues['values'], $aValue['value']);
                 array_push($aValues['values'], $aValue['value']);
                 array_push($aValues['links'], $oModule->serviceGetLink($aValue['object_id']));
                 array_push($aValues['links'], $oModule->serviceGetLink($aValue['object_id']));
-              
             }
             }
             $aValues['colors'] = array_slice($this->aColors, 0, count($aValues['values']));
             $aValues['colors'] = array_slice($this->aColors, 0, count($aValues['values']));
             echo  '{"type": "doughnut", "data":{"labels":' . json_encode($aValues['labels']) . ',"datasets":[{"data":' . json_encode($aValues['values']) . ',"backgroundColor":' . json_encode($aValues['colors']) . '}]}, "options": {"legend": {"position": "bottom"}}, "links": ' . json_encode($aValues['links']) . '}';
             echo  '{"type": "doughnut", "data":{"labels":' . json_encode($aValues['labels']) . ',"datasets":[{"data":' . json_encode($aValues['values']) . ',"backgroundColor":' . json_encode($aValues['colors']) . '}]}, "options": {"legend": {"position": "bottom"}}, "links": ' . json_encode($aValues['links']) . '}';
@@ -153,10 +269,82 @@ class BxChartsModule extends BxDolModule
                 array_push($aValues['values1'], $aValue['create_count']);
                 array_push($aValues['values1'], $aValue['create_count']);
                 array_push($aValues['values2'], $aValue['views_count']);
                 array_push($aValues['values2'], $aValue['views_count']);
                 array_push($aValues['links'], $oModule->serviceGetLink($aValue['object_id']));
                 array_push($aValues['links'], $oModule->serviceGetLink($aValue['object_id']));
-              
             }
             }
             echo  '{"type":"horizontalBar",  "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']) . '}]}, "options": {"legend": {"position": "bottom"}}, "links": ' . json_encode($aValues['links']) . '}';
             echo  '{"type":"horizontalBar",  "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']) . '}]}, "options": {"legend": {"position": "bottom"}}, "links": ' . json_encode($aValues['links']) . '}';
         }
         }
+        
+        if ($Id == 'MostFollowedProfiles'){
+            $aValues = array('labels' => array(), 'values' => array(), 'links' => array());
+            $aData = $this->_oDb->getMostFollowedProfiles();
+            foreach ($aData as $aValue) {
+                $oModule = BxDolModule::getInstance($aValue['module']);
+                array_push($aValues['labels'], $this->getItemName($oModule->serviceGetTitle($aValue['object_id'])));
+                array_push($aValues['values'], $aValue['followers_count']);
+                array_push($aValues['links'], $oModule->serviceGetLink($aValue['object_id']));
+            }
+            echo  '{"type":"horizontalBar",  "data": {"labels":' . json_encode($aValues['labels']) . ',"datasets": [{"label": "' . _t('_bx_charts_most_followed_profiles_legend') . '","backgroundColor": "' . $this->aColors[0] . '","borderColor": "' . $this->aColors[0] . '","borderWidth": 1,"data": ' . json_encode($aValues['values']) . '}]}, "options": {"legend": {"position": "bottom"}}, "links": ' . json_encode($aValues['links']) . '}';
+        }
+        
+        if ($Id == 'ContentByModules'){
+            $aValues = array('labels' => array(), 'values' => array(), 'colors' => array(), 'links' => array());
+            $aItems = $this->_oDb->getStatistic();
+            foreach($aItems as $aItem) {
+                
+                $iValue = 0;
+                if(!empty($aItem['query']))
+                    $iValue = (int)$this->_oDb->getOne($aItem['query']);
+                else if(BxDolRequest::serviceExists($aItem['module'], 'get_query_statistics'))
+                    $iValue = (int)BxDolService::call($aItem['module'], 'get_query_statistics', array($aItem));
+                
+                $sLink = '';
+                if(!empty($aItem['link']))
+                    $sLink = BxDolPermalinks::getInstance()->permalink($aItem['link']);
+                
+                array_push($aValues['labels'], _t($aItem['title']) . ' - ' . $iValue);
+                array_push($aValues['values'], $iValue);
+                array_push($aValues['links'], $sLink);
+            }
+            $aValues['colors'] = array_slice($this->aColors, 0, count($aValues['values']));
+            echo  '{"type": "doughnut", "data":{"labels":' . json_encode($aValues['labels']) . ',"datasets":[{"data":' . json_encode($aValues['values']) . ',"backgroundColor":' . json_encode($aValues['colors']) . '}]}, "options": {"legend": {"position": "bottom"}}, "links": ' . json_encode($aValues['links']) . '}';
+        }
+        
+        if ($Id == 'GrowthByModules'){
+            $aValues = array('labels' => array(), 'values1' => array(), 'values2' => array(), 'links' => array());
+            $sModuleName = $sTableName = bx_get('m');
+            $sModuleTitle = "";
+            $aTmp = $this->getSelectedModulesGrowth();
+            if (empty($sModuleName)){
+                $sModuleName = $sTableName = $aTmp[0][0];
+            }
+            $sModuleTitle = $aTmp[1][$sModuleName];
+            $oModule = BxDolModule::getInstance($sModuleName);
+            if (isset($oModule->_oConfig->CNF['TABLE_ENTRIES']))
+                $sTableName = $oModule->_oConfig->CNF['TABLE_ENTRIES'];
+            
+            $aData = $this->_oDb->getGrowth($sTableName);
+            $aTmp2 = $this->_oDb->getGrowthInitValue($sTableName); 
+            $iValuePrev = $aTmp2[0]; 
+            $iMinTime = $aTmp2[1] * 1000; 
+            $iMaxTime = time() * 1000; 
+            $sGroupBy = getParam('bx_charts_chart_growth_group_by');
+            foreach ($aData as $aValue) {
+                $aValue['count1'] = $iValuePrev + $aValue['count'];
+                $iX = $this->getXValueByParams($aValue, getParam('bx_charts_chart_growth_group_by'));
+                array_push($aValues['values1'], array('x' => $iX , 'y' => $aValue['count1']));
+                array_push($aValues['values2'], array('x' => $iX, 'y' => $aValue['count']));
+                $iValuePrev = $aValue['count1'];
+            }
+            
+            echo  '{"type":"line",  "data": {"datasets": [{"label": "' . $sModuleTitle . ':' . _t('_bx_charts_growth_speed_legend') . '","fill": "false","backgroundColor": "' . $this->aColors[2] . '","borderColor":"' . $this->aColors[2] . '","borderWidth": 1,"data": ' . json_encode($aValues['values2']) . '}, {"label": "' . $sModuleTitle . ':' . _t('_bx_charts_growth_legend') . '","fill": "false","backgroundColor": "' . $this->aColors[3] . '","borderColor": "' . $this->aColors[3] . '","borderWidth": 1,"data": ' . json_encode($aValues['values1']) . '}]}, "options": {"legend": {"position": "bottom"},"scales": {"xAxes": [{"type": "time", "time": {"tooltipFormat": "DD.MM.YYYY", "unit" : "' . ($sGroupBy == 'month' ? 'month' : 'day') . '"}, "ticks": {"min": "' . $iMinTime . '", "max": "' . $iMaxTime . '", "autoSkip": "true"}, "display": "true", "distribution": "linear"}]}}}';
+        }
+    }
+    
+    public function getSelectedModulesGrowth()
+    {
+        $aModulesList = $this->serviceGetModules();
+        $aModules = array_keys($aModulesList);
+        $sModulesDisabled = explode(',', getParam('bx_charts_chart_growth_modules'));
+        return array(array_diff($aModules, $sModulesDisabled), $aModulesList);
     }
     }
     
     
     private function getItemName($sString)
     private function getItemName($sString)
@@ -170,6 +358,21 @@ class BxChartsModule extends BxDolModule
         }
         }
         return $sString;
         return $sString;
     }
     }
+    
+    private function getXValueByParams($aValue, $sMode)
+    {
+        switch ($sMode) {
+            case 'date':
+                return strtotime($aValue['period']) * 1000;
+            case 'week':
+                $mixedTime = strtotime("01.01." . $aValue['year'], time());
+                $iDay = date('w', $mixedTime);
+                $mixedTime += ((7 * $aValue['period']) + 1 - $iDay) * 24 * 3600;
+                return $mixedTime * 1000;
+            case 'month':
+                return strtotime('01.' . $aValue['period'] . '.' . $aValue['year']) * 1000;
+        }
+    }
 }
 }
 
 
 /** @} */
 /** @} */

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

@@ -15,14 +15,37 @@ class BxChartsTemplate extends BxBaseModGeneralTemplate
 {
 {
     function __construct(&$oConfig, &$oDb)
     function __construct(&$oConfig, &$oDb)
     {
     {
+        $this->MODULE = 'bx_charts';
         parent::__construct($oConfig, $oDb);
         parent::__construct($oConfig, $oDb);
     }
     }
     
     
+    function getChartGrowth($sChartName, $iHeight)
+    {
+        $this->getModule();
+        $aTmp = $this->_oModule->getSelectedModulesGrowth();
+        $aModules =  $aTmp[0];
+        $aModulesList = $aTmp[1];     
+        $aModulesList2 = array();
+        foreach($aModules as $sModule){
+            $aModulesList2[] = array('value' => $sModule, 'title' => $aModulesList[$sModule]);
+        }
+        
+        return $this->parseHtmlByName('chart-growth.html', array(
+            'chart' => $this->getChart($sChartName, $iHeight),
+            'bx_if:show_module_selector' => array(
+                'condition' => count($aModulesList2)>1 ? true : false,
+                'content' => array(
+                    'chart_name' => $sChartName,
+                    'bx_repeat:items' => $aModulesList2
+                )
+            )));
+    }
+    
     function getChart($sChartName, $iHeight)
     function getChart($sChartName, $iHeight)
     {
     {
         $this->addJs(array('chart.min.js', 'chart.js'));
         $this->addJs(array('chart.min.js', 'chart.js'));
         $this->addCss(array('chart.css'));
         $this->addCss(array('chart.css'));
-        return $this->getJsCode('chart', array('chartName' => $sChartName, 'height' => $iHeight)) . $this->parseHtmlByName('chart.html', array('chart_name' => $sChartName));
+        return $this->getJsCode('chart', array('chartName' => $sChartName)) . $this->parseHtmlByName('chart.html', array('chart_name' => $sChartName, 'height' => $iHeight));
     }
     }
     
     
     public function getJsCode($sType, $aParams = array(), $bWrap = true)
     public function getJsCode($sType, $aParams = array(), $bWrap = true)

+ 24 - 1
modules/boonex/charts/install/langs/en.xml

@@ -5,16 +5,39 @@
   <string name="_bx_charts_adm_stg_cpt_type"><![CDATA[Charts]]></string>
   <string name="_bx_charts_adm_stg_cpt_type"><![CDATA[Charts]]></string>
 	<string name="_bx_charts_adm_stg_cpt_category_chart_top_contents_by_likes"><![CDATA[Top contents by likes]]></string>
 	<string name="_bx_charts_adm_stg_cpt_category_chart_top_contents_by_likes"><![CDATA[Top contents by likes]]></string>
 	<string name="_bx_charts_adm_stg_cpt_category_chart_most_active_profiles"><![CDATA[Most active profiles]]></string>
 	<string name="_bx_charts_adm_stg_cpt_category_chart_most_active_profiles"><![CDATA[Most active profiles]]></string>
+  <string name="_bx_charts_adm_stg_cpt_category_chart_most_followed_profiles"><![CDATA[Most followed profiles]]></string>
+  <string name="_bx_charts_adm_stg_cpt_category_chart_growth"><![CDATA[Content growth]]></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_modules_enabled"><![CDATA[Enabled for modules]]></string>
   <string name="_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_count"><![CDATA[Max number of items in the chart ]]></string>
   <string name="_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_count"><![CDATA[Max number of items in the chart ]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_interval_day"><![CDATA[Interval in days (0 for all data)]]></string>
   <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_modules_enabled"><![CDATA[Profiles modules]]></string>
   <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_modules_enabled"><![CDATA[Profiles modules]]></string>
-  <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_count"><![CDATA[Max number of items in the chart ]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_count"><![CDATA[Max number of items in the chart]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_interval_day"><![CDATA[Interval in days (0 for all data)]]></string>
   <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_posts_for_module"><![CDATA[Modules to count content in]]></string>
   <string name="_bx_charts_adm_stg_cpt_chart_most_active_profiles_posts_for_module"><![CDATA[Modules to count content in]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_most_followed_profiles_modules_enabled"><![CDATA[Most followed profiles]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_most_followed_profiles_count"><![CDATA[Max number of items in the chart ]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_most_followed_profiles_interval_day"><![CDATA[Interval in days (0 for all data)]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_growth_modules_enabled"><![CDATA[Enabled for]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_growth_interval_day"><![CDATA[Interval in days (0 for all data)]]></string>
+  <string name="_bx_charts_adm_stg_cpt_chart_growth_group_by"><![CDATA[Group by]]></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_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_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_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_page_block_title_chart_most_active_profiles"><![CDATA[Most active profiles]]></string>
+  <string name="_bx_charts_page_block_title_system_chart_most_followed_profiles"><![CDATA[Most followed profiles]]></string>
+  <string name="_bx_charts_page_block_title_chart_most_followed_profiles"><![CDATA[Most followed profiles]]></string>
+  <string name="_bx_charts_page_block_title_system_chart_content_by_modules"><![CDATA[Content]]></string>
+  <string name="_bx_charts_page_block_title_chart_content_by_modules"><![CDATA[Content]]></string>
+  <string name="_bx_charts_page_block_title_system_chart_growth_by_modules"><![CDATA[Growth]]></string>
+  <string name="_bx_charts_page_block_title_chart_growth_by_modules"><![CDATA[Growth]]></string>
   <string name="_bx_charts_most_active_profiles_legend_posts"><![CDATA[Posted items]]></string>
   <string name="_bx_charts_most_active_profiles_legend_posts"><![CDATA[Posted items]]></string>
+  <string name="_bx_charts_growth_legend"><![CDATA[Growth]]></string>
+  <string name="_bx_charts_growth_speed_legend"><![CDATA[Growth speed]]></string>
+  
   <string name="_bx_charts_most_active_profiles_legend_views"><![CDATA[Profile views]]></string>
   <string name="_bx_charts_most_active_profiles_legend_views"><![CDATA[Profile views]]></string>
+  <string name="_bx_charts_most_followed_profiles_legend"><![CDATA[Profile's followers]]></string>
   <string name="_bx_charts_txt_empty_title_item"><![CDATA[Item]]></string>
   <string name="_bx_charts_txt_empty_title_item"><![CDATA[Item]]></string>
+  <string name="_bx_charts_txt_growth_group_by_day"><![CDATA[Day]]></string>
+  <string name="_bx_charts_txt_growth_group_by_week"><![CDATA[Week]]></string>
+  <string name="_bx_charts_txt_growth_group_by_month"><![CDATA[Month]]></string>
 </resources>
 </resources>

+ 5 - 0
modules/boonex/charts/install/sql/disable.sql

@@ -11,3 +11,8 @@ DELETE FROM `sys_pages_blocks` WHERE `module` = @sName;
 
 
 -- CRON
 -- CRON
 DELETE FROM `sys_cron_jobs` WHERE `name` LIKE 'bx_charts%';
 DELETE FROM `sys_cron_jobs` WHERE `name` LIKE 'bx_charts%';
+
+-- ALERTS
+SET @iHandler := (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = @sName LIMIT 1);
+DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandler;
+DELETE FROM `sys_alerts_handlers` WHERE `id` = @iHandler;

+ 33 - 4
modules/boonex/charts/install/sql/enable.sql

@@ -13,7 +13,8 @@ SET @iCategoryId = LAST_INSERT_ID();
 
 
 INSERT INTO `sys_options` (`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_params`, `check_error`, `order`) VALUES
 INSERT INTO `sys_options` (`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_params`, `check_error`, `order`) VALUES
 (@iCategoryId, 'bx_charts_chart_top_contents_by_likes_modules_disabled', '_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_modules_enabled', '', 'rlist', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:16:"get_text_modules";}', '', '', '', 1),
 (@iCategoryId, 'bx_charts_chart_top_contents_by_likes_modules_disabled', '_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_modules_enabled', '', 'rlist', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:16:"get_text_modules";}', '', '', '', 1),
-(@iCategoryId, 'bx_charts_chart_top_contents_by_likes_count', '_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_count', '4', 'digit', '', '', '', '', 2);
+(@iCategoryId, 'bx_charts_chart_top_contents_by_likes_count', '_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_count', '4', 'digit', '', '', '', '', 2),
+(@iCategoryId, 'bx_charts_chart_top_contents_by_likes_interval_day', '_bx_charts_adm_stg_cpt_chart_top_contents_by_likes_interval_day', '7', 'digit', '', '', '', '', 3);
 
 
 INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `hidden`, `order`) VALUES(@iTypeId,  'bx_charts_chart_most_active_profiles', '_bx_charts_adm_stg_cpt_category_chart_most_active_profiles', 0, 2);
 INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `hidden`, `order`) VALUES(@iTypeId,  'bx_charts_chart_most_active_profiles', '_bx_charts_adm_stg_cpt_category_chart_most_active_profiles', 0, 2);
 SET @iCategoryId = LAST_INSERT_ID();
 SET @iCategoryId = LAST_INSERT_ID();
@@ -21,16 +22,44 @@ SET @iCategoryId = LAST_INSERT_ID();
 INSERT INTO `sys_options` (`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_params`, `check_error`, `order`) VALUES
 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_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_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_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', '4', 'digit', '', '', '', '', 3);
+(@iCategoryId, 'bx_charts_chart_most_active_profiles_count', '_bx_charts_adm_stg_cpt_chart_most_active_profiles_count', '4', 'digit', '', '', '', '', 3),
+(@iCategoryId, 'bx_charts_chart_most_active_profiles_interval_day', '_bx_charts_adm_stg_cpt_chart_most_active_profiles_interval_day', '7', 'digit', '', '', '', '', 4);
+
+INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `hidden`, `order`) VALUES(@iTypeId,  'bx_charts_chart_most_followed_profiles', '_bx_charts_adm_stg_cpt_category_chart_most_followed_profiles', 0, 3);
+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_followed_profiles_modules_disabled', '_bx_charts_adm_stg_cpt_chart_most_followed_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_followed_profiles_count', '_bx_charts_adm_stg_cpt_chart_most_followed_profiles_count', '4', 'digit', '', '', '', '', 2),
+(@iCategoryId, 'bx_charts_chart_most_followed_profiles_interval_day', '_bx_charts_adm_stg_cpt_chart_most_followed_profiles_interval_day', '7', 'digit', '', '', '', '', 3);
+
+INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `hidden`, `order`) VALUES(@iTypeId,  'bx_charts_chart_chart_growth', '_bx_charts_adm_stg_cpt_category_chart_growth', 0, 4);
+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_growth_modules', '_bx_charts_adm_stg_cpt_chart_growth_modules_enabled', '', 'rlist', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:11:"get_modules";}', '', '', '', 1),
+(@iCategoryId, 'bx_charts_chart_growth_interval_day', '_bx_charts_adm_stg_cpt_chart_growth_interval_day', '30', 'digit', '', '', '', '', 2),
+(@iCategoryId, 'bx_charts_chart_growth_group_by', '_bx_charts_adm_stg_cpt_chart_growth_group_by', 'date', 'select', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:19:"get_growth_group_by";}', '', '', '', 3);
 
 
 -- PAGES: add page block on dashboard
 -- PAGES: add page block on dashboard
 SET @iPBCellDashboard = 2;
 SET @iPBCellDashboard = 2;
 SET @iPBOrderDashboard = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_pages_blocks` WHERE `object` = 'sys_dashboard' AND `cell_id` = @iPBCellDashboard LIMIT 1);
 SET @iPBOrderDashboard = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_pages_blocks` WHERE `object` = 'sys_dashboard' AND `cell_id` = @iPBCellDashboard LIMIT 1);
 INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES
 INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES
 ('sys_dashboard', @iPBCellDashboard,  @sName, '_bx_charts_page_block_title_system_chart_top_contents_by_likes', '_bx_charts_page_block_title_chart_top_contents_by_likes', 11, 192, 'service', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:31:"get_chart_top_contents_by_likes";}', 0, 1, 1, @iPBOrderDashboard),
 ('sys_dashboard', @iPBCellDashboard,  @sName, '_bx_charts_page_block_title_system_chart_top_contents_by_likes', '_bx_charts_page_block_title_chart_top_contents_by_likes', 11, 192, 'service', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:31:"get_chart_top_contents_by_likes";}', 0, 1, 1, @iPBOrderDashboard),
-('sys_dashboard', @iPBCellDashboard,  @sName, '_bx_charts_page_block_title_system_chart_most_active_profiles', '_bx_charts_page_block_title_chart_most_active_profiles', 11, 192, 'service', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:30:"get_chart_most_active_profiles";}', 0, 1, 1, @iPBOrderDashboard + 1);
-
+('sys_dashboard', @iPBCellDashboard,  @sName, '_bx_charts_page_block_title_system_chart_most_active_profiles', '_bx_charts_page_block_title_chart_most_active_profiles', 11, 192, 'service', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:30:"get_chart_most_active_profiles";}', 0, 1, 1, @iPBOrderDashboard + 1),
+('sys_dashboard', @iPBCellDashboard,  @sName, '_bx_charts_page_block_title_system_chart_most_followed_profiles', '_bx_charts_page_block_title_chart_most_followed_profiles', 11, 192, 'service', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:32:"get_chart_most_followed_profiles";}', 0, 1, 1, @iPBOrderDashboard + 2),
+('sys_dashboard', @iPBCellDashboard,  @sName, '_bx_charts_page_block_title_system_chart_content_by_modules', '_bx_charts_page_block_title_chart_content_by_modules', 11, 192, 'service', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:28:"get_chart_content_by_modules";}', 0, 1, 1, @iPBOrderDashboard + 3),
+('sys_dashboard', @iPBCellDashboard,  @sName, '_bx_charts_page_block_title_system_chart_growth_by_modules', '_bx_charts_page_block_title_chart_growth_by_modules', 11, 192, 'service', 'a:2:{s:6:"module";s:9:"bx_charts";s:6:"method";s:27:"get_chart_growth_by_modules";}', 0, 1, 1, @iPBOrderDashboard + 4);
 
 
 -- CRON
 -- CRON
 INSERT INTO `sys_cron_jobs` (`name`, `time`, `class`, `file`, `service_call`) VALUES
 INSERT INTO `sys_cron_jobs` (`name`, `time`, `class`, `file`, `service_call`) VALUES
 ('bx_charts_cron', '0 1 * * *', 'BxChartsCron', 'modules/boonex/charts/classes/BxChartsCron.php', '');
 ('bx_charts_cron', '0 1 * * *', 'BxChartsCron', 'modules/boonex/charts/classes/BxChartsCron.php', '');
+
+-- ALERTS
+INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `service_call`) VALUES 
+(@sName, 'BxChartsAlertsResponse', 'modules/boonex/charts/classes/BxChartsAlertsResponse.php', '');
+SET @iHandler := LAST_INSERT_ID();
+
+INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
+('system', 'save_setting', @iHandler);
+

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

@@ -11,8 +11,8 @@ CREATE TABLE IF NOT EXISTS `bx_charts_top_by_likes` (
 CREATE TABLE IF NOT EXISTS `bx_charts_most_active_profiles` (
 CREATE TABLE IF NOT EXISTS `bx_charts_most_active_profiles` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `object_id` int(11) NOT NULL default '0',
   `object_id` int(11) NOT NULL default '0',
-  `profile_module` varchar(255) NOT NULL,
-  `content_module` varchar(255) NOT NULL,
+  `profile_module` varchar(19) NOT NULL,
+  `content_module` varchar(19) NOT NULL,
   `views_count` int(11) NOT NULL default '0',
   `views_count` int(11) NOT NULL default '0',
   `create_count` int(11) NOT NULL default '0',
   `create_count` int(11) NOT NULL default '0',
   PRIMARY KEY (`id`),
   PRIMARY KEY (`id`),
@@ -22,6 +22,19 @@ CREATE TABLE IF NOT EXISTS `bx_charts_most_active_profiles` (
   INDEX `profile_module` (`profile_module`)
   INDEX `profile_module` (`profile_module`)
 );
 );
 
 
+CREATE TABLE IF NOT EXISTS `bx_charts_most_followed_profiles` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `object_id` int(11) NOT NULL default '0',
+  `profile_module` varchar(19) NOT NULL,
+  `followers_count` int(11) NOT NULL default '0',
+  PRIMARY KEY (`id`),
+  INDEX `followers_count` (`followers_count`),
+  INDEX `object_id` (`object_id`),
+  INDEX `profile_module` (`profile_module`)
+);
+
+
+
 -- STUDIO: page & widget
 -- STUDIO: page & widget
 INSERT INTO `sys_std_pages`(`index`, `name`, `header`, `caption`, `icon`) VALUES
 INSERT INTO `sys_std_pages`(`index`, `name`, `header`, `caption`, `icon`) VALUES
 (3, @sName, '_bx_charts', '_bx_charts', 'bx_charts@modules/boonex/charts/|std-icon.svg');
 (3, @sName, '_bx_charts', '_bx_charts', 'bx_charts@modules/boonex/charts/|std-icon.svg');

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

@@ -1,6 +1,6 @@
 SET @sName = 'bx_charts';;
 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`, `bx_charts_most_followed_profiles`;
 
 
 -- STUDIO WIDGET
 -- STUDIO WIDGET
 DELETE FROM `tp`, `tw`, `tpw`
 DELETE FROM `tp`, `tw`, `tpw`

+ 29 - 8
modules/boonex/charts/js/chart.js

@@ -25,11 +25,18 @@ BxCharts.prototype.loadData = function () {
     var oGraph = $('.' + this._sKeyGraph);
     var oGraph = $('.' + this._sKeyGraph);
     var oGraphWrp = oGraph.parents('div:first');
     var oGraphWrp = oGraph.parents('div:first');
     var oGraphErr = oGraphWrp.find('.bx-chart-growth-graph-error').hide();
     var oGraphErr = oGraphWrp.find('.bx-chart-growth-graph-error').hide();
+    var sAdditionalParameters = "";
+    if ($('.bx_chart_growth_selector_' + this._sChartName).length > 0) {
+        sAdditionalParameters = '?m=' + $('.bx_chart_growth_selector_' + this._sChartName).val();
+        $('.bx_chart_growth_selector_' + this._sChartName).change(function () {
+            $this.loadData();
+        });
+    }
 
 
     bx_loading(oGraphWrp, true);
     bx_loading(oGraphWrp, true);
 
 
     $.get(
     $.get(
-    	this._sActionsUri + 'get_chart_data/' + $this._sChartName + '/',
+    	this._sActionsUri + 'get_chart_data/' + $this._sChartName + '/' + sAdditionalParameters +'',
     	{
     	{
     	},
     	},
     	function (oData) {
     	function (oData) {
@@ -46,12 +53,25 @@ BxCharts.prototype.loadData = function () {
     	    if (oData.links) {
     	    if (oData.links) {
     	        Chart.defaults.doughnut.legend.onClick = function (e, legendItem) {
     	        Chart.defaults.doughnut.legend.onClick = function (e, legendItem) {
     	            var iIndex = $this._oChart.data.datasets[0].backgroundColor.indexOf(legendItem.fillStyle);
     	            var iIndex = $this._oChart.data.datasets[0].backgroundColor.indexOf(legendItem.fillStyle);
-    	            if (iIndex && oData.links[iIndex]) {
+    	            if (iIndex && oData.links[iIndex] && oData.links[iIndex] != "") {
     	                location.href = oData.links[iIndex];
     	                location.href = oData.links[iIndex];
     	            }
     	            }
     	        };
     	        };
     	    }
     	    }
 
 
+    	    Chart.defaults.doughnut.tooltips.callbacks.label = function (tooltipItem, data) {
+    	        return data.labels[tooltipItem.index];
+    	    };
+
+    	    Chart.defaults.global.layout  = {
+    	        padding: {
+    	                left: 40,
+    	                right: 40,
+    	                top: 40,
+    	                bottom: 20
+    	        }
+    	    }
+
     	    var oDataForChart = oData.data || false;
     	    var oDataForChart = oData.data || false;
     	    var oChartOptions = oData.options || {};
     	    var oChartOptions = oData.options || {};
     	    if ($this._oChart)
     	    if ($this._oChart)
@@ -67,15 +87,16 @@ BxCharts.prototype.loadData = function () {
     	        oGraph.click(function (evt) {
     	        oGraph.click(function (evt) {
     	            var activePoint = $this._oChart.getElementAtEvent(evt)[0];
     	            var activePoint = $this._oChart.getElementAtEvent(evt)[0];
     	            if (activePoint) {
     	            if (activePoint) {
-    	                var data = activePoint._chart.data;
-    	                var datasetIndex = activePoint._datasetIndex;
-    	                var label = data.datasets[datasetIndex].label;
-    	                var value = data.datasets[datasetIndex].data[activePoint._index];
-    	                location.href = oData.links[activePoint._index];
+    	                var oDataChart = activePoint._chart.data;
+    	                var iDatasetIndex = activePoint._datasetIndex;
+    	                var sLabel = oDataChart.datasets[iDatasetIndex].label;
+    	                var sValue = oDataChart.datasets[iDatasetIndex].data[activePoint._index];
+    	                var sLink = oData.links[activePoint._index];
+    	                if (sLink != "")
+    	                    location.href = sLink;
     	            }
     	            }
     	        });
     	        });
     	    }
     	    }
-
     	},
     	},
     	'json'
     	'json'
     );
     );

+ 11 - 0
modules/boonex/charts/template/chart-growth.html

@@ -0,0 +1,11 @@
+<bx_if:show_module_selector>
+    <div>
+        <select class="bx-def-font-inputs bx-form-input-select bx_chart_growth_selector___chart_name__">
+            <bx_repeat:items>
+                <option value="__value__">__title__</option>
+            </bx_repeat:items>
+        </select>
+    </div>
+</bx_if:show_module_selector>
+
+__chart__

+ 3 - 5
modules/boonex/charts/template/chart.html

@@ -1,5 +1,3 @@
-<div class="bx-chart-growth">
-    <div class="bx-chart-growth-graph bx-def-border">
-        <canvas class="bx_chart_growth_graph bx_chart_growth_graph___chart_name__" width="100%" height="__height__"></canvas>
-    </div>
-</div>
+<div class="bx-def-border">
+    <canvas class="bx_chart_growth_graph___chart_name__" width="100%" height="__height__"></canvas>
+</div>