Exemplo n.º 1
0
 /**
  * 
  * @static
  * @param Zend_Log $logger
  * @return void
  */
 public static function setLogger(Zend_Log $logger)
 {
     self::$_logger = $logger;
 }
 /**
  * 在线人数曲线
  */
 public function chartAction()
 {
     $data = array();
     // 当前时间戳
     $nowOffsetTimestamp = Zend_Date::now()->subMinute(abs($this->_getParam('offset')))->getTimestamp();
     foreach ($this->_getParam('allowedGameTypes') as $gameType) {
         if (ZtChart_Model_GameType::isQule($gameType)) {
             // 取Qule游戏的数据
             $qule = new ZtChart_Model_Qule();
             // 取当前偏移量的数据
             $nowData = $qule->getGamedata(array('gametype' => $gameType, 'zoneid' => $this->_getParam('zoneid'), 'loadnumber' => $this->_getParam('range'), 'querydate' => $nowOffsetTimestamp));
             if (array_key_exists('data', $nowData) && !empty($nowData['data'])) {
                 foreach ($nowData['data'] as $item) {
                     $data['datetime'][] = $item[0];
                     $data['data'][0][] = $item[1];
                 }
             }
             // 取同比偏移量的数据
             if ($this->_hasParam('pdate')) {
                 foreach (explode(',', $this->_getParam('pdate')) as $pdate) {
                     $sameOffsetTimestamp = ZtChart_Model_Assemble_Datetime::getPredefinedStartTimestamp($pdate, $nowOffsetTimestamp);
                     $sameData = $qule->getGamedata(array('gametype' => $gameType, 'zoneid' => $this->_getParam('zoneid'), 'loadnumber' => $this->_getParam('range'), 'querydate' => $sameOffsetTimestamp));
                     if (array_key_exists('data', $sameData) && !empty($sameData['data'])) {
                         foreach ($sameData['data'] as $item) {
                             $data['data'][$pdate][] = $item[1];
                         }
                     }
                 }
             }
         } else {
             // 取InfoServer中的数据
             try {
                 if (ZtChart_Model_DbTable_Infoserver::isSingleAdapter($gameType)) {
                     // 游戏只有一个数据库的情况
                     $infoserver = ZtChart_Model_DbTable_Infoserver::factory($gameType);
                     // 取当前偏移量的数据
                     $nowOffsetDate = new Zend_Date($nowOffsetTimestamp);
                     $startNowOffsetTimestamp = $nowOffsetDate->subMinute($this->_getParam('range'))->getTimestamp();
                     for ($i = 0; $i < $this->_getParam('range'); $i++) {
                         $data['datetime'][$i] = $startNowOffsetTimestamp + $i * 60;
                         $data['tmp'][$i] = date('H:i', $data['datetime'][$i]);
                     }
                     foreach ($infoserver->fetchSumGroup($startNowOffsetTimestamp) as $item) {
                         if (in_array(date('H:i', $item[0]), $data['tmp'])) {
                             $data['data'][0][] = $item[1];
                         } else {
                             $data['data'][0][] = -1;
                         }
                     }
                     $data['data'][0] = array_pad($data['data'][0], $this->_getParam('range'), -1);
                     // 取同比偏移量的数据
                     if ($this->_hasParam('pdate')) {
                         foreach (explode(',', $this->_getParam('pdate')) as $pdate) {
                             $startSameOffsetTimestamp = ZtChart_Model_Assemble_Datetime::getPredefinedStartTimestamp($pdate, $startNowOffsetTimestamp);
                             $infoserver->setTablename($startSameOffsetTimestamp);
                             foreach ($infoserver->fetchSumGroup($startSameOffsetTimestamp, $this->_getParam('range')) as $item) {
                                 if (in_array(date('H:i', $item[0]), $data['tmp'])) {
                                     $data['data'][$pdate][] = $item[1];
                                 } else {
                                     $data['data'][$pdate][] = -1;
                                 }
                             }
                             $data['data'][$pdate] = array_pad($data['data'][$pdate], $this->_getParam('range'), -1);
                         }
                     }
                     unset($data['tmp']);
                 } else {
                     // @todo 游戏含有多个数据库的情况
                 }
             } catch (Zend_Db_Exception $e) {
                 ZtChart_Model_Logger::err($e->getMessage());
                 continue;
             }
         }
     }
     $this->_helper->json($data);
 }
Exemplo n.º 3
0
 /**
  * 初始化ZtChart_Model_Logger
  */
 protected function _initLogger()
 {
     $log = $this->bootstrap('Log')->getResource('Log');
     ZtChart_Model_Logger::setLogger($log);
 }