public static function generate($tournament) { $options = []; $options['where'][] = ['match.tournament_id = ?', $tournament->getId()]; $matchCount = \Own\Bus\Match\Data::count($options); if ($matchCount == 0) { $tournamentTime = $tournament->getStartDate()->add(new \DateInterval('PT1M')); if (count($tournament->getTournamentPlayers()) >= $tournament->getSize()) { $position = $tournament->getSize() - 1; $players = self::getOrderedPlayers($tournament); $i = 0; while ($position >= $tournament->getSize() / 2) { $matchTime = $tournamentTime->getTimestamp() + 60 * ($tournament->getSize() - $position) * (6 + 256 / $tournament->getSize()) * (Engine::DAY / 24); $match = new \Own\Bus\Match\Model(); $match->setTournamentId($tournament->getId()); $match->setSurface($tournament->getSurface()); $match->setBestOfSets($tournament->getBestOfSets()); $match->setPosition($position); $playerMatch1 = new \Own\Bus\PlayerMatch\Model(); $playerMatch1->setPlayerId($players[$i]['id']); $playerMatch1->setHasViewed($players[$i]['hasViewed']); if (isset($players[$i]['seed'])) { $playerMatch1->setSeed($players[$i]['seed'] + 1); } $playerMatch1->save(); if ($players[$i]['userId'] != 0) { \Own\Bus\Notification\Service::create($players[$i]['id'], 0, 'tournamentStart', [['scheduledMatch', $matchTime]]); } $i++; $playerMatch2 = new \Own\Bus\PlayerMatch\Model(); $playerMatch2->setPlayerId($players[$i]['id']); $playerMatch2->setHasViewed($players[$i]['hasViewed']); if (isset($players[$i]['seed'])) { $playerMatch2->setSeed($players[$i]['seed'] + 1); } $playerMatch2->save(); if ($players[$i]['userId'] != 0) { \Own\Bus\Notification\Service::create($players[$i]['id'], 0, 'tournamentStart', [['scheduledMatch', $matchTime]]); } $i++; $match->setPlayerMatch1Id($playerMatch1->getId()); $match->setPlayerMatch2Id($playerMatch2->getId()); $match->setScheduled(date('Y-m-d H:i:s', $matchTime)); $match->setType(MatchType::TOURNAMENT); $match->setStatus(MatchStatus::READY); $match->save(); $position--; } } else { Util\Log::log(Util\Code::CRON, 'Tournament not generated, tournamentId: ' . $tournament->getId() . ', ' . count($tournament->getTournamentPlayers()) . ' / ' . $tournament->getSize(), __FILE__, __LINE__); return false; } } return true; }
public static function countFace2Face($signedPlayerId, $playerId) { $options = []; $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'; $options['join'][] = 'bus_player match_player_match2_player ON match_player_match2_player.id = match_player_match2.player_id'; $options['where'][] = [' (match_player_match1.player_id = ? AND match_player_match1.has_viewed = true AND match_player_match2.player_id = ?) OR (match_player_match2.player_id = ? AND match_player_match2.has_viewed = true AND match_player_match1.player_id = ?)', $signedPlayerId, $playerId, $signedPlayerId, $playerId]; $options['where'][] = ['match.status = ?', MatchStatus::FINISHED]; return \Own\Bus\Match\Data::count($options); }