/** * @param Event $event * @return CoordsCollection */ private function getAttackerShots(Event $event) { $shotEvents = $this->eventRepository->findForGameByTypeAndPlayer($event->getGame(), Event::TYPE_SHOT, $event->getPlayer()); $attackerShots = new CoordsCollection(); foreach ($shotEvents as $shotEvent) { $attackerShots->append($shotEvent->getValue()); } return $attackerShots; }
/** * @param Game $game * @param string $eventType * @return bool */ protected function eventAlreadyExists(Game $game, $eventType) { $events = $this->eventRepository->findForGameByTypeAndPlayer($game, $eventType, $game->getPlayerNumber()); return !$events->isEmpty(); }
/** * @param Game $game * @param string $eventType * @param int $playerNumber * @return bool */ private function doesEventExistForPlayer(Game $game, $eventType, $playerNumber) { $events = $this->eventRepository->findForGameByTypeAndPlayer($game, $eventType, $playerNumber); return !$events->isEmpty(); }
/** * Example response:<pre> * [ * { * "id": 5, * "player": 2, * "type": "shot", * "value": "A10|sunk", * "timestamp": "2016-10-18T16:08:47+0000" * }, * ... * ]</pre> * * @ApiDoc( * resource=true, * description="Get events data", * section="Event", * requirements={ * {"name"="game", "dataType"="integer", "requirement"="\d+", "required"=true, "description"="Game id"} * }, * statusCodes = { * 200="Events data received", * 403="Requested details someone else's game", * 404="Game not found" * } * ) * * @Tag(expression="'game-' ~ game.getId() ~ 'events'") * @Security("game.belongsToUser(user)") * @QueryParam( * name="type", * requirements=@Assert\Choice(callback = {"AppBundle\Entity\Event", "getTypes"}), * nullable=true, * strict=true, * description="Filter by type" * ) * @QueryParam(name="gt", requirements="\d+", nullable=true, strict=true, description="Filter by id greater than") * @QueryParam(name="player", requirements="[1-2]", nullable=true, strict=true, description="Filter by player number") * * @param ParamFetcher $paramFetcher * @param Game $game * @return array */ public function getEventsAction(ParamFetcher $paramFetcher, Game $game) { return $this->eventRepository->findForGameByType($game, $paramFetcher->get('type'), $paramFetcher->get('gt'), $paramFetcher->get('player'))->toArray(); }