Example #1
0
File: Data.php Project: vincium/lot
 public static function getCurrentMatch($id, array $redirect = [])
 {
     $options = [];
     $options['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'], '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_player_match.player_id = ?', $id];
     $options['where'][] = 'match.status IN (1,2,3)';
     $options['order'][] = 'match.scheduled';
     $match = \Own\Bus\Match\Data::load($options);
     if (isset($match)) {
         if (in_array($match->getStatus(), $redirect)) {
             // match ready/playing and in less than half Engine::DAY
             if (in_array($match->getStatus(), [MatchStatus::READY, MatchStatus::PLAYING])) {
                 // cannot play if other match in less than 1/10 Day
                 if ($match->getScheduled() < time() + Engine::DAY * 360) {
                     Util\Session::siteError('matchPlaying', null, '/match/schedule');
                 } else {
                     Util\Session::set('siteSuccess', Util\Lang::lang('nextMatch', [$match->getScheduled()->format()]));
                 }
             }
         }
         return $match;
     } else {
         if (in_array(0, $redirect)) {
             Util\Session::siteError('noMatch', null, '/match');
         }
     }
     return null;
 }
Example #2
0
 public function viewProto()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     $matchId = Util\Converter::toInt('id');
     $options = [];
     $options['where'][] = 'match.id = ' . $matchId;
     $options['where'][] = 'match.status IN (' . MatchStatus::FINISHED . ', ' . MatchStatus::PLAYING . ')';
     $matches = \Own\Bus\Match\Data::loadAll($options);
     if (count($matches) != 1) {
         Util\Session::siteError('matchNotFound', null, '/match/schedule');
     }
     $match = $matches[0];
     $matchLog = \Rebond\Config::getPath('config') . 'match/match_' . $match->getId() . '.json';
     if (!file_exists($matchLog)) {
         Util\Session::siteError('noMatchLog', null, '/match/schedule');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('match', $match);
     $logs = json_decode(file_get_contents($matchLog), true);
     $tplMain->set('logs', $logs);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('match-view-proto'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     $this->tplMaster->addJs('/js/proto.js');
     return $this->tplMaster->render('tpl-default');
 }
Example #3
0
 public function view()
 {
     $id = Converter::toInt('id');
     $playerId = $this->player->getId();
     $tournament = \Own\Bus\Tournament\Data::loadById($id);
     if (!isset($tournament)) {
         Session::siteError('itemNotFound', [$id], '/tournament');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['bus', 'match']);
     $tplMain->set('tournament', $tournament);
     if ($tournament->getStatus() >= TournamentStatus::PLAYING) {
         $orderedMatches = \Own\Bus\Match\Data::loadAllByTournamentId($tournament->getId());
         foreach ($orderedMatches as $match) {
             if ($match->getPlayerMatch1() != null && $match->getPlayerMatch1()->getPlayerId() == $playerId && !$match->getPlayerMatch1()->getHasViewed() || $match->getPlayerMatch2() != null && $match->getPlayerMatch2()->getPlayerId() == $playerId && !$match->getPlayerMatch2()->getHasViewed()) {
                 $position = $match->getPosition();
                 $nextPosition = floor($position / 2);
                 while ($nextPosition >= 1) {
                     if (!isset($orderedMatches[$nextPosition])) {
                         break;
                     }
                     if ($nextPosition == 1) {
                         $orderedMatches[$nextPosition]->setWinnerId(0);
                     }
                     if ($position % 2 == 1) {
                         $orderedMatches[$nextPosition]->setPlayerMatch1Id(0);
                     } else {
                         $orderedMatches[$nextPosition]->setPlayerMatch2Id(0);
                     }
                     $position = $nextPosition;
                     $nextPosition = floor($position / 2);
                 }
             }
         }
         $tplMain->set('items', $orderedMatches);
         $tplMain->set('size', $tournament->getSize() / 2);
         $tplMain->set('round', 1);
         $tplMain->set('playerId', $this->player->getId());
         // layout
         $this->tplLayout->set('column1', $tplMain->render('draw'));
     } else {
         $tplMain->set('players', \Own\Bus\Tournament\Data::getPlayerList($tournament->getId()));
         // layout
         $this->tplLayout->set('column1', $tplMain->render('registration'));
     }
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }