Exemplo n.º 1
0
Arquivo: Mail.php Projeto: 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);
 }
Exemplo n.º 2
0
Arquivo: Form.php Projeto: 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());
 }
Exemplo n.º 3
0
Arquivo: Data.php Projeto: 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);
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 public function register()
 {
     $userGadget = new \Own\App\User\Gadget($this->app);
     $register = $userGadget->register();
     $this->signedUser = $this->app->user();
     if ($this->signedUser->getId() != 0) {
         $player = \Own\Bus\Player\Data::loadById($this->signedUser->getId());
         if ($player == null) {
             $player = \Own\Bus\Player\Service::create($this->signedUser);
         }
     }
     return $this->response('tpl-default', ['title' => Util\Lang::lang('profile')], 'layout-home', ['column1' => $register]);
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
Arquivo: Own.php Projeto: vincium/resa
 public function player()
 {
     Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/');
     $playerId = Util\Converter::toInt('id');
     if (!isset($playerId)) {
         Util\Session::adminError('item.not.found', [Util\Lang::lang('player'), $playerId], '/own');
     }
     $user = \Rebond\Core\User\Data::loadById($playerId, true);
     $player = \Own\Bus\Player\Data::loadById($playerId, true);
     $userForm = new \Rebond\Core\User\Form($user);
     $playerForm = new \Own\Bus\Player\Form($player);
     // action
     $save = Util\Converter::toString('save', 'post');
     $membershipIds = Util\Converter::toArray('membership', 'post');
     if (isset($save)) {
         if ($user->getId() == 0) {
             $user->setUsername($user->getEmail());
             $user->setPassword(Util\Security::encryptPassword($user->getPassword()));
         }
         if ($userForm->setFromPost()->validate()->isValid()) {
             if ($playerForm->setFromPost()->validate()->isValid()) {
                 \Own\Bus\PlayerMembership\Data::deleteByPlayerId($player->getId());
                 $newMemberships = [];
                 if (isset($membershipIds)) {
                     foreach ($membershipIds as $membershipId) {
                         $playerMembership = new \Own\Bus\PlayerMembership\Model();
                         $playerMembership->setPlayerId($player->getId());
                         $playerMembership->setMembershipId($membershipId);
                         $newMemberships[] = $playerMembership;
                     }
                 }
                 \Own\Bus\PlayerMembership\Data::saveAll($newMemberships);
                 $user->save();
                 $player->save();
                 Util\Session::adminSuccess('saved', '/own/player?id=' . $user->getId());
             } else {
                 Util\Session::set('adminError', $playerForm->getValidation()->getMessage());
             }
         } else {
             Util\Session::set('adminError', $userForm->getValidation()->getMessage());
         }
     }
     $tplEditor = new Util\Template(Util\Template::SITE, ['admin']);
     $tplEditor->set('user', $userForm);
     $tplEditor->set('player', $playerForm);
     $tplInfo = new Util\Template(Util\Template::SITE, ['admin']);
     $tplInfo->set('user', $user);
     return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-2-col', ['column1' => $tplEditor->render('player-editor'), 'column2' => $tplInfo->render('player-info')]);
 }
Exemplo n.º 8
0
Arquivo: Base.php Projeto: vincium/lot
 public function __construct(\Rebond\App $app)
 {
     if ($app->site()->getStatus() == \Rebond\Core\StatusType::INACTIVE) {
         Util\Session::redirect('/error/maintenance');
     }
     parent::__construct($app);
     if ($this->signedUser->getId() != 0) {
         $this->player = \Own\Bus\Player\Data::loadByUserId($this->signedUser->getId());
         if ($this->player == null) {
             $this->player = \Own\Bus\Player\Service::create($this->signedUser);
         }
     } else {
         $this->player = new \Own\Bus\Player\Model();
     }
 }
Exemplo n.º 9
0
 public static function renderCalendar($player = null)
 {
     $maxBooking = 0;
     $playerLevel = \Own\Bus\Level::value(0);
     $players = [];
     if (isset($player)) {
         $maxBooking = $player->getMaxBooking();
         $playerLevel = $player->getLevelValue();
         $players = \Own\Bus\Player\Data::loadPartners($player->getId());
     }
     $tplCalendar = new Util\Template(Util\Template::MODULE, ['bus', 'book']);
     $tplCalendar->set('maxBooking', $maxBooking);
     $tplCalendar->set('playerLevel', $playerLevel);
     $tplCalendar->set('players', $players);
     return $tplCalendar->render('booking-placeholder');
 }
Exemplo n.º 10
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');
 }
Exemplo n.º 11
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')]);
 }
Exemplo n.º 12
0
 public function __construct(\Rebond\App $app)
 {
     if ($app->site()->getStatus() == \Rebond\Core\StatusType::INACTIVE) {
         if ($app->ajax()) {
             return ['result' => ResultType::ERROR, 'message' => Lang::lang('error.maintenance')];
         } else {
             Util\Session::redirect('/error/maintenance');
         }
     }
     parent::__construct($app);
     if ($this->signedUser->getId() != 0) {
         $options = ['where' => [['id = ?', $this->signedUser->getId()]]];
         $this->player = \Own\Bus\Player\Data::load($options);
         if ($this->player == null) {
             $this->player = \Own\Bus\Player\Service::create($this->signedUser);
         }
     } else {
         $this->player = new \Own\Bus\Player\Model();
     }
 }
Exemplo n.º 13
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);
     }
 }
Exemplo n.º 14
0
 public function player()
 {
     $json = [];
     $json['result'] = \Rebond\Core\ResultType::ERROR;
     $matchView = \Own\Bus\Match\Data::loadRecentByPlayerId($this->player->getId());
     if (isset($matchView)) {
         $json['message'] = Util\Lang::lang('matchView');
         return json_encode($json);
     }
     // check
     $id = Util\Converter::toInt('id', 'post');
     // cache
     $cacheTime = $this->app->site()->getCacheTime();
     $cache = Util\Cache::getCache('profile', $this->signedUser->getId() . '_' . $id, $cacheTime);
     if (isset($cache)) {
         $json['html'] = $cache;
         $json['result'] = \Rebond\Core\ResultType::SUCCESS;
         return json_encode($json);
     }
     $player = \Own\Bus\Player\Data::loadById($id);
     if (!isset($player)) {
         $json['message'] = Util\Lang::lang('playerNotFound');
         return json_encode($json);
     }
     $self = $player->getId() == $this->player->getId();
     $stats = \Own\Bus\Match\Data::loadStatsByPlayerId($player->getId(), $self);
     $options = [];
     $options['where'][] = 'winner_id = ' . $player->getId();
     $titles = \Own\Bus\Tournament\Data::count($options);
     $faceToFace = null;
     if (!$self) {
         $faceToFace = \Own\Bus\Match\Data::loadFaceToFace($this->player->getId(), $player->getId());
     }
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('self', $self);
     $tplMain->set('player', $player);
     $tplMain->set('stats', $stats);
     $tplMain->set('titles', $titles);
     $tplMain->set('faceToFace', $faceToFace);
     $tplMain->set('ajax', true);
     // layout
     $cache = $tplMain->render('profile');
     Util\Cache::saveCache('profile', $this->signedUser->getId() . '_' . $id, $cacheTime, $cache);
     $json['title'] = $player->getUsername();
     $json['html'] = $cache;
     $json['result'] = \Rebond\Core\ResultType::SUCCESS;
     return json_encode($json);
 }
Exemplo n.º 15
0
 public function bookCourt()
 {
     $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);
     }
     $courtId = Util\Converter::toInt('courtId', 'post');
     $dateTime = Util\Converter::toString('dateTime', 'post');
     $bookingType = Util\Converter::toInt('bookingType', 'post');
     $playerId = Util\Converter::toInt('playerId', 'post');
     $pay = Util\Converter::toInt('pay', 'post');
     $guest = Util\Converter::toString('guest', 'post');
     if (!isset($courtId, $dateTime, $bookingType, $playerId, $pay, $guest) || !array_key_exists($bookingType, \Own\Bus\BookingType::toArray())) {
         $json['message'] = Util\Lang::lang('error.invalid.parameters');
         return json_encode($json);
     }
     $dateTime = new Util\DateTime($dateTime);
     if ($dateTime < new \DateTime()) {
         $json['message'] = Util\Lang::lang('error.invalid.time');
         return json_encode($json);
     }
     switch ($bookingType) {
         case \Own\Bus\BookingType::PARTNER:
             $guest = '';
             break;
         case \Own\Bus\BookingType::GUEST:
             $pay = \Own\Bus\Pay::PLAYER_1;
             $playerId = 0;
             break;
         case \Own\Bus\BookingType::CAROUSSEL:
             $pay = \Own\Bus\Pay::BOTH;
             $playerId = 0;
             $guest = '';
             break;
         default:
     }
     // check player
     $player = \Own\Bus\Player\Data::loadById($playerId);
     if (!isset($player) || $player->getIdItem()->getStatus() != 1) {
         $json['message'] = Util\Lang::lang('playerNotFound');
         return json_encode($json);
     }
     if ($pay == \Own\Bus\Pay::BOTH && $this->player->getCredits() < 1 || $pay == \Own\Bus\Pay::PLAYER_1 && $this->player->getCredits() < 2) {
         $json['message'] = Util\Lang::lang('notEnoughCredits');
         return json_encode($json);
     }
     // check credits
     if ($pay == \Own\Bus\Pay::BOTH && $player->getCredits() < 1 || $pay == \Own\Bus\Pay::PLAYER_2 && $player->getCredits() < 2) {
         $json['message'] = Util\Lang::lang('partnerNotEnoughCredits');
         return json_encode($json);
     }
     // check membership
     $memberships = \Own\Bus\Player\Data::hasMembership($courtId, [$this->player->getId(), $playerId]);
     if ($memberships != 2 || $memberships != 1 && $bookingType != \Own\Bus\BookingType::PARTNER) {
         $json['message'] = Util\Lang::lang('noMembership');
         return json_encode($json);
     }
     // check court time
     $options = [];
     $options['where'][] = ['id = ?', $courtId];
     $court = \Own\Bus\Court\Data::load($options);
     if (!isset($court)) {
         $json['message'] = Util\Lang::lang('error.invalid.parameters');
         return json_encode($json);
     }
     $rule = \Own\Bus\Rule\Data::loadById(1, true);
     $timeLength = $rule->getTimeLength();
     $askedTime = (int) $dateTime->format('H') * 60 + (int) $dateTime->format('i');
     $possibleTime = (int) $court->getStartTime()->format('H') * 60 + (int) $court->getStartTime()->format('i');
     $limitTime = (int) $court->getEndTime()->format('H') * 60 + (int) $court->getEndTime()->format('i');
     if ($askedTime < $possibleTime || $askedTime > $limitTime || $askedTime % $timeLength != 0) {
         $json['message'] = Util\Lang::lang('error.invalid.time');
         return json_encode($json);
     }
     // check for court already booked
     $options = [];
     $options['where'][] = ['court_id = ?', $courtId];
     $options['where'][] = ['booking_date = ?', $dateTime->format('Y-m-d H:i:00')];
     $booking = Book\Data::load($options);
     if (isset($booking)) {
         $json['message'] = Util\Lang::lang('alreadyBookedTime');
         return json_encode($json);
     }
     // check for same hour
     $options = [];
     $options['where'][] = ['player1_id = ? OR player2_id = ?', $this->player->getId(), $this->player->getId()];
     $options['where'][] = ['booking_date BETWEEN ? AND ?', $dateTime->format('Y-m-d H:00:00'), $dateTime->format('Y-m-d H:59:00')];
     $booking = Book\Data::load($options);
     if (isset($booking)) {
         $json['message'] = Util\Lang::lang('alreadyBookedTime');
         return json_encode($json);
     }
     // check for max booking
     $maxBooking = $this->player->getMaxBooking();
     if ($maxBooking > 0) {
         $options = [];
         $options['where'][] = ['player1_id = ? OR player2_id = ?', $this->player->getId(), $this->player->getId()];
         $options['where'][] = 'booking_date > NOW()';
         $futureBookings = Book\Data::count($options);
         if ($futureBookings >= $maxBooking) {
             $json['message'] = Util\Lang::lang('maxBookingReachedByYou');
             return json_encode($json);
         }
     }
     $options = [];
     $options['where'][] = ['player1_id = ? OR player2_id = ?', $playerId, $playerId];
     $options['where'][] = 'booking_date > NOW()';
     $futureBookings = Book\Data::count($options);
     if ($futureBookings >= $player->getMaxBooking()) {
         $json['message'] = Util\Lang::lang('maxBookingReached', [$player->getIdItem()->getFullName()]);
         return json_encode($json);
     }
     // add booking
     if ($pay == \Own\Bus\Pay::BOTH) {
         $this->player->addCredits(-1);
         $this->player->save();
         $player->addCredits(-1);
         $player->save();
     } else {
         if ($pay == \Own\Bus\Pay::PLAYER_1) {
             $this->player->addCredits(-2);
             $this->player->save();
         } else {
             if ($pay == \Own\Bus\Pay::PLAYER_2) {
                 $player->addCredits(-2);
                 $player->save();
             }
         }
     }
     $book = new Book\Model();
     $book->setType($bookingType);
     $book->setPlayer1Id($this->player->getId());
     $book->setPlayer2Id($playerId);
     $book->setCourtId($courtId);
     $book->setBookingDate($dateTime);
     $book->setPay($pay);
     $book->setGuest($guest);
     $book->save();
     $json['result'] = \Rebond\Core\ResultType::SUCCESS;
     $json['message'] = Util\Lang::lang('courtBooked');
     return json_encode($json);
 }
Exemplo n.º 16
0
Arquivo: Data.php Projeto: vincium/lot
 public static function updatePlayerPoints($playerIds, $createdDate)
 {
     // tour
     $db = new Util\Data();
     $sql = 'SELECT player_id, SUM(tp.points) as points, COUNT(player_id) as total
         FROM bus_tournament_player tp
         JOIN bus_tournament t ON t.id = tp.tournament_id
         WHERE t.start_date > NOW() - INTERVAL ' . Engine::DAY * 336 . ' HOUR
         AND tp.points > 0
         AND player_id IN (' . implode(',', $playerIds) . ')
         GROUP BY player_id
         ORDER BY points DESC';
     $result = $db->select($sql);
     if (count($result) == 0) {
         return;
     }
     while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
         if ($row['total'] <= 18) {
             \Own\Bus\Player\Data::updateTourPointsByPlayerId($row['player_id'], $row['points']);
             continue;
         }
         $sql = 'SELECT SUM(points) as points
             FROM (
                 SELECT points
                 FROM bus_tournament_player tp
                 JOIN bus_tournament t ON t.id = tp.tournament_id
                 WHERE player_id = ?
                 AND t.start_date > NOW() - INTERVAL ? HOUR
                 ORDER BY points DESC
                 LIMIT 18
             ) AS subquery';
         $subRow = $db->selectOne($sql, [$row['player_id'], Engine::DAY * 336]);
         if (isset($subRow)) {
             \Own\Bus\Player\Data::updateTourPointsByPlayerId($row['player_id'], $subRow['points']);
         }
     }
     // race
     $startYearDate = \Own\Bus\Engine::getStartYearDate($createdDate);
     $sql = 'SELECT player_id, SUM(tp.points) as points, COUNT(player_id) as total
         FROM bus_tournament_player tp
         JOIN bus_tournament t ON t.id = tp.tournament_id
         WHERE t.start_date > \'' . $startYearDate . '\'
         AND tp.points > 0
         AND player_id IN (' . implode(',', $playerIds) . ')
         GROUP BY player_id
         ORDER BY points DESC';
     $result = $db->execute($sql);
     if (count($result) == 0) {
         return;
     }
     while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
         if ($row['total'] <= 18) {
             \Own\Bus\Player\Data::updateRacePointsByPlayerId($row['player_id'], $row['points']);
             continue;
         }
         $sql = 'SELECT SUM(points) as points
             FROM (
                 SELECT points
                 FROM bus_tournament_player tp
                 JOIN bus_tournament t ON t.id = tp.tournament_id
                 WHERE player_id = ? AND t.start_date > ?
                 ORDER BY points DESC
                 LIMIT 18
             ) AS subquery';
         $subRow = $db->selectOne($sql, [$row['player_id'], $startYearDate]);
         if (isset($subRow)) {
             \Own\Bus\Player\Data::updateRacePointsByPlayerId($row['player_id'], $subRow['points']);
         }
     }
 }
Exemplo n.º 17
0
Arquivo: Cron.php Projeto: 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);
     }
 }
Exemplo n.º 18
0
 public function register()
 {
     $userGadget = new \Own\App\User\Gadget($this->app);
     $register = $userGadget->register();
     $this->signedUser = $this->app->user();
     if ($this->signedUser->getId() != 0) {
         $player = \Own\Bus\Player\Data::loadByUserId($this->signedUser->getId());
         if ($player == null) {
             $player = \Own\Bus\Player\Service::create($this->signedUser);
         }
         $player->setActive(true);
         $player->save();
     }
     $email = Util\Converter::toString('email', 'post');
     if (isset($email)) {
         $user = \Rebond\Core\User\Data::loadByEmail($email);
     }
     // view
     $this->setTpl();
     // layout
     $this->tplLayout->set('column1', $register);
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Exemplo n.º 19
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__);
     }
 }
Exemplo n.º 20
0
 public function history()
 {
     // check
     $type = Util\Converter::toString('type', 'get', 'own');
     $page = Util\Converter::toInt('page', 'get', 1);
     $id = Util\Converter::toInt('id', 'get', 0);
     $url = '/match/history?';
     $title = '';
     if (!in_array($type, ['own', 'all', 'f2f'])) {
         $type = 'own';
     }
     if ($type == 'all') {
         $count = \Own\Bus\Match\Data::countFinished($this->player->getId());
         $matches = \Own\Bus\Match\Data::loadAllFinished($this->player->getId(), true, $page - 1);
         $title = '(' . Util\Lang::lower('all') . ')';
         $url .= 'type=all&';
     } else {
         if ($type == 'f2f' && $id != 0) {
             $player = \Own\Bus\Player\Data::loadById($id);
             if (!isset($player)) {
                 $type = 'own';
             } else {
                 $count = \Own\Bus\Match\Data::countFace2Face($player->getId(), $this->player->getId());
                 $matches = \Own\Bus\Match\Data::loadAllFace2Face($player->getId(), $this->player->getId(), $page - 1);
                 $title = '(' . Util\Lang::lower('faceToFace') . ')';
                 $url .= 'type=f2f&id=' . $id . '&';
             }
         }
     }
     if ($type == 'own') {
         if ($id == 0) {
             $player = $this->player;
         } else {
             $player = \Own\Bus\Player\Data::loadById($id);
             if (!isset($player)) {
                 $player = $this->player;
             }
             $title = '';
             $url .= 'id=' . $id . '&';
         }
         $count = \Own\Bus\Match\Data::countFinishedByPlayerId($player->getId(), $this->player->getId() == $player->getId());
         $matches = \Own\Bus\Match\Data::loadAllFinishedByPlayerId($player->getId(), $this->player->getId() == $player->getId(), $page - 1);
     }
     // view
     $this->setTpl();
     // filter
     $tplFilter = new Util\Template(Util\Template::SITE, ['www']);
     $tplFilter->set('current', $page);
     $tplFilter->set('count', $count);
     $tplFilter->set('type', $type);
     $tplFilter->set('title', $title);
     $tplFilter->set('url', $url . 'page=');
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('matches', $matches);
     if ($type != 'all') {
         $tplMain->set('playerId', 0);
         $tplMain->set('username', $player->getUsername());
     } else {
         $tplMain->set('playerId', $this->player->getId());
     }
     $tplMain->set('type', $type);
     // layout
     $this->tplLayout->set('column1', $tplFilter->render('match-history-filter'));
     $this->tplLayout->add('column1', $tplMain->render('match-history'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Exemplo n.º 21
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');
 }
Exemplo n.º 22
0
Arquivo: Data.php Projeto: 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;
 }