示例#1
0
 protected function privateMessage(User $user, $forId, $data)
 {
     $message = new Message();
     $message->user = $user;
     $message->for = User::find($forId);
     $message->datetime = new \DateTime();
     $message->data = $data;
     $message->save();
     $this->sendToUser($forId, Protocol::message($message));
     return $message;
 }
示例#2
0
文件: Chat.php 项目: elfchat/elfchat
 /**
  * @Route("/", name="chat")
  */
 public function index()
 {
     $em = $this->app->entityManager();
     if (!$this->app->isAuthenticated()) {
         return $this->render('index.twig');
     } else {
         $user = $this->app->user();
         // Recent messages
         $recent = array();
         foreach (Message::getLastMessages($user->id) as $message) {
             $recent[] = $message->exportWithUser();
         }
         // Reverse array of messages
         $recent = array_reverse($recent);
         // Language
         $lang = array();
         $translator = $this->app['translator'];
         if ($translator instanceof Translator) {
             $lang = $translator->getCatalogue()->all('browser');
         }
         return $this->render('chat/chat.twig', array('user' => $user->export(), 'recent' => $recent, 'lang' => $lang));
     }
 }
示例#3
0
 public static function message(Message $message)
 {
     return self::data(self::MESSAGE, $message->exportWithUser());
 }