private function rankingTour() { // tour ranking if (count($this->tourPlayerIds) > 0) { \Own\Bus\TournamentPlayer\Data::updatePlayerPoints($this->tourPlayerIds, $this->app->site()->getCreatedDate()); $options = []; $options['clearSelect'] = true; $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'tour_ranking', 'tour_point', 'tour_diff', 'race_ranking', 'race_point', 'race_diff']); $options['where'][] = 'player.active = 1'; $players = \Own\Bus\Player\Data::loadAll($options); $count = count($players); usort($players, function ($p1, $p2) { return $p1->getTourPoint() < $p2->getTourPoint(); }); for ($i = 0; $i < $count; $i++) { $players[$i]->setTourDiff($players[$i]->getTourDiff() + $players[$i]->getTourRanking() - ($i + 1)); $players[$i]->setTourRanking($i + 1); } usort($players, function ($p1, $p2) { return $p1->getRacePoint() < $p2->getRacePoint(); }); for ($i = 0; $i < $count; $i++) { $players[$i]->setRaceDiff($players[$i]->getRaceDiff() + $players[$i]->getRaceRanking() - ($i + 1)); $players[$i]->setRaceRanking($i + 1); } foreach ($players as $player) { $player->save(); } $this->log('ranking (tour & race): ' . $count); } }
public function sign() { $isAllowed = Util\Auth::isAuthorized($this->signedUser, 'member'); $json = []; $json['result'] = \Rebond\Core\ResultType::ERROR; if (!$isAllowed) { $json['message'] = Util\Lang::lang('accessNonAuthorized'); return json_encode($json); } $tournamentId = Util\Converter::toInt('tournamentId', 'post'); $action = Util\Converter::toString('action', 'post'); if ($tournamentId == 0 || !in_array($action, ['up', 'out'])) { $json['message'] = 'Invalid options'; return json_encode($json); } $tournament = \Own\Bus\Tournament\Data::loadById($tournamentId); $playerId = $this->player->getId(); if ($tournament->getClassification() == Classification::AMATEUR && $this->player->getTourPoint() >= 10) { $json['message'] = Util\Lang::lang('tooManyPointsForAmateur'); return json_encode($json); } if ($tournament->getClassification() != Classification::AMATEUR && $this->player->getTourPoint() < 10) { $json['message'] = Util\Lang::lang('notEnoughPointForTournament'); return json_encode($json); } if ($tournament->getClassification() <= Classification::ATP_250 && $this->player->getTourPoint() <= 100) { $json['message'] = Util\Lang::lang('needMorePointsForATP'); return json_encode($json); } $options = []; $options['where'][] = 'tournament_player.tournament_id = ' . $tournamentId; $tp = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($playerId, $options); if ($action == 'up') { if (count($tp) > 0) { $json['message'] = Util\Lang::lang('alreadySignedUp'); return json_encode($json); } if ($this->player->getIsInTournament() || $this->player->getIsRegistered()) { $json['message'] = Util\Lang::lang('alreadySignedUpInOtherTournament'); return json_encode($json); } $tp = new \Own\Bus\TournamentPlayer\Model(); $tp->setTournamentId($tournamentId); $tp->setPlayerId($playerId); $tp->save(); $this->player->setIsRegistered(true); $this->player->save(); $json['result'] = \Rebond\Core\ResultType::SUCCESS; $json['message'] = Util\Lang::lang('signedUp') . '!'; $json['newAction'] = 'out'; $json['html'] = Util\Lang::lang('signOut'); return json_encode($json); } if ($action == 'out') { if (count($tp) == 0) { $json['message'] = Util\Lang::lang('notRegistered'); return json_encode($json); } \Own\Bus\TournamentPlayer\Data::deleteById($tp[0]->getId()); $this->player->setIsRegistered(false); $this->player->save(); $json['result'] = \Rebond\Core\ResultType::SUCCESS; $json['message'] = Util\Lang::lang('signedOut') . '!'; $json['newAction'] = 'up'; $json['html'] = Util\Lang::lang('signUp'); return json_encode($json); } $json['message'] = 'nothing to do'; return json_encode($json); }
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'); }
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'); }