Exemplo n.º 1
0
 public function user_newAction(Request $request)
 {
     $user = new User();
     $addr = new Address();
     $karma = new Karma();
     $user->setCreateTime(new \Datetime());
     $addr->setLastUpdate(new \Datetime());
     $user->setAddress($addr);
     $form = $this->get('form.factory')->create(new UserType(), $user);
     if ($form->handleRequest($request)->isValid()) {
         // $user = $form->getData();
         $em = $this->getDoctrine()->getManager();
         $em->persist($user->getAddress());
         $em->flush();
         $user->setId_address($user->getAddress()->getId());
         $user->setActive(1);
         $toks = explode("@", $user->getEmail());
         $user->setUsername($toks[0]);
         $user->setRoles(array('ROLE_USER'));
         $em->persist($user);
         $em->flush();
         $karma->setidUser($user->getId());
         $karma->setValue(0);
         $em->persist($karma);
         $em->flush();
         // Initialisation des listes
         $this->initLists($em, $user);
         $this->get('session')->getFlashBag()->add('success', 'Inscription effectuée.');
         return $this->redirect($this->generateUrl('ur_user_login'));
     }
     return $this->render('URUserBundle:Default:inscription.html.twig', array('form' => $form->createView()));
 }
Exemplo n.º 2
0
 public function addAction(Request $request)
 {
     $store = new Store();
     $addr = new Address();
     $form = $this->get('form.factory')->create(new StoreAdd(), $store);
     if ($form->handleRequest($request)->isValid()) {
         $addr->setLastUpdate(new \Datetime());
         $em = $this->getDoctrine()->getManager();
         $em->persist($store->getAddress());
         $em->flush();
         $store->setIdAddress($store->getAddress()->getId());
         $em->persist($store->getCompany());
         $em->flush();
         $em->persist($store);
         $em->flush();
         $this->get('session')->getFlashBag()->add('notice', 'Magasin ajouté');
         return $this->redirect($this->generateUrl('ur_admin_store_list'));
     }
     return $this->render('URAdminBundle:Stores:add.html.twig', array('form' => $form->createView()));
 }