示例#1
0
 /**
  * @Route("/round/{round}", name="admin_round", defaults={"round" = null})
  * @Template()
  */
 public function roundAction(Request $request, Round $round = null)
 {
     $this->checkIp($request);
     // new round defining
     if (!$round) {
         $round = new Round();
         if (!($currentRound = $this->roundRepo->findOneBy(['started' => true, 'finished' => false]))) {
             // first round auto start
             $roundId = 1;
         } else {
             $lastRound = $this->roundRepo->findOneBy([], ['id' => 'desc']);
             $roundId = $lastRound->getId() + 1;
         }
     } else {
         $roundId = $round->getId();
     }
     $form = $this->createForm(new RoundType(), $round);
     if ($request->isMethod('post')) {
         $form->submit($request);
         if ($form->isValid()) {
             if ($roundId == 1) {
                 $round->setStarted(true);
             }
             $this->em->persist($round);
             $this->em->flush();
             $this->roundManager->defineWalletAccount($round);
             return $this->redirect($this->generateUrl('admin'));
         }
     }
     return $this->render('AppBundle:Admin:round.html.twig', ['round' => $round, 'roundId' => $roundId, 'form' => $form->createView()]);
 }