コード例 #1
0
ファイル: Service.php プロジェクト: vincium/lot
 public function player()
 {
     $json = [];
     $json['result'] = \Rebond\Core\ResultType::ERROR;
     $matchView = \Own\Bus\Match\Data::loadRecentByPlayerId($this->player->getId());
     if (isset($matchView)) {
         $json['message'] = Util\Lang::lang('matchView');
         return json_encode($json);
     }
     // check
     $id = Util\Converter::toInt('id', 'post');
     // cache
     $cacheTime = $this->app->site()->getCacheTime();
     $cache = Util\Cache::getCache('profile', $this->signedUser->getId() . '_' . $id, $cacheTime);
     if (isset($cache)) {
         $json['html'] = $cache;
         $json['result'] = \Rebond\Core\ResultType::SUCCESS;
         return json_encode($json);
     }
     $player = \Own\Bus\Player\Data::loadById($id);
     if (!isset($player)) {
         $json['message'] = Util\Lang::lang('playerNotFound');
         return json_encode($json);
     }
     $self = $player->getId() == $this->player->getId();
     $stats = \Own\Bus\Match\Data::loadStatsByPlayerId($player->getId(), $self);
     $options = [];
     $options['where'][] = 'winner_id = ' . $player->getId();
     $titles = \Own\Bus\Tournament\Data::count($options);
     $faceToFace = null;
     if (!$self) {
         $faceToFace = \Own\Bus\Match\Data::loadFaceToFace($this->player->getId(), $player->getId());
     }
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('self', $self);
     $tplMain->set('player', $player);
     $tplMain->set('stats', $stats);
     $tplMain->set('titles', $titles);
     $tplMain->set('faceToFace', $faceToFace);
     $tplMain->set('ajax', true);
     // layout
     $cache = $tplMain->render('profile');
     Util\Cache::saveCache('profile', $this->signedUser->getId() . '_' . $id, $cacheTime, $cache);
     $json['title'] = $player->getUsername();
     $json['html'] = $cache;
     $json['result'] = \Rebond\Core\ResultType::SUCCESS;
     return json_encode($json);
 }