public function addBoite(\Projet\UserBundle\Entity\Boite $boite) { $this->boites[] = $boite; $boite->setUser($this); }
/** * Creates a new Message entity. * */ public function createAction() { $entity = new Message(); $request = $this->getRequest(); $form = $this->createForm(new MessageType(), $entity); $form->bindRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $destinataire = $em->getRepository('ProjetUserBundle:User')->findOneByUsername($entity->getDestinataire()); if (!$destinataire) { throw $this->createNotFoundException('le destinataire n\'existe pas'); } $user = $this->container->get('security.context')->getToken()->getUser(); $boite = new Boite(); $boite->setTypeEnvoi("sender"); $boite->setUser($user); $boite->setMessage($entity); $boite1 = new Boite(); $boite1->setTypeEnvoi("receiver"); $boite1->setUser($destinataire); $boite1->setMessage($entity); $entity->setUser($user); $conversation = new Conversation(); $conversation->setMessage($entity); $conversation->setMsg($entity->getMessage()); $conversation->setUser($user); $em = $this->getDoctrine()->getEntityManager(); $em->persist($entity); $em->persist($boite); $em->persist($boite1); $em->persist($conversation); $em->flush(); return $this->redirect($this->generateUrl('message_show', array('id' => $entity->getId()))); } return $this->render('ProjetUserBundle:Message:new.html.twig', array('entity' => $entity, 'form' => $form->createView())); }