コード例 #1
0
ファイル: Profile.php プロジェクト: vincium/lot
 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
ファイル: Cron.php プロジェクト: vincium/lot
 public function match()
 {
     $options = [];
     $options['select'][] = \Own\Bus\Tournament\Data::getList([], 'match_tournament');
     $options['select'][] = \Own\Bus\PlayerMatch\Data::getList([], 'match_player_match1');
     $options['select'][] = \Own\Bus\PlayerMatch\Data::getList([], 'match_player_match2');
     $options['leftJoin'][] = 'bus_tournament match_tournament ON match_tournament.id = match.tournament_id';
     $options['join'][] = 'bus_player_match match_player_match1 ON match_player_match1.id = match.player_match1_id';
     $options['join'][] = 'bus_player_match match_player_match2 ON match_player_match2.id = match.player_match2_id';
     $options['join'][] = 'bus_player match_player_match1_player ON match_player_match1_player.id = match_player_match1.player_id';
     $options['join'][] = 'bus_player match_player_match2_player ON match_player_match2_player.id = match_player_match2.player_id';
     $options['where'][] = '(match.status IN (1,2) AND match.scheduled < NOW()) OR (match.status = 3)';
     $matches = \Own\Bus\Match\Data::loadAll($options);
     $playing = 0;
     $done = 0;
     if (count($matches > 0)) {
         foreach ($matches as $match) {
             $matchService = new \Own\Bus\Match\Service($this->app, $match);
             $winnerId = $match->findWinnerId();
             if ($match->getStatus() == MatchStatus::READY) {
                 $matchService->preMatch();
             }
             $match->setStatus(MatchStatus::PLAYING);
             $match->save();
             // play point
             $firstPoint = true;
             while ($winnerId == 0) {
                 if (!$firstPoint && $match->isTurnOver()) {
                     $match->getPlayerMatch1()->save();
                     $match->getPlayerMatch2()->save();
                     $match->save();
                     $playing++;
                     continue 2;
                 }
                 if ($firstPoint) {
                     $firstPoint = false;
                 }
                 $matchService->playPoint();
                 $winnerId = $match->findWinnerId();
                 if (!$this->cron && $this->app->timer() > 25) {
                     $match->getPlayerMatch1()->save();
                     $match->getPlayerMatch2()->save();
                     $match->save();
                     break 2;
                 }
             }
             // close match
             if ($match->getPlayerMatch1()->getPlayer()->getUserId() == 0) {
                 $match->getPlayerMatch1()->setHasViewed(true);
             }
             if ($match->getPlayerMatch2()->getPlayer()->getUserId() == 0) {
                 $match->getPlayerMatch2()->setHasViewed(true);
             }
             $match->setStatus(MatchStatus::FINISHED);
             $matchService->endMatch();
             $match->save();
             if ($match->getLeagueId() != 0) {
                 $this->leagueIds[] = $match->getLeagueId();
             }
             $this->matchPlayerIds[] = $match->getPlayerMatch1()->getPlayerId();
             $this->matchPlayerIds[] = $match->getPlayerMatch2()->getPlayerId();
             $isWinner = $winnerId == $match->getPlayerMatch1Id();
             // update form, experience, surface, energy, league points
             $result1 = $match->getPlayerMatch1()->getPlayer()->updateAfterMatch($isWinner, $match->getId(), $match->renderScore(true), $match->getGamesCount(), $match->getSurface(), $match->getType(), $match->getPosition(), $match->getPlayerMatch2()->getPlayer());
             $result2 = $match->getPlayerMatch2()->getPlayer()->updateAfterMatch(!$isWinner, $match->getId(), $match->renderScore(true), $match->getGamesCount(), $match->getSurface(), $match->getType(), $match->getPosition(), $match->getPlayerMatch1()->getPlayer());
             $match->getPlayerMatch1()->save();
             $match->getPlayerMatch2()->save();
             $match->getPlayerMatch1()->getPlayer()->save();
             $match->getPlayerMatch2()->getPlayer()->save();
             // if player changes league
             if ($match->getLeagueId() != 0) {
                 $this->leagueIds[] = $match->getPlayerMatch1()->getPlayer()->getLeagueId();
                 $this->leagueIds[] = $match->getPlayerMatch2()->getPlayer()->getLeagueId();
             }
             // create next match
             if ($match->getPosition() > 1) {
                 $matchTime = $match->getScheduled()->getTimestamp() + Engine::DAY * 3600;
                 $position = floor($match->getPosition() / 2);
                 $options = [];
                 $options['where'][] = ['match.tournament_id = ?', $match->getTournamentId()];
                 $options['where'][] = ['match.position = ?', $position];
                 $nextMatch = \Own\Bus\Match\Data::load($options);
                 if (!isset($nextMatch)) {
                     $nextMatch = new \Own\Bus\Match\Model();
                     $nextMatch->setTournamentId($match->getTournamentId());
                     $nextMatch->setSurface($match->getTournament()->getSurface());
                     $nextMatch->setPosition($position);
                     $nextMatch->setBestOfSets($match->getTournament()->getBestOfSets());
                     $nextMatch->setType(MatchType::TOURNAMENT);
                 }
                 $playerMatch = new \Own\Bus\PlayerMatch\Model();
                 if ($isWinner) {
                     $playerMatch->setPlayerId($match->getPlayerMatch1()->getPlayerId());
                     $playerMatch->setLevel($match->getPlayerMatch1()->getPlayer()->calculateLevel());
                     if ($match->getPlayerMatch1()->getPlayer()->getUserId() != 0) {
                         \Own\Bus\Notification\Service::create($match->getPlayerMatch1()->getPlayerId(), 0, 'matchStart', [['scheduledMatch', $matchTime]]);
                     }
                 } else {
                     $playerMatch->setPlayerId($match->getPlayerMatch2()->getPlayerId());
                     $playerMatch->setLevel($match->getPlayerMatch2()->getPlayer()->calculateLevel());
                     if ($match->getPlayerMatch2()->getPlayer()->getUserId() != 0) {
                         \Own\Bus\Notification\Service::create($match->getPlayerMatch2()->getPlayerId(), 0, 'matchStart', [['scheduledMatch', $matchTime]]);
                     }
                 }
                 $playerMatch->save();
                 if ($match->getPosition() % 2 == 0) {
                     $nextMatch->setPlayerMatch2Id($playerMatch->getId());
                 } else {
                     $nextMatch->setPlayerMatch1Id($playerMatch->getId());
                 }
                 $nextMatch->setScheduled(date('Y-m-d H:i:s', $matchTime));
                 $nextMatch->setStatus(MatchStatus::READY);
                 $nextMatch->save();
                 \Own\Bus\Player\Data::updateIsInMatch($playerMatch->getPlayerId());
             } else {
                 if ($match->getPosition() == 1) {
                     $match->getTournament()->setWinnerId($match->getWinner()->getPlayerId());
                     $match->getTournament()->setStatus(TournamentStatus::FINISHING);
                     $match->getTournament()->save();
                 }
             }
             $done++;
         }
     }
     $this->log('match: ' . $playing . ' + ' . $done . ' / ' . count($matches));
     $this->playerAfter();
     $this->rankingLeague();
 }
コード例 #3
0
ファイル: Service.php プロジェクト: vincium/lot
 public function sign()
 {
     $isAllowed = Util\Auth::isAuthorized($this->signedUser, 'member');
     $json = [];
     $json['result'] = \Rebond\Core\ResultType::ERROR;
     if (!$isAllowed) {
         $json['message'] = Util\Lang::lang('accessNonAuthorized');
         return json_encode($json);
     }
     $tournamentId = Util\Converter::toInt('tournamentId', 'post');
     $action = Util\Converter::toString('action', 'post');
     if ($tournamentId == 0 || !in_array($action, ['up', 'out'])) {
         $json['message'] = 'Invalid options';
         return json_encode($json);
     }
     $tournament = \Own\Bus\Tournament\Data::loadById($tournamentId);
     $playerId = $this->player->getId();
     if ($tournament->getClassification() == Classification::AMATEUR && $this->player->getTourPoint() >= 10) {
         $json['message'] = Util\Lang::lang('tooManyPointsForAmateur');
         return json_encode($json);
     }
     if ($tournament->getClassification() != Classification::AMATEUR && $this->player->getTourPoint() < 10) {
         $json['message'] = Util\Lang::lang('notEnoughPointForTournament');
         return json_encode($json);
     }
     if ($tournament->getClassification() <= Classification::ATP_250 && $this->player->getTourPoint() <= 100) {
         $json['message'] = Util\Lang::lang('needMorePointsForATP');
         return json_encode($json);
     }
     $options = [];
     $options['where'][] = 'tournament_player.tournament_id = ' . $tournamentId;
     $tp = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($playerId, $options);
     if ($action == 'up') {
         if (count($tp) > 0) {
             $json['message'] = Util\Lang::lang('alreadySignedUp');
             return json_encode($json);
         }
         if ($this->player->getIsInTournament() || $this->player->getIsRegistered()) {
             $json['message'] = Util\Lang::lang('alreadySignedUpInOtherTournament');
             return json_encode($json);
         }
         $tp = new \Own\Bus\TournamentPlayer\Model();
         $tp->setTournamentId($tournamentId);
         $tp->setPlayerId($playerId);
         $tp->save();
         $this->player->setIsRegistered(true);
         $this->player->save();
         $json['result'] = \Rebond\Core\ResultType::SUCCESS;
         $json['message'] = Util\Lang::lang('signedUp') . '!';
         $json['newAction'] = 'out';
         $json['html'] = Util\Lang::lang('signOut');
         return json_encode($json);
     }
     if ($action == 'out') {
         if (count($tp) == 0) {
             $json['message'] = Util\Lang::lang('notRegistered');
             return json_encode($json);
         }
         \Own\Bus\TournamentPlayer\Data::deleteById($tp[0]->getId());
         $this->player->setIsRegistered(false);
         $this->player->save();
         $json['result'] = \Rebond\Core\ResultType::SUCCESS;
         $json['message'] = Util\Lang::lang('signedOut') . '!';
         $json['newAction'] = 'up';
         $json['html'] = Util\Lang::lang('signUp');
         return json_encode($json);
     }
     $json['message'] = 'nothing to do';
     return json_encode($json);
 }
コード例 #4
0
ファイル: Data.php プロジェクト: vincium/lot
 private static function link($linkTournament = false, $linkLeague = false, $players = false, $needBothPlayers = true)
 {
     $join = 'join';
     if (!$needBothPlayers) {
         $join = 'leftJoin';
     }
     $option = [];
     $option['clearSelect'] = true;
     $options['select'][] = self::getList(['id', 'player_match1_id', 'player_match2_id', 'surface', 'current_set', 'best_of_sets', 'type', 'winner_id', 'position', 'tournament_id', 'league_id', 'status', 'scheduled']);
     $options['select'][] = \Own\Bus\PlayerMatch\Data::getList(['id', 'player_id', 'seed', 'has_viewed', 'set1', 'set2', 'set3', 'set4', 'set5', 'points', 'level'], 'match_player_match1');
     $options['select'][] = \Own\Bus\PlayerMatch\Data::getList(['id', 'player_id', 'seed', 'has_viewed', 'set1', 'set2', 'set3', 'set4', 'set5', 'points', 'level'], 'match_player_match2');
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username', 'user_id', 'country', 'experience'], 'match_player_match1_player');
     if ($players) {
         $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'avatar_id'], 'match_player_match1_player_user');
         $options['select'][] = \Rebond\Core\Media\Data::getList([], 'match_player_match1_player_user_avatar');
     }
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username', 'user_id', 'country', 'experience'], 'match_player_match2_player');
     if ($players) {
         $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'avatar_id'], 'match_player_match2_player_user');
         $options['select'][] = \Rebond\Core\Media\Data::getList([], 'match_player_match2_player_user_avatar');
     }
     if ($linkTournament) {
         $options['select'][] = \Own\Bus\Tournament\Data::getList(['id', 'title', 'size', 'classification'], 'match_tournament');
     }
     if ($linkLeague) {
         $options['select'][] = \Own\Bus\League\Data::getList(['id', 'title'], 'match_league');
     }
     $options[$join][] = 'bus_player_match match_player_match1 ON match_player_match1.id = match.player_match1_id';
     $options[$join][] = 'bus_player_match match_player_match2 ON match_player_match2.id = match.player_match2_id';
     $options[$join][] = 'bus_player match_player_match1_player ON match_player_match1_player.id = match_player_match1.player_id';
     if ($players) {
         $options['leftJoin'][] = 'core_user match_player_match1_player_user ON match_player_match1_player_user.id = match_player_match1_player.user_id';
         $options['leftJoin'][] = 'core_media match_player_match1_player_user_avatar ON match_player_match1_player_user_avatar.id = match_player_match1_player_user.avatar_id';
     }
     $options[$join][] = 'bus_player match_player_match2_player ON match_player_match2_player.id = match_player_match2.player_id';
     if ($players) {
         $options['leftJoin'][] = 'core_user match_player_match2_player_user ON match_player_match2_player_user.id = match_player_match2_player.user_id';
         $options['leftJoin'][] = 'core_media match_player_match2_player_user_avatar ON match_player_match2_player_user_avatar.id = match_player_match2_player_user.avatar_id';
     }
     if ($linkTournament) {
         $options['leftJoin'][] = 'bus_tournament match_tournament ON match_tournament.id = match.tournament_id';
     }
     if ($linkLeague) {
         $options['leftJoin'][] = 'bus_league match_league ON match_league.id = match.league_id';
     }
     return $options;
 }
コード例 #5
0
ファイル: Tournament.php プロジェクト: vincium/lot
 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');
 }