/**
  * Show individual match
  *
  * @param Match $match
  * @return Response
  */
 public function showAction(Match $match)
 {
     $loadMap = $this->get('basketplanner_match.map_loader_service');
     $map = $loadMap->loadMarkerById($match->getCourt()->getId());
     $player = $this->get('doctrine.orm.entity_manager')->getRepository('BasketPlannerMatchBundle:MatchUser')->findOneBy(array('match' => $match, 'user' => $this->getUser()));
     return $this->render('BasketPlannerMatchBundle:Match:show.html.twig', ['match' => $match, 'map' => $map, 'player' => $player]);
 }
 public function saveComment(Request $request, Match $match, User $user)
 {
     $comment = new Comment();
     $form = $this->formFactory->create(new CommentType(), $comment, ['action' => $this->router->generate('basket_planner_comment_create', ['id' => $match->getId()])]);
     $form->handleRequest($request);
     $results['form'] = $form->createView();
     $results['redirectToMatch'] = false;
     if ($form->isValid()) {
         if (!$match->getPlayers()->contains($user)) {
             $this->session->getFlashBag()->add('error', 'Tik prisijungę žaidėjai gali rašyti žinutes.');
         } else {
             $comment->setCreatedAt(new \DateTime('now'));
             $comment->setMatch($match);
             $comment->setUser($user);
             $this->em->persist($comment);
             $this->em->flush();
         }
         $results['redirectToMatch'] = true;
     }
     return $results;
 }
 public function leaveMatch(Match $match, User $user)
 {
     $player = $this->em->getRepository('BasketPlannerMatchBundle:MatchUser')->findOneBy(array('match' => $match, 'user' => $user));
     if (!$match->getPlayers()->contains($player)) {
         $this->session->getFlashBag()->add('error', 'Neįmanoma išeiti iš mačo prie kurio nesate prisijunge!');
         return false;
     }
     $match->removePlayer($player);
     $match->decreasePlayersCount();
     if ($match->getPlayersCount() == 0) {
         $match->setActive(false);
     }
     $this->em->persist($match);
     $this->em->remove($player);
     $this->em->flush();
     $this->session->getFlashBag()->add('success', 'Sėkmingai išėjote iš mačo');
     return true;
 }