Ejemplo n.º 1
0
 /**
  * Returns chart settings
  *
  * @param 	array		$params
  * @return	array
  */
 public function get_chart_settings(array $params = array())
 {
     $sm = vivvo_lite_site::get_instance();
     if (!$sm->user) {
         return array();
     }
     $cache_key = 'ga_chart_settings_' . md5(serialize($params));
     if (vivvo_cache::get_instance()->exists($cache_key)) {
         return vivvo_cache::get_instance()->get($cache_key);
     }
     $ga = new vivvo_ga(array('email' => VIVVO_GA_EMAIL, 'password' => VIVVO_GA_PASSWORD, 'profileId' => VIVVO_GA_PROFILEID, 'no_auth' => true));
     $ret = array('colors' => '#0D8ECF,#B0DE09,#F2B31C,#65CDAA,#CBB9A3,#EC6AA6,#874A85,#8E0001,#2C862E,#99CCFF', 'scroller' => array('height' => '15'), 'grid' => array('x' => array('approx_count' => '8')), 'indicator' => array('color' => '#0D8ECF', 'line_alpha' => '50', 'selection_color' => '#0D8ECF', 'x_balloon_text_color' => '#FFFFFF'), 'legend' => array('text_color_hover' => '#FF2D1F'));
     $report = $ga->getReport($params);
     $ret['graphs'] = array('graph[]' => array());
     $graph_id = 0;
     empty($params['data_handler']) and $params['data_handler'] = '';
     switch ($params['data_handler']) {
         case 'article_views':
             $labels = array();
             foreach ($report as $row) {
                 $labels[$row['dimensions']['ga:eventLabel']] = 1;
             }
             class_exists('Articles') or (require VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php');
             $articles = Articles_list::factory()->get_articles_by_ids(array_keys($labels));
             foreach ($articles as $article) {
                 $ret['graphs']['graph[]'][] = array('@gid' => ++$graph_id, 'title' => $article->get_title(), 'color_hover' => '#FF2D1F', 'line_width' => '2');
             }
             break;
         case 'article_overall_stats':
         case 'article_stats':
             $labels = array();
             foreach ($report as $row) {
                 $labels[$row['dimensions']['ga:eventAction']] = 1;
             }
             foreach (array_keys($labels) as $label) {
                 $ret['graphs']['graph[]'][] = array('@gid' => ++$graph_id, 'title' => $label, 'color_hover' => '#FF2D1F', 'line_width' => '2');
             }
             break;
         default:
             $report = reset($report);
             foreach ($report['metrics'] as $metric => $value) {
                 $ret['graphs']['graph[]'][] = array('@gid' => ++$graph_id, 'title' => preg_replace('/^ga:/', '', $metric), 'color_hover' => '#FF2D1F', 'line_width' => '2');
             }
     }
     vivvo_cache::get_instance()->put($cache_key, $ret, null, VIVVO_GA_CACHE_PERIOD);
     return $ret;
 }