Пример #1
0
 public function calculateStatistics()
 {
     try {
         $collection = Statistics::getInstance()->getCollection();
         $data = $collection->findOne(['account' => $this->getName()]);
         if (!empty($data) && time() - $data['last_update'] < 86400) {
             return;
         }
         $data = ['account' => $this->getName(), 'last_update' => time(), 'wallet' => $this->getStatsWallet(), 'unlocks' => $this->getStatsUnlocks(), 'pvp' => $this->getStatsPvp(), 'race' => $this->getRaceCount(), 'gender' => $this->getGenderCount(), 'profession' => $this->getProfessionCount(), 'generic' => ['characters' => $this->getCharactersCount(), 'age' => $this->getTotalAge(), 'deaths' => $this->getTotalDeaths(), 'level80' => $this->getCharactersLevel80Count()], Item::RARITY_ASCENDED => $this->getAscendedCount(), Item::RARITY_LEGENDARY => $this->getLegendariesCount()];
         $collection->update(['account' => $this->getName()], $data, ['upsert' => true]);
     } catch (\Exception $ex) {
     }
 }
Пример #2
0
 /**
  * 
  * @return string
  */
 public function routeStatisticsJson($code, $dataset)
 {
     try {
         $context = $this->getContext('statistics');
         if ($context) {
             $stats = Statistics::getInstance();
             $stats->setAccount($this->user->getAccount());
             if (preg_match('!^wallet-([0-9]+)$!', $dataset, $m)) {
                 $method = 'getDatasetWallet';
                 if (method_exists($stats, $method)) {
                     $data = $stats->{$method}($m[1]);
                     if (!empty($data)) {
                         $response = new ResponseJson($data);
                     }
                 }
             } else {
                 $method = 'getDataset' . $dataset;
                 if (method_exists($stats, $method)) {
                     $response = new ResponseJson($stats->{$method}());
                 }
             }
             if (isset($response)) {
                 $response->setMaxAge(900);
                 $response->setExpires(new \DateTime('@' . (time() + 900)));
                 $response->setPublic();
                 return $response;
             }
         }
     } catch (\Exception $ex) {
         return new ResponseJson(['error' => $ex->getMessage()]);
     }
 }