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);
     }
 }
Beispiel #2
0
 /**
  * @param Salon  $salon
  * @param User[] $users
  * @param User[] $mods
  * @param bool   $isPrivate
  * @return Salon
  */
 public function createSalon(Salon $salon, $users, $mods, $isPrivate)
 {
     $salon->resetUsers();
     foreach ($users as $u) {
         $salon->addUser($u);
     }
     foreach ($mods as $m) {
         $salon->addMod($m);
     }
     $salon->setPrivate($isPrivate);
     $this->em->persist($salon);
     $this->em->flush();
     foreach ($users as $u) {
         $nv = new NonVuTChat();
         $nv->setSalon($salon);
         $nv->setUser($u);
         $this->em->persist($nv);
     }
     $this->em->flush();
     return $salon;
 }
 /**
  * @param Salon $salon
  * @param User $user
  * @return NonVuTChat[]
  */
 public function nonVuBySalon(Salon $salon, User $user)
 {
     return $this->createQueryBuilder('nv')->join('nv.salon', 's')->join('nv.user', 'u')->where('s.id = ' . $salon->getId())->andWhere('u.id = ' . $user->getId())->getQuery()->getResult();
 }
Beispiel #4
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())));
 }