Beispiel #1
0
 private function newEntity($params)
 {
     // Create account
     $userManager = $this->container->get('fos_user.user_manager');
     $user = $userManager->createUser();
     $user->setUsername($params['name']);
     $user->setEmail($params['name'] . '@test.com');
     $user->setPlainPassword('test');
     $user->setEnabled(true);
     $userManager->updateUser($user, false);
     $this->manager->persist($user);
     // Create profile
     $profile = new Profile();
     $profile->setAccount($user);
     $profile->setFirstname($params['name']);
     $profile->setLastname($params['name']);
     //$profile->setLocation($params['name']);
     $this->manager->persist($profile);
     // Create member
     $member = new Member();
     $member->setAccount($user);
     $member->setProject($params['project']);
     $member->setRole($params['role']);
     $member->setStatus($params['status']);
     $member->setEmail($params['name'] . '@test.com');
     if ($params['status']->getId() == 1) {
         $member->setSender($params['sender']->getAccount());
     }
     $member->setAdmin($params['admin']);
     $this->manager->persist($member);
 }
 /**
  * Creates a new Profile entity.
  *
  * @Route("/create", name="profile_create")
  * @Method("post")
  * @Template("NeblionScrumBundle:Profile:new.html.twig")
  */
 public function createAction()
 {
     // Check if user is authorized
     if (!$this->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         throw new AccessDeniedException();
     }
     $em = $this->getDoctrine()->getManager();
     $account = $this->get('security.context')->getToken()->getUser();
     // Check if the user has already a profile
     if ($account->getProfile()) {
         // Set flash message
         $this->get('session')->getFlashBag()->add('notice', 'You have already a profile, edit it!');
         return $this->redirect($this->generateUrl('profile_edit', array('id' => $account->getProfile()->getId())));
     }
     $entity = new Profile();
     $entity->setAccount($account);
     $request = $this->getRequest();
     $form = $this->createForm(new ProfileType(), $entity);
     $form->bindRequest($request);
     if ($form->isValid()) {
         $em->persist($entity);
         $em->flush();
         // Set flash message
         $this->get('session')->getFlashBag()->add('success', 'Profile was successfully created!');
         return $this->redirect($this->generateUrl('neblion_scrum_welcome'));
     }
     return array('entity' => $entity, 'form' => $form->createView());
 }