Esempio n. 1
0
 function persistMessage(Message $message)
 {
     $em = $this->doctrine->getManager();
     $em->persist($message);
     $em->flush();
     $salon = $message->getSalon();
     $usersToNotify = $salon->getUsers();
     foreach ($usersToNotify as $user) {
         if ($user->getId() != $message->getUser()->getId()) {
             $nonVu = new NonVuTChat();
             $nonVu->setUser($user);
             $nonVu->setSalon($salon);
             $em->persist($nonVu);
         }
     }
     $usersToNotify = $salon->getMods();
     foreach ($usersToNotify as $user) {
         if ($user->getId() != $message->getUser()->getId()) {
             $nonVu = new NonVuTChat();
             $nonVu->setUser($user);
             $nonVu->setSalon($salon);
             $em->persist($nonVu);
         }
     }
     $em->flush();
     $salon->setLastUpdate(new \DateTime());
     $em->persist($salon);
     $em->flush();
 }
Esempio n. 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;
 }