Пример #1
0
 public function buildPlayerMatch2()
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\PlayerMatch\Data::getList(['id', 'player_id']);
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username'], 'player_match_player');
     $options['join'][] = 'bus_player player_match_player ON player_match_player.id = player_match.player_id';
     $items = \Own\Bus\PlayerMatch\Data::loadAll($options);
     return Util\Form::buildDropdownList('player_match2_id' . $this->unique, $items, 'id', 'player', $this->getModel()->getPlayerMatch2Id());
 }
Пример #2
0
 public static function cleanHasViewed()
 {
     $players = Data::loadPlayersWithOldMatches();
     foreach ($players as $player) {
         \Own\Bus\Notification\Service::create($player['player_id'], 0, 'oldMatches', [['oldMatch', $player['total']]]);
     }
     return Data::cleanHasViewed();
 }
Пример #3
0
 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();
 }
Пример #4
0
 public function achievement()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     \Own\Bus\Match\Data::checkMatchToView($this->player->getId());
     $stats = \Own\Bus\PlayerMatch\Data::loadStats($this->player->getId());
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('username', $this->player->getUsername());
     $tplMain->set('stats', $stats);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('profile-achievement'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Пример #5
0
 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;
 }
Пример #6
0
 public function vs()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     $matchId = Util\Converter::toInt('matchId', 'get', 0);
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Match\Data::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'], 'match_player_match');
     $options['join'][] = 'bus_player_match match_player_match';
     $options['where'][] = 'match_player_match.id = match.player_match1_id OR match_player_match.id = match.player_match2_id';
     $options['where'][] = ['match.id = ?', $matchId];
     $options['where'][] = ['match.status IN (?)', [1, 2, 3, 4]];
     $match = \Own\Bus\Match\Data::load($options);
     if (!isset($match)) {
         Util\Session::siteError('noMatch', null, '/match/schedule');
     }
     if (in_array($match->getStatus(), [MatchStatus::PLAYING, MatchStatus::FINISHED])) {
         Util\Session::siteSuccess('matchStarted', '/match/view?id=' . $match->getId() . '&live=true');
     }
     $stats1 = \Own\Bus\Match\Data::loadStatsByPlayerId($this->player->getId());
     $stats2 = \Own\Bus\Match\Data::loadStatsByPlayerId($match->getPlayerMatch2()->getPlayerId(), false);
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('match', $match);
     $tplMain->set('stats1', $stats1);
     $tplMain->set('stats2', $stats2);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('match-vs'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }