Esempio n. 1
0
 /**
  * (non-PHPdoc)
  * @see app/code/core/Mage/Adminhtml/Block/Dashboard/Mage_Adminhtml_Block_Dashboard_Graph#getChartUrl($directUrl = true)
  */
 public function getChartUrl($directUrl = true)
 {
     // check if google chart API should be used or internal chart library
     if (Mage::getStoreConfig('piwik/piwik_chart/google')) {
         return parent::getChartUrl($directUrl);
     }
     // load the data for the series
     $this->_allSeries = $this->getRowsData($this->_dataRows);
     // initialize the axis labels
     foreach ($this->_axisMaps as $axis => $attr) {
         $this->setAxisLabels($axis, $this->getRowsData($attr, true));
     }
     // load the start and the end date
     list($dateStart, $dateEnd) = Mage::getResourceModel('reports/order_collection')->getDateRange($this->getDataHelper()->getParam('period'), '', '', true);
     // initialize the arrays for the data
     $dates = array();
     $datas = array();
     // assemble the arrays with the data and the dates
     while ($dateStart->compare($dateEnd) < 0) {
         switch ($this->getDataHelper()->getParam('period')) {
             case '24h':
                 $d = $dateStart->toString('yyyy-MM-dd HH:00');
                 $dateStart->addHour(1);
                 break;
             case '7d':
             case '1m':
                 $d = $dateStart->toString('yyyy-MM-dd');
                 $dateStart->addDay(1);
                 break;
             case '1y':
             case '2y':
                 $d = $dateStart->toString('yyyy-MM');
                 $dateStart->addMonth(1);
                 break;
         }
         foreach ($this->getAllSeries() as $index => $serie) {
             if (in_array($d, $this->_axisLabels['x'])) {
                 $datas[$index][] = (double) array_shift($this->_allSeries[$index]);
             } else {
                 $datas[$index][] = 0;
             }
         }
         $dates[] = $d;
     }
     // initialize the array for the assembled data
     $params = array();
     // iterate over the dates
     foreach ($dates as $key => $date) {
         // format the date
         switch ($this->getDataHelper()->getParam('period')) {
             case '24h':
                 $date = $this->formatTime($date, 'short', false);
                 break;
             case '7d':
             case '1m':
                 $date = $this->formatDate($date);
                 break;
             case '1y':
             case '2y':
                 $formats = Mage::app()->getLocale()->getTranslationList('datetime');
                 $format = isset($formats['yyMM']) ? $formats['yyMM'] : 'MM/yyyy';
                 $format = str_replace(array("yyyy", "yy", "MM"), array("Y", "y", "m"), $format);
                 $date = date($format, strtotime($date));
                 break;
         }
         // assemble the date and the apropriate data
         foreach ($datas as $name => $values) {
             $params[] = array($date, $key, $datas[$name][$key]);
         }
     }
     // return the encoded data
     if ($directUrl) {
         $p = array();
         foreach ($params as $name => $value) {
             $p[] = $name . '=' . urlencode($value);
         }
         return self::API_URL . '?' . implode('&', $p);
     } else {
         $gaData = urlencode(base64_encode(serialize($params)));
         $gaHash = Mage::helper('piwik')->getChartDataHash($gaData);
         $params = array('ga' => $gaData, 'h' => $gaHash);
         return $this->getUrl('piwik/adminhtml_dashboard/tunnel', array('_query' => $params));
     }
 }
Esempio n. 2
0
 public function testGetChartUrl()
 {
     $this->assertStringStartsWith('http://chart.apis.google.com/chart', $this->_block->getChartUrl());
 }