public function getData(User $user) { $userId = $user->getId(); $usernames = $this->userRepository->getUsernamesIndexedById(); $games = iterator_to_array($this->gameRepository->createRecentByUserQuery($user)->hydrate(false)->select('createdAt', 'status', 'turns', 'v', 'isRated', 'clock.l', 'clock.i', 'players.user.$id', 'players.c', 'players.w', 'players.elo', 'players.eloDiff')->getQuery()->execute()); $data = array(array('#', 'Date (RFC 2822)', 'Color', 'Opponent', 'Result', 'Status', 'Plies', 'Variant', 'Mode', 'Time control', 'Your Elo', 'Your Elo change', 'Opponent Elo', 'Opponent Elo Change', 'Game url', 'Analysis url', 'PGN url')); $it = 0; foreach ($games as $gameId => $game) { list($player, $opponent) = $this->findPlayerAndOpponent($game, $userId); if (!empty($player['isAi'])) { $opponentUsername = sprintf('A.I. level %d', $opponent['aiLevel']); } elseif (!empty($opponent['user']['$id'])) { $opponentUsername = isset($usernames[(string) $opponent['user']['$id']]) ? $usernames[(string) $opponent['user']['$id']] : 'Anonymous'; } else { $opponentUsername = '******'; } $clock = isset($game['clock']) ? $game['clock'] : null; $data[] = array(++$it, date('r', $game['createdAt']->sec), $player['c'], $opponentUsername, $this->getPgnResult($game), $this->getStatusMessage($game['status']), $game['turns'] - 1, $this->getVariantName($game['v']), !empty($game['isRated']) ? 'rated' : 'casual', $clock ? sprintf('%d %d', round($clock['l'] / 60, 1), $clock['i']) : 'unlimited', (int) $player['elo'], (int) isset($player['eloDiff']) ? $player['eloDiff'] : 0, (int) isset($opponent['elo']) ? $opponent['elo'] : 0, (int) isset($opponent['eloDiff']) ? $opponent['eloDiff'] : 0, $this->urlGenerator->generate('lichess_game', array('id' => $gameId, 'color' => $player['c']), true), $this->urlGenerator->generate('lichess_pgn_viewer', array('id' => $gameId, 'color' => $player['c']), true), $this->urlGenerator->generate('lichess_pgn_export', array('id' => $gameId, 'color' => $player['c']), true)); } return $data; }
public function getNbGameByStatus($status) { return $this->gameRepository->countByStatus($status); }