Ejemplo n.º 1
0
Archivo: Home.php Proyecto: vincium/lot
 public function index()
 {
     if (isset($_POST['sign-out'])) {
         \Rebond\Core\UserSecurity\Service::signOut($this->signedUser);
     }
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     if ($this->player->getId() == 0) {
         $tpl = 'index-guest';
         $matchView = \Own\Bus\Match\Data::loadLastMatch();
     } else {
         $tpl = 'index';
         $matchView = \Own\Bus\Match\Data::loadRecentByPlayerId($this->player->getId());
         $nextMatch = \Own\Bus\Match\Data::loadNextMatchByPlayerId($this->player->getId());
         $soon = isset($nextMatch) && $nextMatch->getScheduled() < time() + Engine::DAY * 360 ? true : false;
         $tplMain->set('player', $this->player);
         $tplMain->set('notificationCount', \Own\Bus\Notification\Data::countByPlayerId($this->player->getId()));
         $tplMain->set('isBonusDayXp', $this->player->isBonusDayXp());
         $tplMain->set('nextBonusDayXp', $this->player->getNextBonusDayXp());
         $tplMain->set('nextMatch', $nextMatch);
         $tplMain->set('soon', $soon);
     }
     $tplMain->set('matchView', $matchView);
     $options = [];
     $options['where'][] = 'configuration.property = \'nextWeek\'';
     $nextWeek = \Own\Bus\Configuration\Data::load($options);
     $options = [];
     $options['where'][] = 'configuration.property = \'nextMonth\'';
     $nextMonth = \Own\Bus\Configuration\Data::load($options);
     $options = [];
     $options['where'][] = 'configuration.property = \'nextYear\'';
     $nextYear = \Own\Bus\Configuration\Data::load($options);
     if (!isset($nextWeek, $nextMonth, $nextYear)) {
         Util\error::kill(Util\Code::UNHANDLED_ERROR, 'nextWeek, nextMonth or nextYear is not set in bus_configuration', __FILE__, __LINE__);
     }
     $tplMain->set('gameTime', Engine::renderTime($this->app->site()->getCreatedDate()));
     $tplMain->set('endWeek', (new Util\DateTime())->setTimestamp($nextWeek->getValue()));
     $tplMain->set('endMonth', (new Util\DateTime())->setTimestamp($nextMonth->getValue()));
     $tplMain->set('endYear', (new Util\DateTime())->setTimestamp($nextYear->getValue()));
     // view
     $this->setTpl();
     // layout
     $this->tplLayout->set('column1', $tplMain->render($tpl));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 2
0
Archivo: Cron.php Proyecto: vincium/lot
 public function endTime()
 {
     $options = [];
     $options['where'][] = ['configuration.property = ?', 'nextWeek'];
     $nextWeek = \Own\Bus\Configuration\Data::load($options);
     $options = [];
     $options['where'][] = ['configuration.property = ?', 'nextMonth'];
     $nextMonth = \Own\Bus\Configuration\Data::load($options);
     $options = [];
     $options['where'][] = ['configuration.property = ?', 'nextYear'];
     $nextYear = \Own\Bus\Configuration\Data::load($options);
     // week (day * 7)
     if ((int) $nextWeek->getValue() < time()) {
         \Own\Bus\League\Data::updateSurfaceBatch();
         \Own\Bus\Player\Data::resetLeagueDiff();
         $this->log('leagues surface', true);
         // award achievements
     }
     // 2 days before the end of the month
     if ((int) $nextMonth->getValue() < time() + 2 * Engine::DAY * 3600) {
         \Own\Bus\Notification\Service::createForAll('endOfTheMonth', [['endOfTheMonth', $nextMonth->getValue()]]);
     }
     // month (day * 7 * 4)
     if ((int) $nextMonth->getValue() < time()) {
         // change players league
         $options = [];
         $options['clearSelect'] = true;
         $options['select'][] = \Own\Bus\League\Data::getList(['id', 'classification']);
         $options['order'][] = 'league.classification';
         $leagues = \Own\Bus\League\Data::loadAll($options);
         $leaguesInfo = [];
         $moved = [];
         foreach ($leagues as $league) {
             $leaguesInfo[$league->getId()] = [];
             $leaguesInfo[$league->getId()]['classification'] = $league->getClassification();
             $leaguesInfo[$league->getId()]['up'] = Engine::classificationMove(true, $league->getClassification());
             $leaguesInfo[$league->getId()]['down'] = Engine::classificationMove(false, $league->getClassification());
             $options = [];
             $options['where'][] = ['player.league_id = ?', $league->getId()];
             $options['where'][] = 'player.active = 1';
             $leaguesInfo[$league->getId()]['count'] = \Own\Bus\Player\Data::count($options);
         }
         // going down
         foreach ($leagues as $league) {
             if ($league->getClassification() != Classification::AMATEUR) {
                 $options = [];
                 $options['clearSelect'] = true;
                 $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'league_id']);
                 $options['where'][] = 'player.active = 1';
                 $options['where'][] = ['player.league_id = ?', $league->getId()];
                 if (count($moved) > 0) {
                     $options['where'][] = ['player.id NOT IN (?)', $moved];
                 }
                 $options['order'][] = 'player.league_ranking DESC';
                 $options['limit'][] = Engine::classificationMove(false, $league->getClassification());
                 $players = \Own\Bus\Player\Data::loadAll($options);
                 foreach ($players as $player) {
                     $leagueId = Engine::findLeagueId(false, $player->getLeagueId(), $leaguesInfo);
                     $player->setLeagueId($leagueId);
                     $player->save();
                     $moved[] = $player->getId();
                     if ($player->getUserId() != 0) {
                         \Own\Bus\Notification\Service::create($this->getId(), 0, 'leagueDown', [['leagueDown', $leaguesInfo[$leagueId]['classification']]]);
                     }
                 }
             }
         }
         // going up
         foreach ($leagues as $league) {
             if ($league->getClassification() != Classification::MASTERS) {
                 $options = [];
                 $options['clearSelect'] = true;
                 $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'league_id']);
                 $options['where'][] = 'player.active = 1';
                 $options['where'][] = ['player.league_id = ?', $league->getId()];
                 if (count($moved) > 0) {
                     $options['where'][] = ['player.id NOT IN (?)', $moved];
                 }
                 $options['order'][] = 'player.league_ranking ASC';
                 $options['limit'][] = Engine::classificationMove(true, $league->getClassification());
                 $players = \Own\Bus\Player\Data::loadAll($options);
                 foreach ($players as $player) {
                     $leagueId = Engine::findLeagueId(true, $player->getLeagueId(), $leaguesInfo);
                     $player->setLeagueId($leagueId);
                     $player->save();
                     if ($player->getUserId() != 0) {
                         \Own\Bus\Notification\Service::create($this->getId(), 0, 'leagueUp', [['leagueUp', $leaguesInfo[$leagueId]['classification']]]);
                     }
                 }
             }
         }
         \Own\Bus\Player\Data::resetLeagueRanking();
         $this->log('players leagues update');
         // reset tour and race diff
         \Own\Bus\Player\Data::resetTourAndRaceDiff();
         $this->log('reset tour and race diff', true);
         // remove/add player
         \Own\Bus\Player\Service::removeAndAddPlayer();
         $this->log('remove/add player');
         // award achievements
     }
     // one month before the end of the year
     if ((int) $nextYear->getValue() < time() + Engine::DAY * 28 * 3600) {
         \Own\Bus\Notification\Service::createForAll('endOfTheYear', [['endOfTheYear', $nextYear->getValue()]]);
     }
     // year
     if ((int) $nextYear->getValue() < time()) {
         \Own\Bus\Notification\Service::createForAll('endRanking');
         // reset race ranking
         \Own\Bus\Player\Data::resetRaceRanking();
         $this->log('race ranking reset', true);
         // award achievements
     }
     if ((int) $nextYear->getValue() < time()) {
         $nextYear->setValue((int) $nextYear->getValue() + 336 * Engine::DAY * 60 * 60);
         $nextYear->save();
     }
     if ((int) $nextMonth->getValue() < time()) {
         $nextMonth->setValue((int) $nextMonth->getValue() + 7 * 4 * Engine::DAY * 60 * 60);
         $nextMonth->save();
     }
     if ((int) $nextWeek->getValue() < time()) {
         $nextWeek->setValue((int) $nextWeek->getValue() + 7 * Engine::DAY * 60 * 60);
         $nextWeek->save();
     }
 }
Ejemplo n.º 3
0
 public function index()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     \Own\Bus\Match\Data::getCurrentMatch($this->player->getId(), [1, 2, 3]);
     $playLeague = Util\Converter::toBool('league');
     $playPractice = Util\Converter::toString('play', 'post');
     $lastMatchPlayed = (new \Rebond\Util\DateTime())->getTimestamp() - $this->player->getLastMatchPlayed()->getTimestamp();
     // minimum in 2 minutes, maximum 10 matches per day
     $scheduled = $lastMatchPlayed > Engine::DAY * 60 * 6 ? 120 : Engine::DAY * 60 * 6 - $lastMatchPlayed;
     $options = [];
     $options['where'][] = 'configuration.property = \'nextMonth\'';
     $nextMonth = \Own\Bus\Configuration\Data::load($options);
     if ($playLeague && time() + $scheduled > (int) $nextMonth->getValue()) {
         Util\Session::setAndRedirect('siteError', Util\Lang::lang('leagueMonthFinished'), '/match');
     }
     if ($playLeague || $playPractice != '') {
         $match = new \Own\Bus\Match\Model();
         $playerMatch1 = new \Own\Bus\PlayerMatch\Model();
         $playerMatch2 = new \Own\Bus\PlayerMatch\Model();
         if ($playLeague) {
             $match->setSurface($this->player->getLeague()->getSurface());
             $match->setType(MatchType::LEAGUE);
             $match->setLeagueId($this->player->getLeagueId());
             $match->setBestOfSets($this->player->getLeague()->getBestOfSets());
             $player2 = \Own\Bus\Player\Data::searchByLeague($this->player->getId(), $this->player->getLeagueId());
         } else {
             $surface = Util\Converter::toInt('surface', 'post');
             $level = Util\Converter::toInt('level', 'post');
             if (!in_array($level, [-1, 0, 1])) {
                 $level = 0;
             }
             $match->setType(MatchType::PRACTICE);
             $match->setSurface($surface);
             $player2 = \Own\Bus\Player\Data::searchByLevel($level, $this->player->getExperience(), $this->player->getId());
         }
         if (!isset($player2)) {
             Util\Session::setAndRedirect('siteError', Util\Lang::lang('noPlayerFound'), '/match');
         }
         \Own\Bus\Player\Data::updateIsInMatch($this->player->getId(), $player2->getId());
         $playerMatch1->setPlayerId($this->player->getId());
         $playerMatch1->setLevel($this->player->calculateLevel());
         $playerMatch1->save();
         $playerMatch2->setPlayerId($player2->getId());
         $playerMatch2->setLevel($player2->calculateLevel());
         $playerMatch2->save();
         $match->setPlayerMatch1Id($playerMatch1->getId());
         $match->setPlayerMatch2Id($playerMatch2->getId());
         $scheduledDate = \Rebond\Util\DateTime::createFromTimestamp(time() + $scheduled);
         $match->setScheduled($scheduledDate);
         $match->setStatus(MatchStatus::READY);
         $match->save();
         Util\Session::setAndRedirect('siteSuccess', 'Match scheduled ' . $scheduledDate->format(), '/match/vs?matchId=' . $match->getId());
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('surface', [1 => 'Clay', 2 => 'Grass', 3 => 'Hard']);
     $tplMain->set('level', [-1 => Util\Lang::lang('opponentWeak'), 0 => Util\Lang::lang('opponentEqual'), 1 => Util\Lang::lang('opponentStrong')]);
     $tplMain->set('league', $this->player->getLeague());
     $tplMain->set('scheduled', $scheduled);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('match-play'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }