Example #1
0
 public function ranking()
 {
     \Own\Bus\Match\Data::checkMatchToView($this->player->getId());
     // check
     $type = Converter::toString('type', 'get', 'race');
     $page = Converter::toInt('page', 'get', 1);
     if (!in_array($type, ['race', 'tour'])) {
         $type = 'race';
     }
     $url = '/tournament/ranking?type=' . $type;
     $options = [];
     $options['where'][] = 'player.active = 1';
     $count = \Own\Bus\Player\Data::count($options);
     $players = \Own\Bus\Player\Service::loadRanking($type, $page - 1);
     // view
     $this->setTpl();
     // filter
     $tplFilter = new Template(Template::SITE, ['www']);
     $tplFilter->set('type', $type);
     $tplFilter->set('otherType', $type == 'race' ? 'tour' : 'race');
     $tplFilter->set('current', $page);
     $tplFilter->set('count', $count);
     $tplFilter->set('url', $url . '&page=');
     // main
     $tplMain = new Template(Template::SITE, ['www']);
     $tplMain->set('player', $this->player);
     $tplMain->set('players', $players);
     // layout
     $this->tplLayout->set('column1', $tplFilter->render('tour-ranking-filter'));
     $this->tplLayout->add('column1', $tplMain->render($type . '-ranking'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Example #2
0
File: Base.php Project: 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();
     }
 }
Example #3
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();
     }
 }
Example #4
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]);
 }
Example #5
0
 public static function renderProgressBar($class, $mastery, $value, $max = null)
 {
     $max = !isset($max) ? \Own\Bus\Player\Service::getMaxByMasteryType($mastery) : $max;
     $htmlValue = $max == 100 ? $value . '%' : ($max == 1000 ? round($value / 10) . '%' : $value . ' / ' . $max);
     return '<div class="progress" id="progress-' . $mastery . '">
         <div class="progress-bar ' . $class . '" data-value="' . $value . '" data-max="' . $max . '">
             <span>' . Util\Lang::lang($mastery) . '</span>
             <span class="value">' . $htmlValue . '</span>
         </div>
     </div>';
 }
Example #6
0
File: Cron.php Project: 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();
     }
 }
Example #7
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');
 }
Example #8
0
 public function getMasteryValues()
 {
     $masteries = Service::getMasteryList();
     $list = [];
     foreach ($masteries as $mastery) {
         $list[] = $this->{$mastery};
     }
     return $list;
 }