예제 #1
0
파일: Config.php 프로젝트: aiesh/magento2
 /**
  * Retrieve list of months translation
  *
  * @return array
  */
 public function getMonths()
 {
     $data = $this->_localeLists->getTranslationList('month');
     foreach ($data as $key => $value) {
         $monthNum = $key < 10 ? '0' . $key : $key;
         $data[$key] = $monthNum . ' - ' . $value;
     }
     return $data;
 }
예제 #2
0
파일: Graph.php 프로젝트: aiesh/magento2
 /**
  * Get chart url
  *
  * @param bool $directUrl
  * @return string
  */
 public function getChartUrl($directUrl = true)
 {
     $params = array('cht' => 'lc', 'chf' => 'bg,s,ffffff', 'chco' => 'ef672f', 'chls' => '7', 'chxs' => '0,676056,15,0,l,676056|1,676056,15,0,l,676056', 'chm' => 'h,f2ebde,0,0:1:.1,1,-1');
     $this->_allSeries = $this->getRowsData($this->_dataRows);
     foreach ($this->_axisMaps as $axis => $attr) {
         $this->setAxisLabels($axis, $this->getRowsData($attr, true));
     }
     $timezoneLocal = $this->_scopeConfig->getValue($this->_localeDate->getDefaultTimezonePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     list($dateStart, $dateEnd) = $this->_collectionFactory->create()->getDateRange($this->getDataHelper()->getParam('period'), '', '', true);
     $dateStart->setTimezone($timezoneLocal);
     $dateEnd->setTimezone($timezoneLocal);
     $dates = array();
     $datas = array();
     while ($dateStart->compare($dateEnd) < 0) {
         switch ($this->getDataHelper()->getParam('period')) {
             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;
             default:
                 $d = $dateStart->toString('yyyy-MM-dd HH:00');
                 $dateStart->addHour(1);
         }
         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;
     }
     /**
      * setting skip step
      */
     if (count($dates) > 8 && count($dates) < 15) {
         $c = 1;
     } else {
         if (count($dates) >= 15) {
             $c = 2;
         } else {
             $c = 0;
         }
     }
     /**
      * skipping some x labels for good reading
      */
     $i = 0;
     foreach ($dates as $k => $d) {
         if ($i == $c) {
             $dates[$k] = $d;
             $i = 0;
         } else {
             $dates[$k] = '';
             $i++;
         }
     }
     $this->_axisLabels['x'] = $dates;
     $this->_allSeries = $datas;
     //Google encoding values
     if ($this->_encoding == "s") {
         // simple encoding
         $params['chd'] = "s:";
         $dataDelimiter = "";
         $dataSetdelimiter = ",";
         $dataMissing = "_";
     } else {
         // extended encoding
         $params['chd'] = "e:";
         $dataDelimiter = "";
         $dataSetdelimiter = ",";
         $dataMissing = "__";
     }
     // process each string in the array, and find the max length
     $localmaxvalue = array(0);
     $localminvalue = array(0);
     foreach ($this->getAllSeries() as $index => $serie) {
         $localmaxvalue[$index] = max($serie);
         $localminvalue[$index] = min($serie);
     }
     $maxvalue = max($localmaxvalue);
     $minvalue = min($localminvalue);
     // default values
     $yrange = 0;
     $yLabels = array();
     $miny = 0;
     $maxy = 0;
     $yorigin = 0;
     if ($minvalue >= 0 && $maxvalue >= 0) {
         if ($maxvalue > 10) {
             $p = pow(10, $this->_getPow($maxvalue));
             $maxy = ceil($maxvalue / $p) * $p;
             $yLabels = range($miny, $maxy, $p);
         } else {
             $maxy = ceil($maxvalue + 1);
             $yLabels = range($miny, $maxy, 1);
         }
         $yrange = $maxy;
         $yorigin = 0;
     }
     $chartdata = array();
     foreach ($this->getAllSeries() as $index => $serie) {
         $thisdataarray = $serie;
         if ($this->_encoding == "s") {
             // SIMPLE ENCODING
             for ($j = 0; $j < sizeof($thisdataarray); $j++) {
                 $currentvalue = $thisdataarray[$j];
                 if (is_numeric($currentvalue)) {
                     $ylocation = round((strlen($this->_simpleEncoding) - 1) * ($yorigin + $currentvalue) / $yrange);
                     $chartdata[] = substr($this->_simpleEncoding, $ylocation, 1) . $dataDelimiter;
                 } else {
                     $chartdata[] = $dataMissing . $dataDelimiter;
                 }
             }
         } else {
             // EXTENDED ENCODING
             for ($j = 0; $j < sizeof($thisdataarray); $j++) {
                 $currentvalue = $thisdataarray[$j];
                 if (is_numeric($currentvalue)) {
                     if ($yrange) {
                         $ylocation = 4095 * ($yorigin + $currentvalue) / $yrange;
                     } else {
                         $ylocation = 0;
                     }
                     $firstchar = floor($ylocation / 64);
                     $secondchar = $ylocation % 64;
                     $mappedchar = substr($this->_extendedEncoding, $firstchar, 1) . substr($this->_extendedEncoding, $secondchar, 1);
                     $chartdata[] = $mappedchar . $dataDelimiter;
                 } else {
                     $chartdata[] = $dataMissing . $dataDelimiter;
                 }
             }
         }
         $chartdata[] = $dataSetdelimiter;
     }
     $buffer = implode('', $chartdata);
     $buffer = rtrim($buffer, $dataSetdelimiter);
     $buffer = rtrim($buffer, $dataDelimiter);
     $buffer = str_replace($dataDelimiter . $dataSetdelimiter, $dataSetdelimiter, $buffer);
     $params['chd'] .= $buffer;
     $valueBuffer = array();
     if (sizeof($this->_axisLabels) > 0) {
         $params['chxt'] = implode(',', array_keys($this->_axisLabels));
         $indexid = 0;
         foreach ($this->_axisLabels as $idx => $labels) {
             if ($idx == 'x') {
                 /**
                  * Format date
                  */
                 foreach ($this->_axisLabels[$idx] as $_index => $_label) {
                     if ($_label != '') {
                         switch ($this->getDataHelper()->getParam('period')) {
                             case '24h':
                                 $this->_axisLabels[$idx][$_index] = $this->formatTime(new \Magento\Framework\Stdlib\DateTime\Date($_label, 'yyyy-MM-dd HH:00'), 'short', false);
                                 break;
                             case '7d':
                             case '1m':
                                 $this->_axisLabels[$idx][$_index] = $this->formatDate(new \Magento\Framework\Stdlib\DateTime\Date($_label, 'yyyy-MM-dd'));
                                 break;
                             case '1y':
                             case '2y':
                                 $formats = $this->_localeLists->getTranslationList('datetime');
                                 $format = isset($formats['yyMM']) ? $formats['yyMM'] : 'MM/yyyy';
                                 $format = str_replace(array("yyyy", "yy", "MM"), array("Y", "y", "m"), $format);
                                 $this->_axisLabels[$idx][$_index] = date($format, strtotime($_label));
                                 break;
                         }
                     } else {
                         $this->_axisLabels[$idx][$_index] = '';
                     }
                 }
                 $tmpstring = implode('|', $this->_axisLabels[$idx]);
                 $valueBuffer[] = $indexid . ":|" . $tmpstring;
             }
             $indexid++;
         }
         $params['chxl'] = implode('|', $valueBuffer);
     }
     // chart size
     $params['chs'] = $this->getWidth() . 'x' . $this->getHeight();
     // 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(json_encode($params)));
         $gaHash = $this->_dashboardData->getChartDataHash($gaData);
         $params = array('ga' => $gaData, 'h' => $gaHash);
         return $this->getUrl('adminhtml/*/tunnel', array('_query' => $params));
     }
 }