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 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(); } }
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; }