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')]]); }
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); }
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; }
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'); }
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); } }
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); } }
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__); } }