Пример #1
0
 public function index()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     \Own\Bus\Match\Data::checkMatchToView($this->player->getId());
     $stats = \Own\Bus\Match\Data::loadStatsByPlayerId($this->player->getId());
     $options = [];
     $options['where'][] = 'winner_id = ' . $this->player->getId();
     $titles = \Own\Bus\Tournament\Data::count($options);
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('self', true);
     $tplMain->set('player', $this->player);
     $tplMain->set('stats', $stats);
     $tplMain->set('titles', $titles);
     $tplMain->set('ajax', false);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('profile'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Пример #2
0
 public function tournament()
 {
     $created = 0;
     $options = [];
     $options['where'][] = ['tournament.start_date BETWEEN NOW() + INTERVAL ? HOUR AND NOW() + INTERVAL ? HOUR', Engine::DAY * 4, Engine::DAY * 6];
     $options['where'][] = ['tournament.status != ?', TournamentStatus::CANCELED];
     $count = \Own\Bus\Tournament\Data::count($options);
     if ($count == 0) {
         $tournament = new \Own\Bus\Tournament\Model();
         $tournament->setTitle(Engine::generateName());
         $tournament->setBestOfSets(3);
         $tournament->setSurface(Engine::selectSurface());
         $classification = round(pow(Engine::dice(1, 42), 0.5)) + 2;
         $tournament->setClassification($classification);
         $tournament->setSize(32);
         if ($classification == Classification::AMATEUR) {
             $tournament->setSize(16);
         } else {
             if ($classification == Classification::ATP_1000) {
                 $tournament->setSize(64);
             }
         }
         $startDate = ceil(time() / 3600) * 3600 + Engine::DAY * 3600 * 5;
         $tournament->setStartDate((new Util\DateTime())->setTimestamp($startDate));
         $tournament->setEndDate(Engine::findTournamentEndDate($tournament->getStartDate(), $tournament->getSize()));
         $tournament->save();
         $created = 1;
     }
     $this->log('tournament (creation): ' . $created);
     $done = 0;
     $options = [];
     $options['where'][] = 'tournament.start_date < NOW()';
     $options['where'][] = ['tournament.status = ?', TournamentStatus::NOT_STARTED];
     $tournaments = \Own\Bus\Tournament\Data::loadAll($options);
     foreach ($tournaments as $tournament) {
         if (\Own\Bus\Tournament\Service::fillCPU($tournament)) {
             $tournament->setStatus(TournamentStatus::PREPARATION);
             $done++;
         } else {
             $tournament->setStatus(TournamentStatus::CANCELED);
         }
         $tournament->save();
         \Own\Bus\Tournament\Data::updateIsRegisteredPlayers($tournament);
     }
     $this->log('tournament (fill): ' . $done . ' / ' . count($tournaments));
     $done = 0;
     $options = [];
     $options['where'][] = 'tournament.start_date < NOW()';
     $options['where'][] = ['tournament.status = ?', TournamentStatus::PREPARATION];
     $tournaments = \Own\Bus\Tournament\Data::loadAll($options);
     foreach ($tournaments as $tournament) {
         if (\Own\Bus\Tournament\Service::generate($tournament)) {
             $tournament->setStatus(TournamentStatus::PLAYING);
             \Own\Bus\Tournament\Data::updateIsInMatchPlayers($tournament);
             $done++;
         } else {
             $tournament->setStatus(TournamentStatus::CANCELED);
         }
         $tournament->save();
     }
     $this->log('tournament (draw creation): ' . $done . ' / ' . count($tournaments));
     $options = [];
     $options['where'][] = ['tournament.status = ?', TournamentStatus::FINISHING];
     $tournaments = \Own\Bus\Tournament\Data::loadAll($options);
     foreach ($tournaments as $tournament) {
         $matches = \Own\Bus\Match\Data::loadAllByTournamentId($tournament->getId());
         $tournamentPlayers = \Own\Bus\TournamentPlayer\Data::loadAllByTournamentId($tournament->getId());
         $points = pow(2, 11 - $tournament->getClassification());
         for ($p = 1; $p < $tournament->getSize(); $p++) {
             if (in_array($p, [2, 4, 8, 16, 32, 64])) {
                 $points = floor($points / 2);
             }
             if (!in_array($matches[$p]->getWinner()->getPlayerId(), $this->tourPlayerIds)) {
                 foreach ($tournamentPlayers as $tournamentPlayer) {
                     if ($tournamentPlayer->getPlayerId() == $matches[$p]->getWinner()->getPlayerId()) {
                         if ($matches[$p]->getWinner()->getPlayer()->getUserId() != 0) {
                             \Own\Bus\Notification\Service::create($tournamentPlayer->getPlayerId(), 0, 'tourPoint', [['tourPoint', $points]]);
                         }
                         $tournamentPlayer->setPoints($points);
                         $tournamentPlayer->save();
                         $this->tourPlayerIds[] = $tournamentPlayer->getPlayerId();
                         break;
                     }
                 }
             }
         }
         $tournament->setStatus(TournamentStatus::FINISHED);
         $tournament->save();
     }
     $this->rankingTour();
     $this->log('tournament (point attribution): ' . count($tournaments));
 }
Пример #3
0
 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);
 }
Пример #4
0
 public function past()
 {
     $page = Converter::toInt('page', 'get', 1);
     $options = [];
     $options['where'][] = 'tournament.status IN (3,4)';
     $options['where'][] = 'tournament.start_date < NOW()';
     $count = \Own\Bus\Tournament\Data::count($options);
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Tournament\Data::getList(['id', 'title', 'size', 'classification', 'start_date', 'end_date', 'surface', 'winner_id']);
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username', 'user_id', 'country', 'experience'], 'tournament_winner');
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'avatar_id'], 'tournament_winner_user');
     $options['select'][] = \Rebond\Core\Media\Data::getList([], 'tournament_winner_user_avatar');
     $options['join'][] = 'bus_player tournament_winner ON tournament_winner.id = tournament.winner_id';
     $options['leftJoin'][] = 'core_user tournament_winner_user ON tournament_winner_user.id = tournament_winner.user_id';
     $options['leftJoin'][] = 'core_media tournament_winner_user_avatar ON tournament_winner_user_avatar.id = tournament_winner_user.avatar_id';
     $options['order'][] = 'tournament.start_date DESC';
     $options['limit'][] = ($page - 1) * 20 . ', 20';
     $past = \Own\Bus\Tournament\Data::loadAll($options);
     $registeredIds = \Own\Bus\TournamentPlayer\Data::loadRegistered($this->player->getId());
     // view
     $this->setTpl();
     // filter
     $tplFilter = new Template(Template::SITE, ['www']);
     $tplFilter->set('current', $page);
     $tplFilter->set('count', $count);
     $tplFilter->set('url', '/tournament/past?page=');
     // main
     $tplMain = new Template(Template::SITE, ['www']);
     $tplMain->set('past', $past);
     $tplMain->set('registeredIds', $registeredIds);
     // layout
     $this->tplLayout->set('column1', $tplFilter->render('tour-past-filter'));
     $this->tplLayout->add('column1', $tplMain->render('tour-past'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }