Example #1
0
File: Own.php Project: vincium/resa
 public function index()
 {
     Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/');
     $page = Util\Converter::toInt('page', 'get', 1);
     // get user settings
     $userSettings = $this->signedUser->getUserSettings();
     $maxByPage = isset($userSettings) ? (int) $userSettings->getPagingValue() : 10;
     $countItems = \Own\Bus\Player\Data::count();
     $page = Util\Nav::getCurrentPage($page, $countItems, $maxByPage);
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'credits', 'level']);
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'firstname', 'lastname', 'status'], 'player_id');
     $options['join'][] = 'core_user player_id ON player_id.id = player.id';
     $options['order'][] = 'player_id.username';
     $options['limit'][] = ($page - 1) * $maxByPage . ', ' . $maxByPage;
     $items = \Own\Bus\Player\Data::loadAll($options);
     // main
     $tplFilter = new Util\Template(Util\Template::SITE, ['admin']);
     $tplFilter->set('paging', Util\Nav::renderPaging($countItems, '/own/index?page=', $maxByPage, $page));
     $tplFilter->set('itemsPerPage', Util\Nav::renderItemsPerPage($maxByPage));
     $tplPlayer = new Util\Template(Util\Template::SITE, ['admin']);
     $tplPlayer->set('items', $items);
     return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-1-col', ['column1' => [$tplFilter->render('players-filter'), $tplPlayer->render('players')]]);
 }
Example #2
0
File: Mail.php Project: vincium/lot
 public static function send($playerId, $notification)
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'user_id', 'username']);
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'email'], 'player_user');
     $options['join'][] = 'core_user player_user ON player_user.id = player.user_id';
     $options['where'][] = 'send_notification_email = 1';
     $options['where'][] = ['player.id = ?', $playerId];
     $player = \Own\Bus\Player\Data::load($options);
     if (!isset($player)) {
         return false;
     }
     // send email
     $app = \Rebond\App::instance();
     $tpl = new Util\Template(Util\Template::MODULE, ['bus', 'notification']);
     $tpl->set('url', 'http://' . \Rebond\Config::getPath('siteUrl'));
     $tpl->set('player', $player);
     $tpl->set('notification', $notification);
     $tplMail = new Util\Template(Util\Template::SITE, ['mail']);
     $tplMail->set('title', Util\Lang::lang('notification'));
     $tplMail->set('site', $app->site()->getTitle());
     $tplMail->set('url', 'http://' . \Rebond\Config::getPath('siteUrl'));
     $tplMail->set('layout', $tpl->render('notification'));
     $message = \Swift_Message::newInstance()->setContentType('text/html')->setSubject($app->site()->getTitle() . ' - ' . Util\Lang::lang('notification'))->setFrom(\Rebond\Config::getMail('email'))->setTo($player->getUser()->getEmail())->setBody($tplMail->render('tpl-default'));
     return Util\Mail::send($message);
 }
Example #3
0
 public function loadOwnBookings()
 {
     $isAllowed = Util\Auth::isAuthorized($this->signedUser, 'member', false);
     $json = [];
     $json['result'] = \Rebond\Core\ResultType::ERROR;
     if (!$isAllowed) {
         $json['message'] = Util\Lang::lang('accessNonAuthorized');
         return json_encode($json);
     }
     $weekAgo = new \DateTime();
     $weekAgo = $weekAgo->sub(new \DateInterval('P7D'));
     $weekAgo = $weekAgo->format('Y-m-d');
     $options = [];
     $options['select'][] = \Own\Bus\Player\Data::getList(['id'], 'book_player1');
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'username', 'firstname', 'lastname'], 'book_player1_id');
     $options['select'][] = \Own\Bus\Player\Data::getList(['id'], 'book_player2');
     $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'username', 'firstname', 'lastname'], 'book_player2_id');
     $options['join'][] = 'bus_player book_player1 ON book_player1.id = book.player1_id';
     $options['join'][] = 'core_user book_player1_id ON book_player1_id.id = book_player1.id';
     $options['join'][] = 'bus_player book_player2 ON book_player2.id = book.player2_id';
     $options['join'][] = 'core_user book_player2_id ON book_player2_id.id = book_player2.id';
     $options['where'][] = ['player1_id = ? OR player2_id = ?', $this->player->getId(), $this->player->getId()];
     $options['where'][] = ['booking_date > ?', $weekAgo];
     $options['limit'][] = 5;
     $options['order'][] = 'booking_date';
     $ownBookings = Book\Data::loadAll($options);
     $tplBook = new Util\Template(Util\Template::MODULE, ['bus', 'book']);
     $tplBook->set('items', $ownBookings);
     $tplBook->set('playerId', $this->player->getId());
     $json['html'] = $tplBook->render('own-bookings');
     $json['result'] = \Rebond\Core\ResultType::SUCCESS;
     return json_encode($json);
 }
Example #4
0
File: Form.php Project: vincium/lot
 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());
 }
Example #5
0
File: Data.php Project: vincium/lot
 public static function getPlayerList($tournamentId)
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username', 'user_id', 'country', 'experience', 'tour_ranking']);
     $options['join'][] = 'bus_tournament_player tp ON tp.player_id = player.id';
     $options['where'][] = 'tp.tournament_id = ' . $tournamentId;
     $options['order'][] = 'player.tour_ranking';
     return \Own\Bus\Player\Data::loadAll($options);
 }
Example #6
0
 public static function fillCPU($tournament)
 {
     $need = $tournament->getSize() - count($tournament->getTournamentPlayers());
     $db = new Util\Data();
     if ($need > 0) {
         $sqlBusyPlayer = 'SELECT DISTINCT tp.player_id
             FROM bus_tournament_player tp
             JOIN bus_tournament t ON t.id = tp.tournament_id
             WHERE t.status < 3';
         $rows = $db->select($sqlBusyPlayer);
         $busyPlayers = [0];
         if (count($rows) > 0) {
             $list = $rows->fetchAll(\PDO::FETCH_COLUMN);
             foreach ($list as $key => $value) {
                 $busyPlayers[] = $value;
             }
         }
         $sql = 'SELECT DISTINCT p.id
             FROM bus_player p
             LEFT JOIN bus_tournament_player tp ON tp.player_id = p.id
             WHERE p.active = 1
             AND p.user_id = 0
             AND (tp.player_id IS NULL OR tp.player_id NOT IN (?))
             ORDER BY p.tour_ranking';
         $players = $db->select($sql, [implode(',', $busyPlayers)]);
         if (count($players) == 0) {
             Util\Log::log(Util\Code::CRON, 'Not enough CPU, tournamentId: ' . $tournament->getId() . ', 0 / ' . $need, __FILE__, __LINE__);
             return false;
         }
         $players = $players->fetchAll(\PDO::FETCH_ASSOC);
         if (count($players) < $need) {
             Util\Log::log(Util\Code::CRON, 'Not enough CPU, tournamentId: ' . $tournament->getId() . ', ' . count($players) . ' / ' . $need, __FILE__, __LINE__);
             return false;
         }
         $playerIds = Engine::findCPU($players, $need, $tournament->getClassification());
         if (count($playerIds) < $need) {
             Util\Log::log(Util\Code::CRON, 'Not enough CPU found, tournamentId: ' . $tournament->getId() . ', ' . count($playerIds) . ' / ' . $need, __FILE__, __LINE__);
             return false;
         }
         $options = [];
         $options['clearSelect'] = true;
         $options['select'][] = \Own\Bus\Player\Data::getList(['id']);
         $options['where'][] = 'player.id IN (' . implode(',', $playerIds) . ')';
         $players = \Own\Bus\Player\Data::loadAll($options);
         foreach ($players as $player) {
             $tp = new \Own\Bus\TournamentPlayer\Model();
             $tp->setTournamentId($tournament->getId());
             $tp->setPlayerId($player->getId());
             $tp->save();
         }
     }
     return true;
 }
Example #7
0
 public static function loadRanking($type, $page)
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = Data::getList(['id', 'user_id', 'country', 'experience', 'username', 'tour_ranking', 'tour_point', 'tour_diff', 'race_ranking', 'race_point', 'race_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['order'][] = 'player.' . $type . '_ranking, player.created_date';
     $options['limit'][] = $page * 20 . ', 20';
     return \Own\Bus\Player\Data::loadAll($options);
 }
Example #8
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');
 }
Example #9
0
 public static function createForAll($title, $info = null)
 {
     $db = new Util\Data();
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'race_ranking', 'race_point']);
     $options['where'][] = 'user_id != 0';
     $players = \Own\Bus\Player\Data::loadAll($options);
     foreach ($players as $player) {
         $info = $title == 'endRanking' ? [['endRanking', $player->getRaceRanking(), $player->getRacePoint()]] : $info;
         $sql = 'SELECT id FROM bus_notification WHERE player_id = ? AND match_id = 0 AND title = ?';
         $exists = $db->selectOne($sql, [$player->getId(), $title]);
         if (isset($exists)) {
             if ($title == 'endRanking') {
                 continue;
             }
             break;
         }
         self::create($player->getId(), 0, $title, $info);
     }
 }
Example #10
0
File: Cron.php Project: vincium/lot
 private function rankingLeague()
 {
     // league ranking
     if (count($this->leagueIds) > 0) {
         $options = [];
         $options['clearSelect'] = true;
         $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'league_id', 'league_ranking', 'league_diff']);
         $options['where'][] = 'player.active = 1';
         $options['where'][] = ['player.league_id IN (?)', array_unique($this->leagueIds)];
         $options['order'][] = 'player.league_id, player.league_point DESC, player.id';
         $players = \Own\Bus\Player\Data::loadAll($options);
         $count = count($players);
         $rank = 1;
         $leagueId = 0;
         for ($i = 0; $i < $count; $i++) {
             if ($leagueId != $players[$i]->getLeagueId()) {
                 $leagueId = $players[$i]->getLeagueId();
                 $rank = 1;
             }
             $players[$i]->setLeagueDiff($players[$i]->getLeagueDiff() + $players[$i]->getLeagueRanking() - $rank);
             $players[$i]->setLeagueRanking($rank);
             $players[$i]->save();
             $rank++;
         }
         $this->log('ranking (league): ' . $count);
     }
 }
Example #11
0
 public static function removeAndAddPlayer()
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username']);
     $options['where'][] = 'player.user_id = 0';
     $options['where'][] = 'player.active = 1';
     $players = \Own\Bus\Player\Data::loadAll($options);
     if (count($players) > 0) {
         $db = new Util\Data();
         $pick = \Own\Bus\Engine::dice(0, count($players) - 1);
         $remove = 'UPDATE bus_player SET active = 0 WHERE id = ' . $players[$pick]->getId();
         $db->execute($remove);
         Util\Log::log(Util\Code::CRON, 'player retired: ' . $players[$pick]->getUsername() . ' (' . $players[$pick]->getId() . ')', __FILE__, __LINE__);
         $leagues = \Own\Bus\League\Data::loadAll();
         $player = new \Own\Bus\Player\Model();
         $player->setRandom(1);
         $player->setActive(true);
         if (count($leagues) > 0) {
             $player->setLeagueId(\Own\Bus\Engine::findLeague($leagues, 1));
         }
         $player->save();
         Util\Log::log(Util\Code::CRON, 'new player: ' . $player->getUsername() . ' (' . $player->getId() . ')', __FILE__, __LINE__);
     }
 }
Example #12
0
File: Data.php Project: 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;
 }
Example #13
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');
 }