protected function onSuccess(UserInterface $user, $confirmation)
 {
     $group = $this->groupManager->findGroupBy(array('id' => 2));
     if (!empty($group)) {
         $role = new UserRole();
         $role->setGroupe($group);
         $role->setUser($user);
         $role->setRole("usr");
         $this->em->persist($role);
         $this->em->flush();
         $user->addGroup($group);
         $user->setChosenGroup($group);
     }
     parent::onSuccess($user, $confirmation);
     $mainBotAccount = $this->userManager->findUserBy(array('id' => 20));
     if ($this->registrationMessage->hasMessage()) {
         $content = $this->registrationMessage->getMessage();
     } else {
         $content = '';
     }
     if (!empty($mainBotAccount) && !empty($content)) {
         $salon = new Salon();
         $salon->setName('Discussion privée');
         $salon = $this->salonManager->createSalon($salon, array($user, $mainBotAccount), array($user), true);
         $message = $this->persistManager->buildMessage($mainBotAccount, $salon, $content, new \DateTime());
         $this->persistManager->persistMessage($message);
     }
 }
Example #2
0
 public function privateDiscussionAction($userId)
 {
     $user = $this->getUser();
     if ($user == null) {
         throw new AccessDeniedException("Vous n'avez pas le droit de modérer ce salon.");
     }
     $em = $this->getDoctrine()->getManager();
     $salon = $em->getRepository('TerAelisTChatBundle:Salon')->getPrivateRoom($user->getId(), $userId);
     if ($salon == null) {
         $otherUser = $em->getRepository('TerAelisUserBundle:User')->findOneBy(array('id' => $userId));
         if ($otherUser == null) {
             throw $this->createNotFoundException('User not found');
         }
         $salon = new Salon();
         $salon->setName('Discussion privée');
         $this->get('teraelis.tchat.salon_manager')->createSalon($salon, array($user, $otherUser), array($user, $otherUser), true);
         $em->persist($salon);
         $em->flush();
     }
     return $this->redirect($this->generateUrl('teraelis_tchat_show', array('id' => $salon->getId())));
 }