Ejemplo n.º 1
0
 public function addChar($data)
 {
     $fraction = $this->em->find('riki34GameBundle:Fraction', $data['fractionID']);
     $specialization = $this->em->find('riki34GameBundle:Specialization', $data['specializationID']);
     $char = new PlayerChar($fraction, $specialization);
     $char->setName($data['name']);
     $char->setSex($data['sex']);
     $char->setUser($this->user);
     $errors = $this->validator->validate($char, null, array('create'));
     if (count($errors) === 0) {
         $bag = new Bag();
         $bag->setChar($char);
         $this->em->persist($bag);
         $this->em->persist($char);
         $this->em->flush();
         return $this->response->generateSuccessResponse();
     } else {
         return $this->response->generateErrorResponse($errors);
     }
 }