Esempio n. 1
0
 public function registerNewUser(Registration $registration)
 {
     $user = new User();
     $administration = new Administration();
     $administration->setOwner($user);
     $registration->updateUser($user);
     $registration->updateAdministration($administration);
     $user->setEnabled(false);
     $categoryPreset = new Preset();
     $rootCategory = $categoryPreset->createPreset($administration);
     $event = new RegistrationEvent($user, $registration);
     $this->dispatcher->dispatch(UserEvents::REGISTRATION_SUCCESS, $event);
     $this->entityManager->persist($user);
     $this->entityManager->persist($administration);
     $this->entityManager->persist($rootCategory);
     $this->entityManager->flush();
 }
 /**
  * @Route("/administrations/new", name="new_administration")
  * @param Request $request
  * @return Response
  */
 public function newAction(Request $request)
 {
     $user = $this->getUser();
     $administration = new Administration();
     $administration->setOwner($user);
     $form = $this->createForm('administration_edit', $administration);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($administration);
         $categoryPreset = new Preset();
         $rootCategory = $categoryPreset->createPreset($administration);
         $em->persist($rootCategory);
         $em->flush();
         $this->addFlash('success', 'administration.updated');
         return $this->redirect($this->generateUrl('manage_administrations'));
     }
     return $this->render('HomefinanceBundle:Administration:edit.html.twig', array('form' => $form->createView()));
 }