예제 #1
0
파일: League.php 프로젝트: vincium/lot
 public function index()
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\League\Data::getList(['id', 'title', 'classification', 'surface']);
     $options['order'][] = 'league.classification';
     $leagues = \Own\Bus\League\Data::loadAll($options);
     foreach ($leagues as &$league) {
         $options = [];
         $options['where'][] = 'player.league_id = ' . $league->getId();
         $options['where'][] = 'player.active = 1';
         $league->playerCount = \Own\Bus\Player\Data::count($options);
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::SITE, ['www']);
     $tplMain->set('leagues', $leagues);
     $tplMain->set('leagueId', $this->player->getLeagueId());
     // layout
     $this->tplLayout->set('column1', $tplMain->render('league'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
예제 #2
0
파일: Cron.php 프로젝트: 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();
     }
 }
예제 #3
0
파일: Service.php 프로젝트: vincium/lot
 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__);
     }
 }