Example #1
0
 /**
  * @Route("/api/newgame")
  * @Method("POST")
  */
 public function newGameAction()
 {
     $game_logic = $this->get("game_logic");
     $word = $game_logic->get_random_word();
     if ($word) {
         //now that we have a word. Generate a unique id for the user
         $user_id = uniqid();
         //and save the user unique id in the DB:TB session
         $session = new Session();
         $session->setUniqueId($user_id);
         $session->setWord($word);
         $session->setStatus("busy");
         $session->setTriesLeft(11);
         $session->setTs(new \DateTime("now"));
         $entity = $this->getDoctrine()->getManager();
         $entity->persist($session);
         $entity->flush();
         if ($entity) {
             //saved into DB? return the game info
             $new_game_info = $game_logic->get_session_raport($session, $game_logic->word_progress($session->getWord()));
             return new JsonResponse($new_game_info);
         }
     }
     return false;
 }