/** * @param Game $game * @param User $user * @return Game */ public function getUserGame(Game $game, User $user = null) { $game->setMine(false)->setUserMove(false)->setCanAbort($this->container->get('core.service.chess')->canAbort($game)); try { $game->getUserWhite()->setRating($game->getRatingWhite()); $game->getUserBlack()->setRating($game->getRatingBlack()); } catch (\Throwable $e) { $this->container->get('logger')->warning($e->getMessage()); } if (!$user instanceof User || !$this->isMyGame($game, $user)) { return $game; } $game->setMine(true); $this->defineUserColorForGame($user, $game); $this->defineUserMoveAndOpponentForGame($user, $game); if ($game->getStatus() == GameStatus::END) { switch ($game->getColor()) { case GameColor::WHITE: $game->setMyResult($game->getResultWhite()); break; case GameColor::BLACK: $game->setMyResult($game->getResultBlack()); break; } } return $game; }