Exemple #1
0
 public function ranking()
 {
     $id = Converter::toInt('id', 'get', $this->player->getLeagueId());
     $league = \Own\Bus\League\Data::loadById($id);
     if (!isset($league)) {
         $league = $this->player->getLeague();
     }
     // player not logged in
     if (!isset($league)) {
         Session::redirect('/league');
     }
     // view
     $this->setTpl();
     $cacheTime = $this->app->site()->getCacheTime();
     $cache = \Rebond\Util\Cache::getCache('league-ranking', $league->getId(), $cacheTime);
     if (isset($cache)) {
         // layout
         $this->tplLayout->set('column1', $cache);
     } else {
         $options = [];
         $options['clearSelect'] = true;
         $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'user_id', 'country', 'experience', 'username', 'league_ranking', 'league_point', 'league_diff']);
         $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'avatar_id'], 'player_user');
         $options['select'][] = \Rebond\Core\Media\Data::getList([], 'player_user_avatar');
         $options['leftJoin'][] = 'core_user player_user ON player_user.id = player.user_id';
         $options['leftJoin'][] = 'core_media player_user_avatar ON player_user_avatar.id = player_user.avatar_id';
         $options['where'][] = 'player.active = 1';
         $options['where'][] = 'player.league_id = ' . $league->getId();
         $options['order'][] = 'player.league_ranking, player.created_date';
         $players = \Own\Bus\Player\Data::loadAll($options);
         // main
         $tplMain = new Template(Template::SITE, ['www']);
         $tplMain->set('league', $league);
         $tplMain->set('player', $this->player);
         $tplMain->set('players', $players);
         // layout
         $cache = $tplMain->render('league-ranking');
         $this->tplLayout->set('column1', $cache);
         // cache
         \Rebond\Util\Cache::saveCache('league-ranking', $league->getId(), $cacheTime, $cache);
     }
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Exemple #2
0
 public function players_add()
 {
     Util\Auth::isAdminAuthorized($this->signedUser, null, false, '/');
     $start = Util\Converter::toInt('start', 'get', 0);
     $batch = 100;
     $today = new Util\DateTime();
     $message = [];
     $players = \Own\Bus\Player\Data::count();
     if ($players != $batch * $start + 2) {
         $message[] = 'Players already added (' . $players . ')';
     } else {
         $message[] = $this->addPlayers($this->getPlayers(), $start, $batch);
     }
     // main
     $tpl = new Util\Template(Util\Template::SITE, ['admin']);
     $tpl->set('today', $today->format('Y-m-d'));
     $tpl->set('message', implode($message, '<br>'));
     return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'integration'], 'layout-1-col', ['column1' => $tpl->render('integration')]);
 }
Exemple #3
0
 public function detail()
 {
     if (!$this->app->isDebug()) {
         return self::generic();
     }
     $logId = Util\Converter::toInt('id');
     if ($logId == 0) {
         return self::generic();
     }
     $log = \Rebond\Core\Log\Data::loadById($logId);
     if (!isset($log)) {
         return self::generic();
     }
     $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
     // main
     $tpl = new Util\Template(Util\Template::MODULE, ['app', 'error']);
     $tpl->set('log', $log);
     $tpl->set('referer', $referer);
     $tpl->set('adminUrl', \Rebond\Config::getPath('adminUrl'));
     return $tpl->render('detail');
 }
Exemple #4
0
 public function tour_points()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     \Own\Bus\Match\Data::checkMatchToView($this->player->getId());
     $race = Util\Converter::toBool('race', 'get', true);
     // params
     $id = Util\Converter::toInt('id');
     if ($id == 0) {
         $player = $this->player;
     } else {
         $player = \Own\Bus\Player\Data::loadById($id);
         if (!isset($player)) {
             $player = $this->player;
         }
     }
     if ($race) {
         $options = [];
         $options['join'][] = 'bus_tournament tournament ON tournament.id = tournament_player.tournament_id';
         $options['where'][] = 'tournament.status = ' . TournamentStatus::FINISHED;
         $options['where'][] = 'tournament.start_date > \'' . Engine::getStartYearDate($this->app->site()->getCreatedDate()) . '\'';
         $options['order'][] = 'points DESC';
         $tournaments = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($player->getId(), $options);
         $oldTournaments = null;
     } else {
         $options = [];
         $options['join'][] = 'bus_tournament tournament ON tournament.id = tournament_player.tournament_id';
         $options['where'][] = 'tournament.status = ' . TournamentStatus::FINISHED;
         $options['where'][] = 'tournament.start_date > NOW() - INTERVAL ' . Engine::DAY * 336 . ' HOUR';
         $options['order'][] = 'points DESC';
         $tournaments = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($player->getId(), $options);
         $options = [];
         $options['join'][] = 'bus_tournament tournament ON tournament.id = tournament_player.tournament_id';
         $options['where'][] = 'tournament.status = ' . TournamentStatus::FINISHED;
         $options['where'][] = 'tournament.start_date < NOW() - INTERVAL ' . Engine::DAY * 336 . ' HOUR';
         $options['order'][] = 'tournament.start_date DESC';
         $oldTournaments = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($player->getId(), $options);
     }
     // view
     $this->setTpl();
     // filter
     $tplFilter = new Util\Template(Util\Template::SITE, ['www']);
     $tplFilter->set('race', $race);
     $tplFilter->set('playerId', $player->getId());
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('username', $player->getUsername());
     $tplMain->set('tournaments', $tournaments);
     $tplMain->set('oldTournaments', $oldTournaments);
     // layout
     $this->tplLayout->set('column1', $tplFilter->render('profile-tour-point-filter'));
     $this->tplLayout->add('column1', $tplMain->render('profile-tour-point'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Exemple #5
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');
 }
Exemple #6
0
 public function membership()
 {
     Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/');
     $this->setTpl();
     $membershipId = Util\Converter::toInt('id');
     if (!isset($membershipId)) {
         Util\Session::adminError('item.not.found', [Util\Lang::lang('membership'), $membershipId], '/own/memberships');
     }
     $membership = \Own\Bus\Membership\Data::loadById($membershipId, true);
     $membershipForm = new \Own\Bus\Membership\Form($membership);
     // action
     $save = Util\Converter::toString('save', 'post');
     $courtIds = Util\Converter::toArray('court', 'post');
     if (isset($save)) {
         if ($membershipForm->setFromPost()->validate()->isValid()) {
             \Own\Bus\MembershipCourt\Data::deleteByMembershipId($membership->getId());
             $newCourts = [];
             if (isset($courtIds)) {
                 foreach ($courtIds as $courtId) {
                     $membershipCourt = new \Own\Bus\MembershipCourt\Model();
                     $membershipCourt->setMembershipId($membership->getId());
                     $membershipCourt->setCourtId($courtId);
                     $newCourts[] = $membershipCourt;
                 }
             }
             \Own\Bus\MembershipCourt\Data::saveAll($newCourts);
             $membership->save();
             Util\Session::adminSuccess('saved', '/own/memberships');
         } else {
             Util\Session::set('adminError', $membershipForm->getValidation()->getMessage());
         }
     }
     $tplEditor = new Util\Template(Util\Template::SITE, ['admin']);
     $tplEditor->set('item', $membershipForm);
     return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-1-col', ['column1' => $tplEditor->render('membership-editor')]);
 }
Exemple #7
0
 public function adminBooking()
 {
     $isAllowed = Util\Auth::isAdminAuthorized($this->signedUser);
     $json = [];
     $json['result'] = \Rebond\Core\ResultType::ERROR;
     if (!$isAllowed) {
         $json['message'] = Util\Lang::lang('accessNonAuthorized');
         return json_encode($json);
     }
     $title = Util\Converter::toString('title', 'post');
     $color = Util\Converter::toString('color', 'post');
     $courtIds = Util\Converter::toArray('courtIds', 'post');
     $startDate = Util\Converter::toDate('startDate', 'post', new \DateTime());
     $endDate = Util\Converter::toDate('endDate', 'post', new \DateTime());
     $days = Util\Converter::toArray('days', 'post');
     $startTime = Util\Converter::toInt('startTime', 'post');
     $endTime = Util\Converter::toInt('endTime', 'post');
     $count = 0;
     // @todo validate param
     $json['startDate'] = $startDate->format('datetime');
     $json['endDate'] = $endDate->format('datetime');
     $options = [];
     $options['where'][] = ['id IN (?)', $courtIds];
     $courts = \Own\Bus\Court\Data::loadAll($options);
     $book = new Book\Model();
     $book->setType(\Own\Bus\BookingType::ADMIN);
     $book->setTitle($title);
     $book->setSequence(uniqid());
     $book->setColor($color);
     $dateLoop = clone $startDate;
     $today = new \DateTime();
     $now = (int) $today->format('H') * 60 + (int) $today->format('i');
     $today->setTime(0, 0, 0);
     $rule = \Own\Bus\Rule\Data::loadById(1, true);
     $timeLength = $rule->getTimeLength();
     foreach ($courts as $court) {
         $book->setCourtId($court->getId());
         while ($dateLoop <= $endDate) {
             if ($dateLoop < $today) {
                 $dateLoop->add(new \DateInterval('P1D'));
                 continue;
             }
             if (!in_array($dateLoop->format('w'), $days)) {
                 $dateLoop->add(new \DateInterval('P1D'));
                 continue;
             }
             $possibleTime = (int) $court->getStartTime()->format('H') * 60 + (int) $court->getStartTime()->format('i');
             $limitTime = (int) $court->getEndTime()->format('H') * 60 + (int) $court->getEndTime()->format('i');
             while ($possibleTime < min($limitTime, $endTime)) {
                 if ($possibleTime >= $startTime && ($dateLoop != $today || $possibleTime >= $now)) {
                     $dateLoop->setTime(floor($possibleTime / 60), $possibleTime % 60, 0);
                     // check for court already booked
                     $options = [];
                     $options['where'][] = ['court_id = ?', $court->getId()];
                     $options['where'][] = ['booking_date = ?', $dateLoop->format('Y-m-d H:i:00')];
                     $booking = Book\Data::load($options);
                     if (!isset($booking)) {
                         $book->setBookingDate($dateLoop);
                         $book->save();
                         $book->setId(0);
                         $count++;
                     }
                 }
                 $dateLoop->setTime(0, 0, 0);
                 $possibleTime += $timeLength;
             }
             $dateLoop->add(new \DateInterval('P1D'));
         }
         $dateLoop = clone $startDate;
     }
     $json['result'] = \Rebond\Core\ResultType::SUCCESS;
     $json['count'] = $count;
     return json_encode($json);
 }
Exemple #8
0
 public function matchLog()
 {
     $json = [];
     $json['result'] = \Rebond\Core\ResultType::ERROR;
     // check
     $matchId = Util\Converter::toInt('matchId', 'post');
     $debug = Util\Converter::toBool('debug', 'post', false);
     $options = [];
     $options['where'][] = ['match_id = ?', $matchId];
     $options['order'][] = 'id';
     $matchLog = \Own\Bus\Log\Data::loadAll($options);
     if (count($matchLog) == 0) {
         $json['message'] = Util\Lang::lang('noMatchLog');
         return json_encode($json);
     }
     $logs = [];
     foreach ($matchLog as $log) {
         $logs[] = $log->toArray();
     }
     $htmlLog = '';
     if (count($logs) > 0) {
         $htmlLog .= '<table class="list">';
         foreach ($logs as $log) {
             $htmlLog .= '<tr>';
             $htmlLog .= '<td class="score">' . \Own\Bus\Engine::renderScore($log['game'], $log['point1'], $log['point2']) . '</td>';
             $htmlLog .= '<td>' . \Own\Bus\Engine::renderDescription($log['description'], $debug);
             $htmlLog .= '<strong>' . Util\Lang::lang($log['result']) . '</strong></td>';
             $htmlLog .= '</tr>';
         }
         $htmlLog .= '</table>';
     }
     // layout
     $json['result'] = \Rebond\Core\ResultType::SUCCESS;
     $json['html'] = $htmlLog;
     return json_encode($json);
 }
Exemple #9
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');
 }