Esempio n. 1
0
 public function createRandomGame($users, $sports, $centers)
 {
     $gameDate = $this->getRandomDate();
     $createdDate = clone $gameDate;
     $limitDate = clone $gameDate;
     $game = new Game();
     $game->setAdmin($users[rand(0, 3)]);
     $game->setCreated($createdDate->modify("-10 days"));
     $game->setGameDate($gameDate);
     $game->setLimitDate($limitDate->modify("-1 day"));
     $game->setPrice(rand(3, 10));
     $game->setNumPlayers(rand(3, 10));
     $game->setSport($sports[rand(0, 4)]);
     $game->setDescription("Creo este evento en tal sitio por que quiero bla bla");
     $game->setCenter($centers[rand(0, 4)]);
     $game->addPlayer($users[rand(0, 3)]);
     $game->addPlayer($users[rand(0, 3)]);
     return $game;
 }
Esempio n. 2
0
 /**
  * @Route("/partidos/organizar",name="intranet_create_game")
  * @Template("MIWIntranetBundle:Game:createGame.html.twig");
  */
 public function createGameAction(Request $request)
 {
     // get user
     $user = $this->get('security.context')->getToken()->getUser();
     // create new game
     $game = new Game();
     $center = new Center();
     $address = new Address();
     $game->setAdmin($user);
     $center->setAddress($address);
     $game->setCenter($center);
     // get form
     $form = $this->createForm(new GameType(), $game);
     if ($request->getMethod() == "POST") {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $dm = $this->get('doctrine.odm.mongodb.document_manager');
             // Check if is a new center or not
             $centerName = $game->getCenter()->getName();
             $center = $dm->getRepository('MIWDataAccessBundle:Center')->findOneByName($centerName);
             if (!$center) {
                 $dm->persist($game->getCenter());
             } else {
                 $game->setCenter($center);
             }
             // Transform dates, possible move to event
             $gameDate = Utility::addTimeToDate($game->getGameDate(), $form->get('gameTime')->getData());
             $gameLimitDate = Utility::addTimeToDate($game->getLimitDate(), $form->get('limitTime')->getData());
             $game->setGameDate($gameDate);
             $game->setLimitDate($gameLimitDate);
             $dm->persist($game);
             $dm->flush();
             return $this->redirect($this->generateUrl('intranet_games'));
         }
     }
     return array('form' => $form->createView(), 'game' => $game);
 }