public function index() { Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/'); $page = Util\Converter::toInt('page', 'get', 1); // get user settings $userSettings = $this->signedUser->getUserSettings(); $maxByPage = isset($userSettings) ? (int) $userSettings->getPagingValue() : 10; $countItems = \Own\Bus\Player\Data::count(); $page = Util\Nav::getCurrentPage($page, $countItems, $maxByPage); $options = []; $options['clearSelect'] = true; $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'credits', 'level']); $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'firstname', 'lastname', 'status'], 'player_id'); $options['join'][] = 'core_user player_id ON player_id.id = player.id'; $options['order'][] = 'player_id.username'; $options['limit'][] = ($page - 1) * $maxByPage . ', ' . $maxByPage; $items = \Own\Bus\Player\Data::loadAll($options); // main $tplFilter = new Util\Template(Util\Template::SITE, ['admin']); $tplFilter->set('paging', Util\Nav::renderPaging($countItems, '/own/index?page=', $maxByPage, $page)); $tplFilter->set('itemsPerPage', Util\Nav::renderItemsPerPage($maxByPage)); $tplPlayer = new Util\Template(Util\Template::SITE, ['admin']); $tplPlayer->set('items', $items); return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-1-col', ['column1' => [$tplFilter->render('players-filter'), $tplPlayer->render('players')]]); }
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'); }
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'); }
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')]); }
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(); } }