Exemplo n.º 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;
 }
Exemplo n.º 2
0
 public function reGenerateSession()
 {
     $newSession = new Session();
     $newSession->setIpAddress($this->getIpAddress());
     $newSession->setStatus($this->getStatus());
     $newSession->setUser($this->getUser());
     $newSession->setShippingClass($this->getShippingClass());
     $newSession->setPaymentClass($this->getPaymentClass());
     $newSession->save();
     $_SESSION["ECommSessionId"] = $newSession->getId();
     return $newSession->getId();
 }
Exemplo n.º 3
0
 /**
  * Attempts to form a group with all the members of the group from the previous round.
  * If a group can be formed, sets it as the current group for all of its members,
  * then returns that group.
  * Otherwise, sets the current status of this session to Session::group_request_pending,
  * then returns FALSE.
  * 
  * A group is considered "ready to be formed" when the status of each of its members
  * is Session::group_request_pending.
  * 
  * @param Session $session
  * @return Group if the group is formed, FALSE otherwise 
  */
 public static function getOldGroup(Session $session)
 {
     // set given group's satus as "request pending". this is for internal state checks.
     $session->setStatus(Session::group_request_pending);
     // get the group for the previous round
     $previous_group = $session->getGroup($session->currentRound()->previousRound());
     // are all members ready?
     $ready = array_reduce($previous_group->members, function ($v, $w) {
         return $v && $w->getStatus() == Session::group_request_pending;
     }, TRUE);
     if ($ready) {
         // let the group members know they're in a group
         self::setSessionsGroup($previous_group->members, $previous_group);
         return $previous_group;
     } else {
         return FALSE;
     }
 }