/** * @Route("/", name="settings") */ public function settingsAction(Request $request) { /** @var \AppBundle\Entity\User $user */ $user = $this->getUser(); $form = $this->createForm(new UserType(), $user, ['validation_groups' => ['settings']]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); if (false === $this->get('security.authorization_checker')->isGranted('ROLE_COMPLETE_USER')) { $user->addRole('ROLE_COMPLETE_USER'); $token = new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles()); $this->getSecurityContext()->setToken($token); $this->addFlash('info', 'Nu har vi registrerat dina uppgifter, och kommer att höra av oss så fort vi har hittat en ny matchning.'); $connectionRequest = new ConnectionRequest(); $connectionRequest->setUser($user); $connectionRequest->setCity($form->get('city')->getData()); $connectionRequest->setWantToLearn($user->getWantToLearn()); $em->persist($connectionRequest); } $em->persist($user); $em->flush(); return $this->redirect($this->generateUrl('homepage')); } $parameters = ['form' => $form->createView()]; return $this->render('user/settings.html.twig', $parameters); }
/** * @Route("/", name="homepage") */ public function indexAction(Request $request) { $activeRequest = false; if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { if (false === $this->get('security.authorization_checker')->isGranted('ROLE_COMPLETE_USER')) { return $this->redirect($this->generateUrl('settings')); } $user = $this->getUser(); $em = $this->getDoctrine()->getManager(); /** @var \AppBundle\Entity\User $user */ $connectionRequest = new ConnectionRequest(); $connectionRequest->setUser($user); $connectionRequest->setWantToLearn($user->getWantToLearn()); $connectionRequest->setMusicFriend($user->isMusicFriend()); $form = $this->createForm(new ConnectionRequestType(), $connectionRequest); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $activeRequest = $em->getRepository('AppBundle:ConnectionRequest')->hasActiveRequest($user); if (!$activeRequest) { $em->persist($connectionRequest); $em->flush(); $this->get('app.user_mailer')->sendRegistrationWelcomeEmailMessage($user); return $this->redirect($this->generateUrl('homepage')); } } $parameters = ['form' => $form->createView(), 'activeRequest' => $activeRequest]; } else { $parameters = ['activeRequest' => $activeRequest]; } return $this->render('default/index.html.twig', $parameters); }
/** * @Route("/", name="admin_create_connectionrequest") * @Method("POST") */ public function createAction(Request $request) { /** @var User $user */ $user = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->find($request->request->getInt('userId')); $city = $this->getDoctrine()->getManager()->getRepository('AppBundle:City')->find($request->request->getInt('cityId')); $connectionRequest = new ConnectionRequest(); $connectionRequest->setUser($user); $connectionRequest->setWantToLearn($request->request->getBoolean('wantToLearn')); $connectionRequest->setComment($request->request->get('comment')); $connectionRequest->setCity($city); $connectionRequest->setSortOrder($request->request->getInt('sortOrder')); $connectionRequest->setMusicFriend($request->request->getBoolean('musicFriend')); $this->getDoctrine()->getEntityManager()->persist($connectionRequest); $this->getDoctrine()->getEntityManager()->flush(); return new Response(); }
/** * @param ObjectManager $manager */ protected function loadConnectionRequests(ObjectManager $manager) { $connectionRequest = new ConnectionRequest(); $connectionRequest->setWantToLearn(true); $connectionRequest->setCity($this->getReference('city-1')); $connectionRequest->setUser($this->getReference('user-learner')); $connectionRequest->setComment('Jag vill fika'); $manager->persist($connectionRequest); $connectionRequest = new ConnectionRequest(); $connectionRequest->setWantToLearn(false); $connectionRequest->setCity($this->getReference('city-1')); $connectionRequest->setUser($this->getReference('user-fluentspeaker')); $connectionRequest->setComment('Jag vill dricka kaffe'); $manager->persist($connectionRequest); $connectionRequest = new ConnectionRequest(); $connectionRequest->setWantToLearn(false); $connectionRequest->setCity($this->getReference('city-2')); $connectionRequest->setUser($this->getReference('user-glenn')); $connectionRequest->setComment('Jag vill träffas ute'); $manager->persist($connectionRequest); }