예제 #1
0
 /**
  * 在路由结束之后,载入权限分配表。
  * 
  * @see Zend_Controller_Request_Abstract::routeShutdown()
  * @param Zend_Controller_Plugin_Abstract $request
  * @return void
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $user = Zend_Registry::get('user');
     $role = ZtChart_Model_Acl_Loader::hash($user->getRoleId());
     Zend_View_Helper_Navigation_HelperAbstract::setDefaultRole($role);
     ZtChart_Model_Acl_Loader::getInstance()->load($this->_acl);
     Zend_View_Helper_Navigation_HelperAbstract::setDefaultAcl($this->_acl);
     // 如果拥有全部游戏,则设置为NULL。
     if (($gameTypes = $user->getRole()->getGameTypes(true)) == array_keys(ZtChart_Model_GameType::getGames())) {
         $gameTypes = null;
     }
     ZtChart_Model_Assemble_Backend_Abstract::setAllowedGameTypes($gameTypes);
 }
예제 #2
0
 /**
  * 工厂方法,返回指定游戏的在线人数日志数据表对象
  * 
  * @param integer $gameType
  * @param string $datetime
  * @param mixed $config
  * @return ZtChart_Model_DbTable_Infoserver
  */
 public static function factory($gameType, $datetime = null, $config = array())
 {
     $loader = new Zend_Loader_PluginLoader(array(__CLASS__ => realpath(__DIR__ . '/Infoserver')));
     if (false !== ($class = $loader->load(ZtChart_Model_GameType::getShortName($gameType), false))) {
         $infoserver = new $class($gameType, $datetime, $config);
     } else {
         $infoserver = new self($gameType, $datetime, $config);
     }
     return $infoserver;
 }
예제 #3
0
 /**
  * 取得可访问的游戏类型
  * 
  * @param boolean $onlycode
  * @return array
  */
 public function getGameTypes($onlycode = false)
 {
     $allowedGameTypes = ZtChart_Model_GameType::getGames();
     if (!$this->isAdmin()) {
         $gameTypes = empty($this->_roleRow) ? array() : Zend_Json::decode($this->_roleRow->role_gametype);
         $allowedGameTypes = array_intersect_key($allowedGameTypes, array_fill_keys($gameTypes, null));
     }
     if ($onlycode && is_array($allowedGameTypes)) {
         $allowedGameTypes = array_keys($allowedGameTypes);
     }
     return $allowedGameTypes;
 }
 /**
  * 在线人数曲线
  */
 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);
 }
 /**
  * 取得游戏的所有区信息
  */
 public function gamezoneAction()
 {
     $zones = array();
     $user = new ZtChart_Model_User($this->_getParam('uname'));
     if ($user->isActive() && $user->getTokenring() == $this->_getParam('token')) {
         $allowedGameTypes = $user->getRole()->getGameTypes(true);
         if (in_array($this->_getParam('gametype'), $allowedGameTypes)) {
             if (ZtChart_Model_GameType::isQule($this->_getParam('gametype'))) {
                 // 取趣乐的游戏区
                 $qule = new ZtChart_Model_Qule();
                 $zones = $qule->getGamezone($this->_getParam('gametype'));
             } else {
                 // TODO 取InfoServer的游戏区
             }
         }
     }
     $this->_helper->json($zones);
 }